Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

New answers tagged

1

I would like to know if there is a way to target only that node type directly from the hook and not to have the hook triggered for all nodes and then checking the node type. Node hooks aren't that granular, they're invoked for all nodes and there isn't a system in place to make that selective based on the type. If you're worried about performance, don't be; ...


0

It turns out I was missing <head-placeholder token="{{ placeholder_token|raw }}"> in the head section of html.html.twig. Once I put that in there, the tags appeared and the favicon gets updated properly.


0

I think it's maybe for the name of the function. My theme's name is bartik, but the function example it's amptheme_image. Without more info it's hard to be sure, but it sounds like you're adding this code to the core bartik.theme file? If so then yes, that's why it's not working. You need to create a subtheme, add your code to its .theme file, and then ...


1

The beauty about Services is that they can be overridden to your liking. So all we have to do is extend the WebformMessageManager so we inherit all of it's properties and methods and simply alter the method you need to modify. my_module/src/CustomWebformMessageManager.php <?php namespace Drupal\my_module; use Drupal\webform\WebformMessageManager; use ...


1

I gave up on hook_views_pre_render and wound up meeting my requirements with template_preprocess_image_formatter as follows: function <TEMPLATE_NAME>_preprocess_image_formatter(&$variables) { $styles = array('thumbnail', 'medium', 'large'); if ($variables['image']['#style_name'] === 'medium') { $variables['image']['#style_name'] = $styles[...


0

You must consider using the Business Rules module as it is a great alternative to Rules modules and it is quite stable for now.


1

As seen in webform_example_handler You need to add: mymodule/mymodule.module <?php /** * @file * Provides a custom webform handler. */ /** * Implements hook_theme(). */ function mymodule_theme() { return [ 'webform_handler_myform_form_handler_summary' => [ 'variables' => ['settings' => NULL, 'handler' => []], ], ]; }...


0

You can change the favicon with MYTHEME_page_attachment_alter. First you should remove the favicon added by the theme with. unset($attachments['#attached']['html_head_link'][0]); as mentioned here then add you favicon here is a code sample works for me. /** * Implements hook_page_attachments_alter(). */ function MYTHEME_page_attachments_alter(array &$...


0

If its not a browser cache issue perhaps you should try modifying it with a hook called later namely THEMENAME_preprocess_html function THEMENAME_preprocess_html(array &$variables) { $test = ""; $variables["page"]["#attached"]["html_head_link"][0][0] = array( 'rel' => 'shortcut icon', 'href' => '/themes/fu/favicon_urbana.png', ...


-1

Picking up from @leymannx (and copy/pasting from the linked answer) here's a more spelled-out solution: You could use the template_preprocess_views_view() hook to do this: function THEME_preprocess_views_view(&$vars) { $view = &$vars['view']; // Make sure it's the correct view if ($view->name == 'my_slick_view') { // add needed ...


-1

OK, I found the problem. In my routing file, I was missing: options: no_cache: TRUE That fixed it.


0

turns out I am overwriting the form and the one that is working for me is : $form['field_reference']['widget']['#default_value'] = $thenodeid;


0

Although there may be a method to do this via a query alter I was unable to find the correct solution. I was however able to find a solution. Although we utilise search API heavily and we can use the content type relevance weighting we had a requirement to sort by a custom content type order and then by date, in addition some content types needed the same ...


1

this hook is invoked with module_invoke_all which should pass argument by value (and not by reference like drupal_alter() ) That's not how PHP works - $node is an object; objects are (ostensibly) passed by reference. Or, more accurately, from the docs One of the key-points of PHP5 OOP that is often mentioned is that "objects are passed by references by ...


2

Hooks are plain PHP functions that follow a specific name schema. As such, the same function name cannot be used from two modules. Furthermore, Drupal is not able to understand if c_a_b() is the implementation of hook_a_b() done from c.module, or the implementation of hook_b() done from c_a.module. To answer the question, yes, there would be conflicts and (...


1

Thank you very much! I really didn't need routing! Well, finally I found the solution to my problem - I created the module with 2 files only - mymodule.info.yml and mymodule.module. In .module file I only added these lines of code and everything worked! (Almost) function mymodule_inline_entity_form_entity_form_alter(&$entity_form, &$form_state) { ...


2

All hooks are in the global scope; PHP doesn’t allow two functions to have the same name in the global scope (it wouldn’t be able to distinguish which the intended callee was). It will exit with a fatal error during parsing. Yes, there is a definite potential for conflicts in the style you mentioned, but I doubt you’ll see it happen that often in the real ...


2

Assuming background-image refers to the example: <img src="" style="background-image: url(path/to/image);" />. Background images are different when written as: style="background-image: url(path/to/image);", they do not necessarily use Drupal's render service. A couple of options to try depending on your use case: • Try preprocessing your image field ...


1

Try with hook_form_alter something like /** * Implements hook_form_alter(). */ function MyModule_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) { if ($form_id == "field_config_delete_form"){ $field = $form_state->getFormObject()->getEntity(); \Drupal::messenger()->addWarning("You are going to delete ...


1

In order to get this to work, I did the following. This assume you have access to the $node object, which you would if you are performing this within the hook_preprocess_node() hook. $variables['url'] = $node->toUrl()->setAbsolute()->toString();


1

Drupal has dedicated theme hook, hook_page_attachments_alter, for this scenario. Your theme can hook into it, check the rendered route (for your node type), and take action on the $page['#attached']['library'] render array accordingly: function MYTHEME_page_attachments_alter(array &$page) { $node = \Drupal::routeMatch()->getParameter('node'); if (...


2

You've almost done it but $current_path = \Drupal::service('path.current')->getPath(); return real path, not the alias , you should get its path alias /** * Implements hook_theme_suggestions_HOOK_alter(). */ function mymodule_search_theme_suggestions_html_alter(array &$suggestions, array $variables) { $current_path = \Drupal::service('path....


0

This is a very late answer. With \Drupal\node\NodeInterface interface, I'm using that snippet to achieve your needs : /** * Implements hook_node_presave(); * * @param \Drupal\node\NodeInterface $node */ function module_name_node_presave(\Drupal\node\NodeInterface $node) { if($node->get('field_name')->getString() != 'search') { $node-&...


Top 50 recent answers are included