Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [hooks]

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

0
votes
1answer
8 views

How to display a message to a user, with the selections he/she has made from the contextual filter in drupal 7 views?

I have a view with more than one contextual filters. For example, filter on Age, and Gender. if the filter is on Age, and/or gender I would like to display a message to the user regarding the ...
-1
votes
0answers
18 views

I need a hook to media insert [on hold]

I need to know if exist a hook when some user add a content media in a kind of media type. I tried to use the hook_ENTITY_TYPE_insert() but it doesn't work for media.
0
votes
1answer
39 views

How to override other module function/hook from my custom module?

I'm currently working on a custom module which holds a list of organization IDs that will be used to match with an attribute I get from a SAML idP response. I'm currently using the saml_sp SAML ...
0
votes
1answer
13 views

File widget custom upload location

I am working on a custom module (based on Model project) with a file field attached to my custom entities, now I would like to save files in certain directories according to entity id eg: public://...
0
votes
0answers
27 views

Programmatically change the required state of a field

I need a field in a content type to be required but only based on the value of another field. I'm trying to enforce this via hook_node_presave but I'm not sure that's the right hook to use for this.....
1
vote
0answers
26 views

Why don't hook_file_insert() and hook_file_presave() need the cache cleared to work?

I think all hooks need the cache tto be cleared to work (or at least I thought until now), but it seems that these particular hooks don't need the cache to be cleared. I tried this even on a clean ...
0
votes
0answers
21 views

Creating new node entity during presave of another node entity causes SQL Exception sometimes [on hold]

We have a Donation Record Content type and a Donor content type for a Blood Bank management drupal application. A donor can have any number of donation record. The system does not explicitly require ...
0
votes
1answer
24 views

is there an alternative for hook_views_ajax_data_alter in drupal 8?

As the title sais, is there a similar behavior like hook_views_ajax_data_alter in drupal 8 like in 7? If not has anyone achived the same result programatically? Thanks in advance.
0
votes
0answers
17 views

How do I implement hook_custom_theme()?

We would like to allow users to choose between a day theme, night theme, and automatically set day or night based on time. We would also like this selection to be saved until they change it to another ...
0
votes
0answers
32 views

Remove string from [node:url] and node alias

Background We have enabled content translation where we detect based on the content language. This allows us to translate properly as needed, but it has a bad side effect. It will not only add ?...
0
votes
0answers
31 views

How do I add an error and welcome message?

How do I add an AJAX error and welcome message? I am using the following code, but it's not working. function mymodule_form_alter(&$form, FormStateInterface $form_state, $form_id) { if ($...
0
votes
0answers
31 views

Custom Entity View Date Picker

I have a custom entity with a date field in it. I have spent a lot of time reviewing several posts related to this issue: https://www.drupal.org/project/drupal/issues/2489476 https://www.drupal.org/...
1
vote
1answer
62 views

How to get the correct 'base hook' to override a template file in a custom module?

How can I find the 'base hook' to override a template file using a custom module? 'node' and 'user' are pretty straightforward, but others can be a little more elusive. Example code... MYMODULE....
1
vote
1answer
47 views

hook_theme_suggestions_HOOK vs. hook_theme_suggestions_HOOK_alter

Let's say some people are working on a contrib module (link) to provide some obvious template suggestions which are not covered by the default Twig Template naming conventions. View mode for fields, ...
1
vote
0answers
38 views

What's the difference between adding a template and overriding a template, from a custom module?

I found a paragraph in the documentation about using template files in a custom module. This way can be even used to override a template like I did here. However, I am wondering if this is the ...
0
votes
0answers
25 views

How do I get the paragraph fields values in hook_node_form_alter

I have a field named field_page_schedule which relates to an entity reference paragraph field and the paragraph has two fields named field_start_date_and_time & field_end_date_and_time. I need to ...
0
votes
1answer
24 views

Update the author_uid for an entity registration

