Stack Exchange Network

Stack Exchange network consists of 175 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.

1
vote
1answer
13 views

Set value on a new term based on a vocabulary custom field

I want to set the value of a field of a term based on a custom field set on the vocabulary. Basically if the vocabulary promote_to_index field is checked I want to the field_index_page of the term ...
0
votes
0answers
13 views

How can I enable a block, set the pages it is visible on, and dynamically change the contents of the block from inside my custom module?

I have a custom module in Drupal 8 called hello world. in that module I make a custom block called Hello World!, I am trying to enable the block and set it's region to "sidebar_second" from inside my ...
0
votes
1answer
12 views

How do I change the Views (Entity Reference) filter via AJAX?

I have an entity form that allows an admin to select a content type (checkbox) and an autocomplete field that is tapped into a VIEWS Entity Reference (via the Reference Method). Goal: What I would ...
0
votes
0answers
15 views

Bit stuck on trying to just some hooks in a custom module [on hold]

I am trying to write an auto increment in a custom module that will check how many records exist for a specific content type (responses) and then add to a custom field the count + 1. Response 1, ...
-2
votes
0answers
20 views

how to alter the drupal webform data before post to other url

I have a drupal webfrom with one radion button input and another one is number input and i am posting the from to outside url and my question is i need to aissign number input value to radio input if ...
1
vote
0answers
37 views

Error when saving node with submit callback added in form alter

Scenario: I am building a Multistep Wizard for two different content type. Magazine Information Magazine Details On 1st Node I have by Default, Save/Submit Button Available. Now i want to add "Save ...
0
votes
1answer
47 views

Get node based target id from entity reference

We have an Article content type which has an Entity Reference field called field_document that is linked to the Media bundle type of Document. In mymodule we need to write a hook that will take the ...
0
votes
0answers
9 views

Is it possible to use hook_views_query_alter to compare the value of two fields?

We have a D8 site with a view that links a Content-->Paragraph-->Content. We also have language translation enabled so the views_ui module displays duplicate rows for all combinations for the content ...
0
votes
1answer
23 views

Drupal 8 Alter views exposed form

I have a view that in that view I set up 3 exposed filter, all working fine. I need to set a condition to show the third filter option to a specific user, it can be checked according to the user role, ...
0
votes
0answers
20 views

View presents fewer items per page after using Unset

I'm deleting items by means of an unset in hook_views_post_execute, as far as the view I have it configured by 10 items per page. The problem is that it shows me sometimes 6 or 8, I have searched for ...
0
votes
0answers
33 views

Hooks vs Events vs Extension - when to use what?

Im writing a module. One thing it will do is alter the menu edit form. I've been looking at core code and examples on the internet and can't really figure out when to extend Drupals core classes, use ...
1
vote
1answer
21 views

Which hook to use for updates of all nodes of a particular type

This question is about Drupal 7. For a particular node type, let's take three examples: a) book b) article c) customcontenttype I would like to be able to capture the moment of an update of an ...
0
votes
1answer
19 views

amp-img tag, replace to simple img

I need to change this tag <img> to <amp-img>, I've been researching about this and I have this function for change the img tag. function amptheme_image($variables) { // Remove RDF ...
-2
votes
0answers
15 views

How can we alter drupal primary links?

I want to add and remove some links at runtime. How can I do this in Drupal 6? I want to display them on a conditional basis.
1
vote
1answer
11 views

How to change image style using hook_views_pre_render()

I am trying to adapt the following Drupal 7 code to Drupal 8, in order to set a different image style to every image in a view: // Assigns a random style name to each image function <MODULE_NAME&...
3
votes
2answers
80 views

Alter webform messages found in WebformMessageManager

List item Is there a way to change the hardcoded webform messages from /webform/src/WebformMessageManager.php? for example, the one on line 284 case WebformMessageManagerInterface::...
-1
votes
0answers
37 views

How to disable caching for hook_preprocess_menu

