Questions tagged [hooks]

Use it for the mechanism that allows to extends module's functionality without editing its code.

Filter by
Sorted by
Tagged with
0
votes
0answers
3 views

Drupal 9 - remove tabs from local tasks block

I'm using Drupal 9.2.6 with Group module and I want to remove some tabs from local tasks block and rename some of them. I've created the module and placed above code with hook_menu_local_actions_alter ...
0
votes
0answers
8 views

Get all updated (changed) fields in submit function

In hook_form_alter in the specific form, I've added the new submit button if ($form_id == 'myform') { $form['custom_submit'] = [ '#type' => 'submit', '#value' => t('custom ...
0
votes
1answer
23 views

The values returned from hook_node_access_records() aren't considered to allow access

I am implementing a solution in Drupal 9 where users are allowed to see only the nodes that belongs to their same group. If a node doesn't belong to any group, t hey should be able to see it. I've ...
2
votes
1answer
46 views

What is the difference/purpose of 'content' and 'elements' keys, in preprocess?

I'm using hook_preprocess_node and looking at $variables. I can see there's two similar keys: content and elements. I see that there's a comment in the core code: // Helpful $content variable for ...
0
votes
0answers
14 views

How to use views query alter to show filtered content according to tags

I am new to Drupal and started learning hooks. I am trying to use hook_views_query_alter to show related content to user according to it's preferred tags. function related_content_views_query_alter(...
0
votes
0answers
17 views

drupal 7: no hooks run on page load

I have site on drupal 7. I'm creating a module to add a poll on-page instead of a template string. As I understand, I should do it in some hook-like hook_page_load, hook_init, hook_boot, etc I created ...
1
vote
0answers
15 views

Disable the "Add Link" button in entity.menu.edit_form for certain roles

I'd like to hide the "Add Link" button in menu.edit_form for certain roles. Running dpm($form) for this form I can't find that button in there. In core there is menu_ui.links.action.yml with ...
0
votes
1answer
42 views

How do you remove a user role via a hook update?

