Categories
CMS Drupal Mastering Development

How to create a term reference field programmatically

I need to add a taxonomy reference field to a node bundle, programmatically. I found a couple examples here, but one actually is incorrectly titled and is about creating a from field for it, and the other is from 2012. I have tried the following, based on the couple of suggested examples I found, and […]

Categories
CMS Drupal Mastering Development

Setting value of form element from $form_state not working

I need to track previous values of a few form elements on a form to detect when they change to invalidate some other options on the page. Essentially, if the value of these fields change a field that controls pagination should reset. I’m trying to accomplish this with this: $values = $form_state->getValues(); $form[‘element1’] = [ […]

Categories
CMS Magento Mastering Development

Product custom attributes not updated – Magento 2 REST API

I’m using Magento 2.3.4 CE. I used the below JSON to update the product custom attribute part_number in swagger. { “product”: { “sku”: 678899, “name”: “Product name”, “attribute_set_id”: “4”, “price”: 2.93, “status”: “1”, “visibility”: 0, “type_id”: “simple”, “weight”: 0, “extension_attributes”: { “stock_item”: { “qty”: 10, “is_in_stock”: true } }, “custom_attributes”: [ { “attribute_code”: “part_number”, “value”: […]

Categories
CMS Magento Mastering Development

Magento Web API giving server internal error add products

I tried posting a product to my Magento site through its REST web API. I am using curl. I got this error: {“message”:”Internal Error. Details are available in Magento log file. Report ID: webapi-5e884238b420f”} And when I searched for the log file, I found: /var/www/html/var/log/exception.log:[2020-04-04 08:15:52] main.CRITICAL: Report ID: webapi-5e884238b420f; Message: Property “ShowDefaultNotificationMessage” does not […]

Categories
CMS Drupal Mastering Development

Form Select not rendering as a dropdown

I’m building a form that contains a select but it’s not rendering as a dropdown. It’s rendering with a scrollbar and a dropdown down arrow $form[‘my_select’] = [ ‘#type’ => ‘select’, ‘#empty_option’ => ‘- None -‘, ‘#title’ => $this->t(‘My Select’), ‘#options’ => [‘Option1’, ‘Option2’], ‘#size’ => 6, ‘#weight’ => ‘0’, ]; What am I doing […]

Categories
CMS Development Drupal

Ajax callback not called from a modal form

I dont understand because after i opened a modal form in drupal using this method (inside class Announcements) public function ajaxSubmitForm(array &$form, FormStateInterface $form_state) { // We begin building a new ajax reponse. $response = new AjaxResponse(); //$form_state = new \Drupal\Core\Form\FormState(); $modal_form = \Drupal::formBuilder()->getForm(‘Drupal\cdfsport\Form\AnnouncementsModalEventForm’); /* $this ->messenger() ->deleteAll();*/ // Add the OpenModalDialogCommand to the response. […]

Categories
CMS Development Drupal

Help with dynamic form caching issue

I’m sure I’m not approaching this in the right way but I don’t know how to fix it. I have the following form that submits via AJAX. If a user has already submitted the form before I’d like a message to replace the form and give them a message. However, with page_cache enable AJAX is […]

Categories
CMS Development Drupal

Bind new events from successful AJAX callback

I’m working on a site that needs a certain feature gated by a simple form containing a single email field: public function buildForm(array $form, FormStateInterface $form_state) { $form[’email_intro’] = [ ‘#markup’ => ‘<p>Please enter your email to begin.’, ]; $form[’email’] = [ ‘#type’ => ‘textfield’, ‘#maxlength’ => 128, ‘#size’ => 64, ‘#weight’ => ‘0’, ]; […]

Categories
CMS Development Drupal

how to update content node menu link in drupal 8?

I am creating Drupal 8 node using code and same time I am assigning a menu link as well its working fine. I am creating a menu using this code. MenuLinkContent::create([ ‘title’ => $item[‘title’], // Menu title is your title of menu, in this case node title ‘link’ => [‘uri’ => ‘entity:node/’ . $value->entity_id], ‘menu_name’ […]

Categories
Development PHP

How do I move an array element with a known key weight of an array in PHP?

Having a brain freeze over a fairly trivial problem. If I start with an array like this: $my_array = array( 1 => array( “id” => 1, “weight” => 0 ), 2 => array( “id” => 2, “weight” => -1 ), 3 => array( “id” => 3, “weight” => 0 ), 4 => array( “id” => […]