I have used hook_preprocess_menu to add the child to the menu items. The child's are a specific content type. If i make changes to the content the changes are not reflected to the menu item child ...
0
votes
0answers
16 views

How do i alter commerce product price?

I have installed Drupal 8 and using commerce 2.x, I want to alter price according to the user set its own price on user field of a user who created the product. example: user1 has its user price 10 $ ...
1
vote
1answer
34 views

Theme hook not found

I have a custom module that implements a webform handler. I'm seeing this error in my Watchdog log when I navigate to admin/structure/webform/manage/myform/handlers: Theme hook ...
0
votes
3answers
40 views

Using MYTHEME_page_attachment_alter does not alter the favicon

Based on other similar stackexchange questions and documentation, I've implemented the following in the MYTHEME_page_attachment_alter function in MYTHEME.theme file to change the favicon based on the ...
-1
votes
1answer
11 views

How do I attach JS and CSS on Slick Views

I would like to attach a CSS file and a JS library on Slick Views module from a custom module. Is there a hook function for Slick Views or any solution?
0
votes
0answers
18 views

How to modify term reference

I have added term reference field on one content type i want to alter that term reference list. I have search in drupal.org site but not information is find. Can any one help me how to alter the ...
0
votes
0answers
38 views

Drupal commerce 2 add to cart form not working for anonymous user