I would like to remove a user role via a hook update in Drupal 9. I believe I would need to do something like the below but unclear what other code might be needed. $user->removeRole('administrator'...
0
votes
1answer
32 views

How to get current region or current block of node in hook_theme_suggestions_node()

I need to get the current region or the current block where a node is rendered, in hook_theme_suggestions_node(). function mymodule_theme_suggestions_node(array $variables) { $node_region = "I ...
0
votes
0answers
5 views

How to display group operations block not in a dropbottom menu either "normal" links list/HOOK_block_build_group_operations_alter does not fire

currently the links of the "group operations block" of group module are displayed in a dropbutton menu. I want them to get displayed in a "normal" link list. I found an issue (...
6
votes
2answers
744 views

Is it bad practice to use the same hook twice?

I'm working a quite a big project and I use hook_entity_update() in three of my modules. I do this to keep my project structured and have different functions of my site in different modules. Is it ...
0
votes
1answer
16 views

Node form ajax dependent dropdown fields issue

I am using Drupal 9. I know how to change single dropdown list using another one. Here is my scenario: I have three dropdowns, in node form - company, protocol and investigator. What I like to do, ...
0
votes
1answer
78 views

hook_theme_suggestions_image_alter() not returning ['data-responsive-image-style']

Perhaps I have similar issue to this Drupal 9.2 template_preprocess_image hook not working. When I put this code in myTheme.theme function HOOK_theme_suggestions_image_alter(array &$suggestions, ...
-2
votes
1answer
51 views

Alter "Action processing results" message for a specific action

I have a view based on view bulk operations. this is a comment based view and performs the below actions: 1. Publish comment 2. Unpublish comment When one of these actions are selected to be executed ...
0
votes
1answer
20 views

How do I programmatically set a flag's custom entity reference field when programmatically setting the flag?

Some background: I'm new to Drupal 8/9 module building. I need a particular content type's nodes to be automatically flagged. I have this working using the code below. However, the flag involved also ...
3
votes
1answer
25 views

Derive all image styles when user uploading

I have several image styles defined but only thumbnail and medium styles(images) can be derived from the original image. I know those two styles are set in the "manage field" of image and my ...
0
votes
1answer
25 views

How to use hook_node_insert to automatically flag nodes of a specific content type

All nodes of one content type in my project need to get automatically flagged (by the Flags module) when created. I'm aware that there is probably a way to accomplish this using Rules module, but I'm ...
0
votes
0answers
14 views

Webform custom element layout twig

I am creating a custom webform element, im using the /modules/contrib/webform/webform_example_example, i installed the module and added the element to a form but now i want to customize the webform in ...
1
vote
1answer
132 views

How to hook on paragraph deletion?

I'm on D9 and I've a paragraph inside a content type node. I need to hook when the paragraph is deleted to do some custom logic and set up a queue. I've tried hook_entity_delete, hook_entity_predelete ...
0
votes
1answer
47 views

Entity reference field hidden widget or edit disabled on custom form

I have a custom node creation form I am rendering within a views preprocess hook. In that form I have two entity reference fields. I am setting the [#value] and [#default_value] of those reference ...
2
votes
1answer
44 views

Add a custom variable to an existing block

Is there a way to alter the render array of an existing block? I want to do it for a commerce block (cart block) but the question remains for any core or contrib module block. When a block uses a ...
-1
votes
2answers
43 views

How to add view filter programmatically using hook_views_pre_view()

I want to add a simple filter to an existing view in Drupal 9. It appears that I can achieve this with hook_views_pre_view(). In every example I can find, including all the "Similar questions&...
0
votes
0answers
23 views

How to get remote post handler returned response at module file?

I want to get remote post handler returned response inside hook_webform_handler_invoke_post_save_alter. Please help me. function hook_webform_handler_invoke_post_save_alter(\Drupal\webform\Plugin\...
1
vote
1answer
19 views

Adding a class to an image using preprocess function

I am having trouble adding a class to an image using a preprocessor function in Drupal 9. Specifically, I only want certain images to have that class added. The image is being added using paragraphs. ...
2
votes
1answer
54 views

hook_node_presave get original of translated node

I'm using a hook_node_presave and I want to detect which field is updated when the translated node is updated. Here is my code : function hook_import_node_presave(\Drupal\node\NodeInterface $node) { ...
1
vote
1answer
26 views

Place field in "Url Alias" advanced group section (path-0)

I'm trying to place my node field to the Advanced group - URL alias section. I'm doing it in custom hook_form_BASE_FORM_ID_alter(), where I'm trying to set custom #group like this: $form['my_filed']['#...
-3
votes
1answer
33 views

How to pass an argument to a hook without creating a custom module?

I need to attach a theme-agnostic ("global") CSS file to the preprocess_hook() function so that any theme I use, would include that CSS. I want to do that without creating a custom module ...
0
votes
1answer
17 views

Hook for field not triggered when using delta in template

I tried to hook my Link type field with machine name "field_link". This field is rendered in template using delta index to extract some values, e.g.: {{ content.field_link[0]['#title'] }} I ...
2
votes
2answers
89 views

add field to user in hook_update_n

The latest release of our existing module needs to define MANY new fields that are attached to the drupal user. For each field, in {module}/config/optional there is a field config and a field storage ...
0
votes
0answers
65 views

Save textarea word count programmatically

I'm trying to keep a word count tally on a set of long text fields. As far as I can see, there are several options: Create a view and add php to a custom template that produces the word count. Most ...
0
votes
0answers
27 views

Why my custom select view filter is not working?

I have a publication content type, each publication can have one or more authors. I'm trying to add a custom select list filter depending on the author, so far i managed to make it appear in the view ...
0
votes
1answer
38 views

How to edit file 'description' label and help text

I want to edit the file upload description label and the help sentence underneath it: I tried the below code: function mymodule_field_widget_form_alter(&$element, FormStateInterface &$...
0
votes
0answers
22 views

Ajax message after node save

I am trying to add a Ajax Alert or popup message inside a hook_node_presave or hook_node_update, but it is not working. My current code look like this, but I have tried a lot of other ajax $response = ...
0
votes
1answer
65 views

Throw error for required field in hook_form_alter?

I have a node type that can be created by authenticated users. In the node create form, I added a terms-of-service checkbox via a form hook like so: function themename_form_alter(&$form, &$...
-1
votes
1answer
81 views

How to remove big pipe <script> tags from page response

I need to remove <script> tags from some pages. I have managed to remove almost all of them, but these remain: <script type="application/vnd.drupal-ajax" data-big-pipe-event="...
1
vote
1answer
50 views

Hook webform options WEBFORM OPTIONS ID alter() [closed]

[{"value_1":"Dragon fly"},{"value_1":"Agapostemon angelicus"},{"value_1":"Albuna oberthuri"},{"value_1":"Callohesma ...
0
votes
0answers
17 views

Unable to inherit profile

I am trying to create a custom installation profile which will use standard as a base profile. So I created the customprofile.info.yml as below: name: 'Custom profile' core_version_requirement: '^9' ...
0
votes
1answer
49 views

How to use hook_block_access() with custom block created in UI

I have a custom block created using Drupal 9 Custom block library. I want to use hook_block_access() to control access to it, but, as it is a custom block, it does not have a block machine name. The ...
0
votes
0answers
19 views

Display machine name in entity_form_display_edit_form

The Entity Form Display edit form has a hidden field: 'hidden_name' => [ '#type' => 'hidden', '#default_value' => $field_name, '#attributes' => [ '...
0
votes
0answers
23 views

Hook_install or hook_modules_installed save entity does not work

I am trying to insert a new vocabulary to taxonomy because a custom entity from my custom module needs that vocabulary as an entity reference. I think it would be better to always insert the reference ...
2
votes
0answers
48 views

How can I capture a field’s configs and storage so I can delete it and then re-create it?

I’m trying to implement this in a hook_update_N() but I’m not sure it’s proper (see excerpt below). Note I’m changing max_length in the process. What I'm trying to do: update my_custom_entity....
1
vote
0answers
13 views

Custom display in saved Entity reference in Widget field

We have an entity reference field widget. Based on a view where you can enter the code of a product to get to the product reference. The widget shows the 2 fields (code) - (Title) when we type in the ...
0
votes
0answers
20 views

Using memcached and ip_ban simultaneously?

Memcached is by no doubt an essential tool to speed up Drupal websites. Is there a way to use the ip_ban module in order to block certain countries from accessing my website before the cached content ...
4
votes
1answer
234 views

How to make a checkbox read-only/disabled from list of user entity references

In my Content type, I add a field Reference: User with unlimited values, Reference method from a view of user managers, and widget checkboxes. Basically when a user manager edit the node, he can only ...
-1
votes
1answer
31 views

drupal custom callback in node edit form is not firing

i am fairly new to drupal , i have custom button added to one the content type edit page , when i click on that button i want to call a function but it seems like it is not calling function when i ...
0
votes
1answer
31 views

Add class to field parent with a preprocess hook in a custom module?

Background: I would like to alter the classes that are added to a rendered field in Drupal 9 in a custom module. I'm trying to use hook_preprocess_field and I'm not sure if this will work or if there ...
0
votes
1answer
55 views

hook_forms() not working

I'm trying to add a button to all node forms via callback in hook_forms. I get a similar error. Can someone help. Warning: call_user_func_array() expects parameter 1 to be a valid callback, class '...
-1
votes
1answer
123 views

Can't get page html after updating the page and flushing all caches

Once I updated a page via admin panel, I need to programatically flush all the caches, then get the page source code and write it to a file. I use the following code inside of my module: function ...
0
votes
0answers
36 views

Load css and js assets as absolute paths during twig render

By default, Drupal 8 loads css and js libraries using relative paths. ie: /core/modules/contextual/css/contextual.module.css However, because I want to generate static pages to be used by another ...
0
votes
1answer
35 views

Change paragraph object for rendering

I have a paragraph type with a node ref field that, if you leave it empty, is supposed to show a random node using some defined logic. I have the code to do the query and get the node, and ideally I'd ...

1
2 3 4 5
52