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
0 answers
37 views

Access method from outside of a class [closed]

I’m trying to access a method from a controller class that would open a modal in a preprocess hook but am unable to get it to work, I’m not sure of the correct way to do this, can anyone point me in ...
  • 111
0 votes
0 answers
17 views

user_login_finalize only works when the user has admin roles

i create custom login form in drupal 9 using user_login_finalize function. But this function only work when user has admin roles... i dont know why. This is my code :.. { if (isset($_POST['email'])...
0 votes
0 answers
16 views

What hook to use to fire a JS event when a layout is used?

I inherited a Drupal site. I'm a Drupal noob. There are lots of things that don't seem to be in use, but I want to be certain before I delete them. Right now I'm looking at dozens of layouts that ...
  • 101
1 vote
2 answers
43 views

How to loop through and build an array from each referenced entity [closed]

I’m trying to create a card grid component using paragraphs. I have a reference entity which references different card types with unlimited cardinality. I’m able to pull the values from the ...
  • 111
0 votes
2 answers
62 views

How to add/install a new field to all bundles of certain entity types?

I need to add a new string field called instagram_owner to all bundles of nodes, media and file entities. If new bundles are created, I need the field on them too. This is what I have so far in my ...
0 votes
1 answer
25 views

Add theme suggestion to a node depending on the menu it belongs to

I have a mega menu that displays child menu items when you click on a parent menu item in form of a drop-down menu. The thing is that, this menu, also displays cards as nodes and I want to add a theme ...
1 vote
1 answer
25 views

Provide theme suggestions for menu content items

For a mega menu, I'm trying to add theme suggestions to every parent menu item / menu link depending on the chosen view mode for that menu item. I'm aware of the ...
0 votes
0 answers
17 views

How to filter list items values based on user roles programmatically

I am in scenario where I need to filter list elements based on User Roles. for example.. i have create two roles 1.Vegetable seller and 2. Fruits seller. I have created a list field with values as '...
0 votes
1 answer
36 views

Dynamic webform component select options

In Drupal 7, dynamic options for a select widget could be created with hook_webform_select_options_info(): /** * Implements hook_webform_select_options_info(). */ function ...
  • 404
0 votes
0 answers
20 views

Views filter "NOT IN" showing all results

I have a drupal commerce website. On my product, i've added a field "stock" which tell if is product is available (custom workflow) which is like the "visibility" field (list of ...
  • 69
1 vote
0 answers
19 views

Add Javascript On Webform Confirmation Page

I am using Webform to generate a form on a page. Wherever this form loads, I need to run some javascript to push some data for Google Analytics 4 on two events (any field is focused, form is submitted ...
  • 51
1 vote
1 answer
48 views

Replacement for hook_user_presave() for saving values captured in the user form to the user profile

I am porting a module from Drupal 7 to Drupal 9. The code uses hook_user_presave() to save two fields on the fly into the user profile data. /** * Implements hook_user_presave(). */ function ...
  • 848
0 votes
1 answer
30 views

Hook menu alter - Restrict access to edit block - wrong page is shown

I want to restrict the editing of a block to users whom have X or Y permissions. I have tried access arguments and access callback. function MYMODULE_menu_alter(&$items) { $items['admin/...
0 votes
0 answers
20 views

Adding custom field and pdf print option to Webform Submission information

I have a requirement to add a select list containing yes/no to a webform submission view form and make it available in Drupal views, is there a way to add a field with a dropdown and with print option ...
0 votes
0 answers
33 views

How do I send a notification email as soon as file is uploaded from the node add/edit form?

I have a media video content type that has a video file field (takes a file), name, and air date. The video files are saved on amazon S3 not locally. I want to monitor the files that are uploaded and ...
  • 251
0 votes
0 answers
18 views

How do I add custom settings to a field? [duplicate]

Strangely, I'm having trouble finding any info on this, though seems simple at first. I need to alter the field type in my instance (decimal, to be precise), adding a new setting. The current settings ...
0 votes
0 answers
30 views

Attach custom javascript library to entity print output

I'm trying to load an easy Javascript for the Entity Print module. It should load a library defined in my theme, and a JS File. I tried some hooks, (_page, _preprocess_html, etc) but had no chance to ...
  • 333
2 votes
2 answers
181 views

How to completely change node/entity rendering to my own render element using hook_entity_build_defaults_alter()

I want to interrupt the normal entity view build process for certain content type and view mode combination, and use a custom render array instead of the default node builder render array. I can ...
0 votes
1 answer
91 views

Update the text format and process the body field of existing nodes programmatically

I am trying to resave a number of nodes to apply the text format changes to the body field. I’ve written a drush command to do this. The command does update the text format, but the text in the body ...
  • 21
0 votes
2 answers
71 views

How to get newly created user id in user_presave hook?

Following is my .module file code /** * Implements hook_user_presave(). */ function cost_sheet_user_presave($account) { $source_userid = $account->id(); \Drupal::messenger()->...
  • 471
0 votes
1 answer
23 views

How can I run a certain action when a taxonomy field value is removed or added? [closed]

I have a user_territories field which can have multiple values. I need to run a certain action when this field value is changed from the user entity, not when other fields are changed. How can I write ...
  • 471
1 vote
0 answers
24 views

Missing Details form on custom shipping method/service

In Drupal 7, I created custom shipping service which doesn't calculate any rate but collects customer account number for Fedex or UPS on the cart page when a specific shipping method is selected. $...
1 vote
2 answers
212 views

How can I use function template_preprocess_field() to pass a value from one field to an attribute of another field?

I have an Entity Product entity where one of the fields is: reference field on Media type with name Media Product Image Media Product Image has fields: Image Custom color id And in the developers ...
  • 21
0 votes
0 answers
16 views

How to transfer field_img_1 field_img_2 field values to the web form template field_my_webform

How to transfer field_img_1 field_img_2 field values to the field_my_webform web form template (webform-submission-form--web-form-with-images-for-each-step.html.twig) ...
0 votes
0 answers
37 views

Completely remove the default option _none in select list

This question has been asked many times but I can't find the complete solution. I want to remove the default option from a select value="_none". <select data-drupal-selector="edit-...
1 vote
2 answers
40 views

How can I ensure my_custom_module.install runs my_custom_module_update_8101()?

I have a custom module in Drupal 8.9.3. hook_schema() runs and creates the module table. I would like to run a hook_update_N() implementation to change the auto increment to start at a specific number,...
1 vote
1 answer
53 views

How to put fields created with BaseFieldDefinition::create() within the advanced group on node edit pages?

I am wanting to create some fields for a few of my existing content types but not sure how to go about it. Currently I am creating fields like this function HOOK_entity_base_field_info(...
  • 13
0 votes
1 answer
49 views

Toggle (show or hide) visibility of content type field in view depending on relationship with other content type

I have a member content type that displays info about a company's member. One of the fields is named member publications, and it's a link to a blog view where the publications of the member (another ...
  • 3
0 votes
1 answer
164 views

How do I add a variable for menu.html.twig?

I want a variable in menu.html.twig file. I tried adding the following hook in the theme's .theme file, but the template file doesn't print anything. function my_theme_name_preprocess_menu(&$...
0 votes
1 answer
48 views

Image inside paragraph being cached

I have a Paragraph type called image - that holds a media reference and also a field which describes how the sibling image should be rendered. I look at the value of the "field_image_style"...
0 votes
1 answer
47 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 ($...
0 votes
0 answers
60 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 ...
  • 31
-2 votes
1 answer
101 views

How can I use "drush updb" to pass a value to the hook_update_N() implementation done from a module?

I am trying to drush updb with an argument that is passed to the hook_update_N() implementation done from a module I wrote, which would use it to execute some update tasks. function ...
  • 9
0 votes
1 answer
147 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('...
0 votes
1 answer
181 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'...
0 votes
1 answer
39 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 ...
  • 938
0 votes
1 answer
492 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. ...
  • 1
0 votes
0 answers
75 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
17 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 - ...
0 votes
2 answers
50 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 ...
  • 14.9k
1 vote
1 answer
64 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 ...
  • 1,319
0 votes
0 answers
17 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. ...
  • 47
3 votes
2 answers
301 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 ...
  • 14.9k
0 votes
1 answer
60 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 ...
1 vote
1 answer
60 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 ...
  • 1,027
1 vote
1 answer
55 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/...
0 votes
0 answers
11 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 ...
0 votes
1 answer
211 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 ...
  • 5,270
0 votes
1 answer
39 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 ...
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 ...
  • 153

1
2 3 4 5
53