When anonymous users add a product to the cart it’s not working, but it works for authenticated users. Following code is creating the form function mycustommodule_preprocess_commerce_product(...
0
votes
0answers
11 views

Desable showing language en in url for specifique content type

i have website multilingue version english and french i find a module who can add EN And FR to link here This module work for me but , but the problem this module enable languages in all pages but i ...
-2
votes
1answer
31 views

after 8.6.14 set entity reference field via form alter failed

after the core update some how the form alter set field was broken, I tried multiple methods but its not working like : $form['field_trip_reference']['widget']['#default_value'] = array(820); $...
0
votes
1answer
44 views

I can see the changes I made (as an administrator) but as an anonymous user, I can't

Have you had any problems like this before? I appreciate your help. When I'm an admin and update a node (custom module), I can see the changes I made (as an administrator). However, when I'm an ...
0
votes
0answers
118 views

Preprocess Menu Link Independent of menu.html.twig?

I am hoping there is a way to alter a menu link independent of menu.html.twig Motivation is this example from Bootstrap theme menu.html.twig: {% set link_title = item.title %} {% set link_title %}{{ ...
-1
votes
1answer
28 views

module_invoke_all() pass arguments by reference?

when I implement the HOOK_node_presave , I can access to the $node and alter it ex: function drupal7_test_node_presave($node){ $node->title = 'Abricoooooooooooooooooo'; } the strange thing is ...
0
votes
0answers
30 views

Create second button and reload form page

I have a form with Entity Registration module. I have to add another button in order to save and add another account to registration. For this i created a second module and i try to overide the ...
1
vote
0answers
28 views

Redirect Page on Change of Exposed Filter

We have an All Articles view that is added to the http://www.example.com/articles page that is supposed to display all pages where content type is Article. The content type has a taxonomy term, ...
0
votes
0answers
26 views

Inline Entity Form hook_alter causes Ajax error on 'Add another' button

I created the module to hide some fields in my Inline Entity form. Although it works I faced the problem. I need to add multiple custom content nodes with Inline Entity Form. When my field setting ...
0
votes
2answers
42 views

Hook naming conflicts: what happens?

This is a theoretical question. If some modules define hooks, and two modules implementing two separate hooks ended up with functions with the same name, could that cause a conflict or problem? A....
1
vote
1answer
27 views

Modify existing custom content form

I'm very new to Drupal development and I am completely stuck(. I have a custom content form, where I need to hide some fields in Inline Entity Form. I am trying to write my own custom module to ...
0
votes
1answer
43 views

Optimize image that does not have an image style

We are using the imageapi_optimize modules with the imageapi_optimize_resmushit. We are able to flush the caches for all the image styles and see an improvement. However, there are images that are ...
0
votes
1answer
31 views

Get Absolute url using hook_preprocess_node

We are attempting to change the $variables['url'] from a relative to absolute URL within the mymodule_preprocess_node() hook. The $variables['url'] is displayed as a <a> element within our node--...
0
votes
1answer
25 views

Get Field Name Being Deleted From Configuration Updates/Delete Form

Trying to get the field_name being deleted when viewing a route like entity.field_config.user_field_delete_form. Example path: /admin/config/people/accounts/fields/user.user.field_name/delete Some ...
0
votes
0answers
46 views

How to populate/customize a view exposed filter's options based on the current nid?

Selecting a filter option after successfully populating the options triggers an "Illegal choice has been detected." error if the population logic is dependent on a Drupal service like: \Drupal::...
0
votes
1answer
36 views

How to override html.html.twig template for my custom page? [closed]

I need the different html template for one my custom page. So I try suggestions hook alter, but it's don't work. /** * Implements hook_theme_suggestions_HOOK_alter(). */ function ...
1
vote
1answer
19 views

Remove library from page based on node field value

We have a content type, Basic Page, where we may want to include 3rd party CSS such as Bootstrap. However, this 3rd party CSS may conflict with our custom theme, mytheme. On the Basic Page, we added a ...
0
votes
0answers
15 views

Display current filters from view

We have a landing page that has a search block that has exposed filters for category and content type. We are using facets to add the exposed filters to the page. The exposed filters are displayed to ...
-4
votes
1answer
29 views

If admin theme is 'seven' disable the module

So in a custom module, I'd like to check whether the theme is seven or not, if it's seven the module shouldn't load/work. Note: I have a module that shouldn't override half of UI of seven theme but ...
0
votes
0answers
14 views

Creating menu tabs in a child page

I have a suite of modules that go together, and they are all ideally housed under one parent item on the 'management' menu. The normal pages of these modules are correctly being placed under this ...
0
votes
0answers
24 views

Trying to send data from client (JS) to server (D8) using jQuery.ajax [duplicate]

I'm new to D8 but have some D7 experience. I'm trying to receive some JSON data from the client and process it in my module. I have successfully received (I can break on it in my debugger) the ajax ...
0
votes
1answer
84 views

Get Entity ID when is saved

I need to capture the entity_id when the entity is saved. The ID will process and insert in a custom field. I use hook_entity_presave(), but when is a new entity the ID is void. Is there any way to ...
1
vote
2answers
60 views

Get node's view mode within template_preprocess_page

We have to get the current node's view_mode from within the mymodule_preprocess_page(&$variables) hook. When we tried the following we could not get the view_mode after performing some validation ...
1
vote
1answer
24 views

Create config object with array containing key-value pairs

We have a custom module, mymodule, that we want to use to create a config object for so that it can contain an array of key-value pairs. We need to be able to click button Add More on the form that ...
0
votes
1answer
25 views

Custom Entity Type and Bundle Creation

I've been building custom entities for a while now, but have been using the entity construction kit (eck) to build them. This has limitations as it requires you to #1 depend on the package for new ...
0
votes
1answer
20 views

Recursion when reading field in hook_entity_load

Is there a preferred approach modifying values? I need to modify a value when a node loads, but must use other values from the node. The code below causes recursion errors. function ...
0
votes
0answers
25 views

hook_form_alter : Not authorized value in a view exposed filter

I am using Drupal 8. I have a view that shows some public content and some group content. I try to add a filter on group name as select list. I would like to have in the select list an option to get ...
3
votes
1answer
82 views

applyUpdates() is deprecated. Is it really needed in hook_install() anyway?

I maintain a contrib module which defines two base fields, but these are not added to any content type on installation, as this is done during admin config. The module has // Add our base fields to ...