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
1 answer
37 views

cant get file uri using field preprocess

Im trying to use function theme_preprocess_field to get the file path of a file field. I have tried different variations of below. function mytheme_preprocess_field(&$variables) { if ($...
user avatar
0 votes
0 answers
27 views

Redirect after using the one time login after password reset

How can i programmatically change the button link destination after clicking the one time login button in drupal 9: I've tried this solution but got stuck because i didn't know how to compare a link ...
user avatar
  • 11
-2 votes
1 answer
28 views

How to set value on drush updb running and get that value on hook_update_N, to call specific function? [closed]

On drush updb I am trying to set parameter value (ex: drush updb {value} -> drush updb unique) to get this value on my_module_update_9001(&$value): function my_module_update_9001(&$value) { ...
user avatar
  • 1
0 votes
1 answer
29 views

How to render a custom block with variables from another custom block twig template

I have a custom block with some values I can access in the template of that block, for example the product_type variable. In the same template file I'm adding another view block with {{ drupal_block('...
user avatar
0 votes
1 answer
45 views

Access preprocess variable globally

I am trying to get the Custom Block type fields using a preprocess hook. I can successfully use the following code. function theme_preprocess_block(&$variables) { $content = $variables['elements'...
user avatar
0 votes
1 answer
25 views

Run hook_preprocess_node only for main page

Is it possible to run hook_preprocess_node() only for the main page, and not for the referenced nodes that are on that same page? I am using the following code, but it doesn't feel like the best ...
user avatar
  • 892
0 votes
1 answer
33 views

How to add class to paragraph fields through preprocess hook?

I created a paragraph named flight-search-info-block with two fields: field_svg_icon and field_teaser_text. Then I created a custom block, where that paragraph was added as an entity reference field. ...
user avatar
  • 1
0 votes
0 answers
48 views

Troubleshooting Setting Cache Context to Session in Preprocess

My goal is to look for "webp" in the client HTTP_ACCEPT header in order to determine if I can serve WebP images. I chose this approach rather than using the WebP module because I thought it ...
user avatar
0 votes
0 answers
9 views

add prefixes and suffixes to taxonomy terms in hierarchical taxonomy vocabulary with hook_form_alter()

Is it possible to add prefixes and suffixes to taxonomy terms in hierarchical taxonomy vocabulary with hook_form_alter(). For example : Category A - Category A1 - Category A2 Category B - ...
user avatar
0 votes
2 answers
37 views

How can I get a multivalue field correctly inserted?

I have a custom module that creates a field type. It is a plain text field abd I've added it to a content type using the Drupal UI. The cardinality of this field is "Unlimited". This is how ...
user avatar
  • 14.8k
0 votes
0 answers
24 views

How to remove a sort in hook_views_query_alter

I've got a search API search view that has two sorts on it. relevance and then published date. This means that when I do a text search the relevancy score handles the sorting, but when there is no ...
user avatar
  • 1,269
0 votes
0 answers
16 views

Fluid UI container is injected in code without location choice for the developer

Problem I have installed the FluidUI module on my D9 website. It works fine, can use all the settings to change look and feel of the website to accommodate all people with accessibility issues. ...
user avatar
  • 47
3 votes
2 answers
166 views

How to not show the "has been created" message? [duplicate]

I want to remove the message that is output in the message area when a new node is created. A typical message may look like this. "Article My article has been created." I examine the node ...
user avatar
  • 14.8k
0 votes
1 answer
55 views

Generate Link based on custom content field types

I am using Drupal 8.9.8 and I have created a custom content type with field types such as plain text, number (integer), and so on. Then, I created Content based on the custom content types and filled ...
user avatar
0 votes
1 answer
45 views

Clarify difference between hook_form_TYPE_alter and hook_form_TYPE_EDIT_alter

I have a site with a lot of hook form alters for node forms and I'm finding that I have to create two separate hook functions to affect both the node create and node edit forms. For example, I have to ...
user avatar
1 vote
1 answer
45 views

How can I detect when a stream wrapper is uninstalled?

Does Drupal provide an "uninstall" hook to get notified when a Drupal Stream Wrapper is removed/uninstalled? Or, is there a way to prevent a custom Drupal stream wrapper from being removed/...
user avatar
0 votes
0 answers
8 views

How can i get the fields of a view which has contextual filter inside views_view_field hook in drupal 9?

I have a drupal 9 site. I have a parent view A and a child view B. I am using views_field_view contrib module in order to pass an id from view A to view B. I have added a contextual filter in B to get ...
user avatar
0 votes
1 answer
73 views

Programmatically change view mode of media field

I'm attempting to change the view mode of a media field programmatically. I've created a view mode called 'modal'. I created a mytheme_preprocess_media hook and attempted to change the view mode a ...
user avatar
  • 5,076
0 votes
1 answer
25 views

Clear field value when edit node

I have a List (text) field in a content type that will determine the importance of the content whether it is Major or Minor and that field is set to be required. I need to force content editors to ...
user avatar
0 votes
0 answers
30 views

hook_form_alter makes js on every other form not work

I use hook_form_alter() to alter a field. function mymodule_form_alter(&$form, &$form_state) { if ($form['#id'] == 'my_form') { $form['my_field']['#value'] = 'New value'; } } It ...
user avatar
  • 133
3 votes
2 answers
70 views

String substitution in Views Contextual filter parameter?

In Drupal 9, I have a View called News. The View is displayed at the following path: /news I can edit it at the following path: /admin/structure/views/view/news/edit It has the following Contextual ...
user avatar
  • 1,939
0 votes
1 answer
20 views

How to hide / modifiy ['operations']['#links'] edit / delete under structure -> menus in D8

I am trying to hide the edit and eelete links in the operations menu under structure -> menu for specific roles. I was just trying to hide the operations dialog at all by this code but it returns ...
user avatar
  • 281
0 votes
1 answer
28 views

theme_preprocess_menu is not seeing main menu

Background: I have an event website where I want to hide the event registration menu item when registration for the event is closed. theme_preprocess_menu is not triggering on anything except '...
user avatar
2 votes
2 answers
157 views

How do I properly define a library so that JS will execute after a certain condition is met?

I'm creating a custom module to execute some JS AFTER the cache is cleared. Here is the structure of the module: Module -> flush.info.yml name: Flush type: module description: A very important ...
user avatar
  • 25
1 vote
1 answer
70 views

Get the node title field value in the form_state

Drupal version 9.3.9. This is a process of Ajax callback, where the value of the title field is required. In the form node add, the title is displayed. It seems that the form_state does not apply to ...
user avatar
  • 63
1 vote
2 answers
111 views

How can I retrieve information about the current request's URL?

I need help finding a way to get the current request URL in a controller and, based on that, change the webform name in the controller. My code: '#url' => Url::fromRoute('entity.webform.canonical',[...
user avatar
  • 113
0 votes
1 answer
118 views

How should I use hook_cache_flush() or hook_rebuild() in a custom module to execute JavaScript code when the cache is cleared?

I'm trying to create a module that executes some JavaScript code when the cache is flushed (via administrator menu or otherwise). I believe I can implement either hook_cache_flush() or hook_rebuild(), ...
user avatar
  • 13
0 votes
0 answers
22 views

Creating link option in form and modifying it's url in form alter hook

I'm searching to modify a node add form, so far i added a personal field "link" to display as a button to add another node type if the user wants to, that link has this code in ...
user avatar
1 vote
0 answers
32 views

hook_help() isn't recognized in my custom module [closed]

I created a custom module in Drupal 9.3.8 which implements hook_help() using code similar to what I have seen in other modules. This is the relevant code in the node_usage.module file. function ...
user avatar
  • 399
0 votes
2 answers
35 views

Change default user tab

After logging in, users would be redirected to their user profile page. I have added a new tab, My dashboard using hook_menu(). Everything functions well. After the users log in, I would like they are ...
user avatar
  • 41
0 votes
1 answer
60 views

Cannot get hook for custom twig template to work

I have a custom template with the following twig file: views-view-unformatted--offices_contact_us_page_.html.twig The view is added as part of extra fields module inside of a Drupal paragraph. I have ...
user avatar
  • 163
-2 votes
1 answer
11 views

How can I loop on checkboxes to hide all using mlid: from the datatable?

function ts_core_form_menu_overview_form_alter (&$form, &$form_state, $form_id) { $form['mlid:11242']['hidden']['#type'] = 'hidden'; $form['mlid:11246']['hidden']['#type'] = 'hidden'; $...
user avatar
1 vote
2 answers
27 views

Set entity field to read-only after user input

I am using hook_entity_presave() to check some conditions and set field value. I would like to set the field to read-only after all conditions pass and the value is saved to database. Is it possible ...
user avatar
-1 votes
1 answer
26 views

How can I pass more variables/trigger preprocess to plugin block?

The block opigno_documents_last_group_block is located in opigno_learning_path/src/Plugin/Block/DocumentsLastGroupBlock.php, which looks like this: <?php namespace Drupal\opigno_learning_path\...
user avatar
  • 189
0 votes
2 answers
82 views

Can I use theme hook to display some extra fields in block?

Let's say I have 'opigno_documents_last_group_block' hook: <!-- THEME DEBUG --> <!-- THEME HOOK: 'opigno_documents_last_group_block' --> <!-- BEGIN OUTPUT from 'modules/contrib/...
user avatar
  • 189
0 votes
0 answers
28 views

Do something when a content is saved

I'm a total beginner in module coding and i'm trying to adapt a simple D7 module which is updating a field from a content type from an external API when the content is created or modified. On an fresh ...
user avatar
  • 1
0 votes
0 answers
10 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 ...
user avatar
  • 21
0 votes
1 answer
29 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 ...
user avatar
2 votes
1 answer
60 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 ...
user avatar
  • 3,929
0 votes
0 answers
21 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(...
user avatar
0 votes
0 answers
20 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 ...
user avatar
  • 101
2 votes
0 answers
49 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 ...
user avatar
  • 281
0 votes
1 answer
59 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'...
user avatar
  • 23
0 votes
1 answer
43 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 ...
user avatar
  • 31
0 votes
0 answers
11 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 (...
user avatar
  • 129
6 votes
2 answers
830 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 ...
user avatar
  • 892
0 votes
1 answer
27 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, ...
user avatar
0 votes
1 answer
103 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, ...
user avatar
  • 31
-2 votes
1 answer
53 views

Alter "Action processing results" message for a specific action [closed]

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 ...
user avatar
  • 33
0 votes
1 answer
74 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 ...
user avatar
  • 117

1
2 3 4 5
53