Questions tagged [hooks]
Use it for the mechanism that allows to extends module's functionality without editing its code.
2,640
questions
-1
votes
1
answer
15
views
How can i subscribe/unsubscribe to a simplenews newsletter programmatically?
I have the following code to set subscriptions to a simplenews newsletter on or off:
$user_load = User::load($userID_current);
$newsletter_subscriptions = [
'newsletter1' => 'on',
...
1
vote
2
answers
55
views
Hook post update not found
I have a problem with the drush updb command which does not find the hook post updates of my custom module.
I noticed that the module install saves the module's name string here in database, table &...
0
votes
2
answers
62
views
Attaching a library to only one custom module
I wrote a sample custom module (juniper) and created the corresponding juniper.libraries.yml file to link the CSS and JS. I am trying to load this library only on this module pages (/juniper). However,...
0
votes
0
answers
6
views
Why might a panel pane print a block as class="panel-pane pane-block..." vs class="block block--views..."?
I apologize if the wording for this question title does little to explain my problem. I'm so deep into not understanding an issue I'm having trouble describing it.
To preface, I'm quite a noob with ...
1
vote
1
answer
20
views
Module template for a comment field is not triggering comment_preprocess_field
I have a custom module in which I am trying to override a comment field's template in Drupal 9.3.
In my module file I have defined the hook_theme to override the core template in use. (comment.html....
0
votes
0
answers
30
views
Headless and custom node / entity access
I struggle to set up custom access rules for "nodes" that are viewed via the
jsonApi
entityQueries which response via json endpoint
What I try to achieve:
I need to skip a node, that ...
0
votes
1
answer
54
views
Why does this code to create a dependent dropdown not work?
I am trying to implement the dependent dropdown option in Drupal 7 from this URL http://w3shaman.com/article/creating-ajax-dropdown-drupal-7. When changing the first dropdown value, it is showing the ...
1
vote
1
answer
35
views
using hook_form_alter() to change year range of datetime select widget, with deltas for multi-value fields
I have multiple date fields on a node form for which I am using the select widget. The year select list has a range of years that is far too wide for our purposes (1900-present), so we want to limit ...
1
vote
0
answers
30
views
How to use groupBy on query based on the search API views?
My search api query returns a list of articles with its nid and field category. I would like to group by category. I mean 1 article by category.
Is there a way to accomplish this?
I tried via the ...
0
votes
1
answer
46
views
How can I add a button to every row of custom column?
I have created a custom column in the content listing section using hook_views_data(). I want to add a button to the every row of that custom column. Can anyone help me with this issue?
function ...
0
votes
0
answers
23
views
How to access block contents in run within hook_form_alter? [duplicate]
I am using Drupal 9 and I need to get the block content within hook_form_alter implementation, I tried these lines:
$bid = 'consumerorganizationselection';
$block = \Drupal::entityTypeManager()->...
0
votes
1
answer
64
views
How can I dynamically change the default value for views exposed filter based on the terms weight?
I have an exposed filter in a view is referencing taxonomy terms from specific vocabulary. The operator allows selecting a term as the default value for that filter. What I want to achieve is to ...
1
vote
0
answers
98
views
How do I add a query condition to the QueryPluginBase in hook_views_query_alter()?
Using hook_views_query_alter() for a view configured as a REST feed, I'm attempting to add an additional filter value to the query, based on the presence of multiple filters passed via the URL.
I need ...
1
vote
1
answer
87
views
Is there a way to add / remove items from an unlimited cardinality field in form alter / after build?
In a node edit form, I am trying to add items to a multivalue field with unlimited cardinality in a form builder hook, like form_alter or after_build. I can't figure out how to do it, though, at least ...
4
votes
1
answer
63
views
How to add an item constraint to a field
How do I define an item level constraint, as opposed to a constraint on an item list?
In the comments of \Drupal\Core\Field\FieldConfigInterface, there is this note:
* If you wish to apply a ...
0
votes
2
answers
51
views
How can i add a class with 'html' tag(not with body) for specified pages (10 nodeID's)?
How can i add a class with 'html' tag(not with body) for some specified pages (10 nodeID's) ? I tried with html preprocess, but didn't worked,
0
votes
0
answers
29
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
22
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 ...
1
vote
2
answers
61
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 ...
0
votes
2
answers
96
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
29
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
88
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
20
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
147
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 ...
0
votes
0
answers
27
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 ...
1
vote
0
answers
77
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 ...
1
vote
1
answer
120
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 ...
0
votes
1
answer
55
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
29
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
43
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 ...
0
votes
0
answers
19
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
48
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 ...
2
votes
2
answers
374
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
286
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 ...
0
votes
2
answers
166
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()->...
0
votes
1
answer
25
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 ...
1
vote
0
answers
38
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
623
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 ...
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
84
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
45
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
88
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(...
0
votes
1
answer
74
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 ...
0
votes
1
answer
255
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
67
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
53
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
126
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 ...
-2
votes
1
answer
187
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 ...
0
votes
1
answer
322
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
390
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'...