I'm looking to update the author_uid for an Entity Registration in Drupal 7 programatically. I want to replace all anonymous users with the UID of 0 with another UID lets say 2 upon saving the ...
-2
votes
0answers
31 views

How to prevent access to node based on user role

I have created a new role in my drupal 7 gives view publish content permission on node. I have created new module implemented hook_menu when i am trying to access node it gives "access denied error" I ...
-1
votes
0answers
19 views

Add a custom variable in main menu template

I want to use a custom variable in my main menu template (menu--main.html.twig). After reading several posts, I don't see any solution. In a first try I tried to use a simply hook_preprocess_menu ...
0
votes
1answer
18 views

Alter menu link if logged in

I have a regular node in my main menu that: if an anonymous user clicks on it, the node should be shown regularly if a logged in user clicks on it, there should be a redirect to an external website ...
0
votes
0answers
25 views

How to add image field in a custom module form?

In our custom module, mymodule we have a form MyModuleForm where we want to allow for an image to be uploaded or chosen from already uploaded images. Below is the MyModuleForm.php file, but cannot ...
0
votes
2answers
34 views

How to remove exposed filter if value is supplied in url?

We have a view page (path = /some-path/) that has an exposed filter called category. The detailed view setup is below. How would we hide the exposed filter if it is supplied from the url? View setup: ...
0
votes
1answer
28 views

Redirect to home after NODE_ACCESS_DENY

My D7 customer uses the Workbench suite of modules to use taxonomy to allow fine-grained access to nodes successfully. But with a large amount of data to manage, sometimes they want to unpublish a ...
0
votes
0answers
35 views

How to conditionally bypass login restriction to access node

I have installed "redirect 403 user login" module to restrict nodes access anonymously. Now this condition working fine but my client gave another condition. He wants to display these node url's with ...
0
votes
0answers
18 views

Translate programmatically a menu lable

Translate programmatically a menu label I m using hook menu to get menu item programmatically. need to load menu item label based on the language code like how we used do with taxonomy term $...
0
votes
0answers
13 views

drupal_alter for event count in registration module not being applied

I'm trying to write a custom event counting function for the registration module. But I can't seem to figure it out. Im using the Entity registration module (version 7.x-2.0-beta2) to create events ...
0
votes
1answer
36 views

How to define template suggestions for node add and edit form by content type?

I have a content type Project and it has a more than 100 fields in the node form. The form fields are grouped in different section and category. I tried to use a field_group module to group and ...
0
votes
1answer
12 views

Add property to ProductVariationType via hook_entity_type_build()

Hy guys, I'm trying to implement a simple stock management in my e-commerce. The ProductVariation will have a stock_quantity field used to track product availability. I would like that ...
0
votes
1answer
26 views

how to get views field names/values for hook_views_pre_render?

I'm trying to figure out how to modify a view's results with hook_views_pre_render. How do I get the available values to work with? I've turned on Devel and Kint, but I don't see any array on the page ...
0
votes
2answers
37 views

MODULENAME_page_attachment_alter() Undefined [closed]

I have a custom module named rsm_library. I would like to use hook_page_attachment_alter() in rsm_library.module and called the hook as follows: rsm_library_page_attachment_alter($attachments); I ...
0
votes
1answer
24 views

hook_views_pre_render - how to print field x after each loop

I have a grouped view that displaces content containing multiple entity references. I have a field that generates multiple times, because of those entity references. I've looked into modifying views-...
1
vote
0answers
36 views

hook_file_download triggered twice on Firefox [closed]

I'm using a clean slate Firefox Quantum 63 testing my Drupal 8 website. It is well working on Chrome and IE but Firefox fired twice on hook_file_download API (some nodes automatically created twice). ...
0
votes
1answer
27 views

Add elements to webform dynamically via hook_form_alter

I'm trying to dynamically add multiple toggle fields to a form (in my case webform) via a form-alter-hook. function module_form_alter(&$form, FormStateInterface $form_state, $form_id) { .... ...
0
votes
0answers
19 views

Form API states not working when form loaded via Ajax

