New answers tagged

0

Since I wanted to apply a change to the page.html.twig template based on if it was a form, I looked first for the form suggestions I was given. Since I couldn't find a way to generically apply a template to all forms, I instead created a template that I would then tell all of the forms that I have to use this template. I used a ...


-1

In Drupal 8 you can get a form id like this. You have to write this code in your .module file function modulename_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id){ echo "my form id is : ".$form_id; }


-1

'#title' should be a plain text. you have added html code Button in it.


0

The answer provided by Shawn works great, but if you would prefer to have separate controllers per content type eg. PageController, ArticleController etc. This is achievable by the Kernel Subscriber. services: app.kernel_subscriber: class: Drupal\app\EventSubscriber\KernelSubscriber arguments: ['@controller_resolver'] tags: - { name: ...


0

In my case I was trying to hide the label on quantity field provided by Drupal Commerce cart module and the following wasn't working: $form['my_field']['#title_display'] = 'invisible'; I had to do this inside my hook_form_alter $form['quantity']['widget'][0]['value']['#title_display'] = 'invisible';


1

The yaml-files that do this for the core is located in core/modules/system/. I eventually solved it by copying and adapting the relevant bits from system.routing.ymland system.links.menu.yml. First, in hello_world.routing.yml, set up the routings we shall need: hello_world.admin_config_examples: path: '/admin/config/examples' defaults: _controller: '...


1

Here is a way to do it. #example_codes.links.menu.yml example_codes.base: title: 'Example Codes Module' parent: system.admin description: 'A Module with various Examples.' route_name: example_codes.base weight: 0 You need to define system.admin as parent. And in your routing.yml should contain this base route. #example_codes.routing.yml ...


0

Create a paragraph "Node Image". Within the Paragraph type, add your media reference field and various text fields for your image metadata. Set them all to required, this is key for later. Go back to your Node type and add a new Paragraphs field called "Node Images", set to unlimited cardinality. Restrict the field to only allow the "...


1

Ok, this was just a stupid mistake in a another javascript. There the jQuery method .off() was used to remove event listeners which had the effect to remove the Ajax event listener.


0

I guess you are using Entity metadata wrapper solution to set values of an entity (in this case node) , if so you have to use set method like this : $location->field_locationmap->set([$form_state['values']['field_locationmap']['lon'], $form_state['values']['field_locationmap']['lat']]); if not using entity metadata wrapper you might using some code ...


0

You can get the string value by using the following method. getUntranslatedString() So if you get the object as $link_object then accessing the string would be done using $link_object->getUntranslatedString();


0

I had the same problem. Instead of "#limit_validation_error", adding validation handler which simply omits all the error works fine. function my_module_form_alter(&$form, $form_state, $form_id) { $form['actions']['save_as_draft'] = [ '#type' => 'submit', '#value' => t('Save as Draft'), '#submit' => ['::submitForm', '::...


Top 50 recent answers are included