New answers tagged

0

Module names are all lowercase or underscore. Your preprocess function name must start exactly with the same name as your module/theme. Never uppercase. function mymodule_preprocess_page(&$variables) { ... } And there is no $hook parameter in this case, the _page function name suffix already declares this function as a specific hook only for the page ...


0

note:I have tested it in my machine and it works 100% the Hook_preprocess_node is gonna be executed before the rendering of any node of any content-type, you have to apply your logic here but be sure to apply it only of the body field exist otherwise you'll get an error if some content type doesn't have this field, then inject the updated dom into the node....


1

Use hook_views_pre_view function mymodule_views_pre_view(\Drupal\views\ViewExecutable $view, $display_id, array &$args) { // Modify contextual filters for view_name. $paragraph_id = 22; if ($view->id() == 'view_name') { $args = [$paragraph_id]; // args must be an array. } }


1

Drupal 8/9 modules often use events to take the place of alter hooks like this one found in Commerce 1.x on Drupal 7. You have to do a little digging to find the place in the code that executes it, but you can look it up with the following info: An Add to Cart form in Commerce 2.x is an order item add form governed by the "Add to Cart" form mode (a new ...


0

In first instance I would also go with the suggested approach by @jrockowitz. However I had a use case where the element was already in use and it couldn't be swapped out with a new element. What we ended up doing was to substitute the element's class with an extended class in a .module file: use Drupal\foo\Plugin\WebformElement\CustomWebformToggle; /** *...


0

Although I was unable to actually replace the tokens with the tokens' data in the database, I was able to figure out the ultimate goal which was to replace tokens in the email. This is the basic code (more details at https://www.drupal.org/forum/support/module-development-and-code-questions/2020-05-03/add-save-send-email-button-to-both#comment-13647867). $...


0

So, if dont want to use conditional_fields module and only conditional fields core You can do it, but required field have sometime a little bug. In the issue someone take some code from conditional_fields that fix this issue, and use it. your_module/js/conditional_fields.js (function ($, Drupal) { // Fix core's required handling. $(document).bind('state:...


0

You need to set the new value on the body, and save it. function MYMODULE_node_presave(Drupal\Core\Entity\EntityInterface $node) { if ($node->bundle() == 'article') { $body = $node->get('body')->value; $token = Drupal::token(); $body = $token->replace($body); $node->get('body')->value = $body; $node->save(); } }


0

One way to work around this is to go to /admin/appearance and uncheck Use the administration theme when editing or creating content. Alternately, you can create a separate user account that does not have permission View the administration theme and use that account to create content.


0

The default_value attribute accept an array in case of managed_file: $form['my_file'] = [ '#type' => 'managed_file', '#title' => 'my file', '#name' => 'my_custom_file', '#description' => $this->t('my file description'), '#default_value' => [$config->get('my_file')], '#upload_location' => 'public:/...


2

In hooks which are not executed in a render context use renderPlain(), see Cron error: LogicException : Render context is empty $html = \Drupal::service('renderer')->renderPlain($processedResult); Caveat: Text filters can bubble up metadata which you ignore by storing only the HTML. For a custom text filter this might be OK when you know it doesn't ...


0

When I changed base fields in the past they always updated in the plugin definitions on a cache clear. Also if this involved a schema update, by the way, which then produced a warning on the status page that there is a mismatch with the database, for which you then would need what you've described in the question. In your case, though, my guess would be ...


1

There are a couple of steps to doing this. For our demonstration, let's make a few assumptions: The module is called image_taxonomy. We have only one taxonomy term and one file to worry about. The image file is called color.jpg. The taxonomy term is called color_red. The image field is called field_color_image. The image is stored in your module's folder ...


2

It could be that you are using the incorrect argument. hook_ENTITY_TYPE_insert is a generic hook, it's not opinionated about what entity you are "inserting" (E.g. it could be a node, taxonomy, user...) Try: function weekly_digest_user_insert(\Drupal\Core\Entity\EntityInterface $entity) { // Do stuff. }


Top 50 recent answers are included