Drupal form #states not working when I am loading form via jQuery Ajax. $form['activity_container_' . $i]['new_comment_' . $i] = [ '#type' => 'textarea', '#title' => t('Your ...
1
vote
1answer
21 views

can we change block title using template_preprocess_block?

I am having a need to dynamically change the title of a block. Here is what I am trying but no avail. function MYMODULE_preprocess_block(&$variables) { if ($variables['elements']['#id'] == "...
0
votes
1answer
108 views

Alter Multiple Field Values by Testing “Field Type”

Drupal 8.x I would like to alter the value of all/any ckeditor/text fields on a node. Currently working with HOOK_node_presave(). Ideally, I'd like an agnostic approach that doesn't mind where the ...
0
votes
1answer
41 views

Passing Image through hook

Background: Im working in Drupal 8 and I have a paragraph type that contains a title and an image and I am trying to pass it through the preprocessor hook so I can set it inside a html template. For ...
0
votes
0answers
16 views

hook_block_view_BASE_BLOCK_ID_alter for machine readable name not working

I have a block with this machine readable name And I have a module named ef. In that I need to get the block name and do some manipulation on the title, but it isn't working out. as given in doc ...
0
votes
0answers
16 views

How do I enable translation tab for unpublished contents for users except administrators

In the node edit form the translation tab is hidden in unpublished contents for users except administrators and the author of the node? How do I give permission to translate those nodes for other ...
0
votes
2answers
61 views

Is there a hook for node after save?

How do I unpublish translations when the english content is unpublished? I tried to unpublish the language content programmatically when I am unpublishing the english content in the hook_node_update() ...
2
votes
1answer
25 views

How would we add Drupal Core modules as dependencies on custom modules post 8.6.2?

We recently updated to Drupal Core 8.6.2 and noticed there are changes to module dependencies. We are noticing that drupal: is added before the module names. We were unable to find any documentation ...
1
vote
3answers
150 views

Custom Theming Bootsrap Carousel with Paragraph Type

Background Info: I tried to create a custom theme for my carousel section and I am unable to get it to work. I have tried using the default carousel that Drupal comes with. I have tried using slide ...
0
votes
1answer
12 views

Edit custom field using user_presave hook during account creation

I have made a custom field for user field_custom_xyz from the admin GUI. Now after i saved it i got two tables into the database : one for data and one for revisions. I already have a huge database ...
0
votes
0answers
37 views

How to insert the store ID in a plugin?

I have a Drupal 8 site with a marketplace (several stores). I want to display in the "review" step of the "Checkout Pane" a checkbox with the sales terms. The terms of sales are accessible for each ...
0
votes
1answer
15 views

Unable to override default translation publishing status using entity_translation module

We are using the entity_translation module in a large site, and we have 57 defined languages. We have some custom date fields in each locale, and we are using some custom code to only publish the ...
0
votes
0answers
31 views

When Using Views Group By - Programmatically move a grouping to the end

I've got a Apache Solr Views display where I'm using "Group By" to group the results by a particular taxonomy term. I'm then sorting the results so the taxonomy terms appear in ascending (...
0
votes
1answer
41 views

Image field causes #access to reset to default

I am using ajax to show/hide a field based on a date field. I set the default access to TRUE. If the user selects a date of birth over 18 years old, $is_younger and consequently the access switch to ...
1
vote
1answer
29 views

Modify date popup structure

I would like to modify the date popup structure, in the image below you can see how date module builds the element. Drupal's default label is hidden, and it generates other to display the title. I ...
0
votes
1answer
27 views

How to add a column to DB with weight by using hook_update_N?

I want to add a column to a database by using hook_update_N(), but it should be 3rd column instead of last column. How I can achieve that please help in this regard. I tried to add weight but not ...
0
votes
0answers
12 views

How to move fields into secondary region where Menu Settings are located?

We have a need to move the language selector field to right column in the same section as the Menu Setting (see screenshot). Using Twig Debugging, we found that the template node-edit-form.html.twig ...