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.

-4
votes
1answer
27 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
13 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
18 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
15 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 ...
0
votes
2answers
32 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
19 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
24 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 ...
-2
votes
0answers
18 views

hook_form_FORM_ID_alter() is not working [closed]

hook_form_alter() works fine but hook_form_FORM_ID_alter() doesn't. I created a hook to alter the action after the submission of a form. The hook gets called when hook_form_alter() is implemented, ...
-2
votes
2answers
34 views

How to get value of array in custom email

I have custom form for emails. In the putput email, I always get the index of the choosen option, not the option string. Given this form element definition, how do I get, for example, Soins Duo ...
0
votes
1answer
13 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
16 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
71 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 ...
0
votes
1answer
19 views

How do I correctly implement hook_bootstrap_colorize_text() to alter button colors in a Bootstrap sub-theme?

I have read similar questions on here, but I'm still struggling for an answer for this. I'm trying to implement hook_bootstrap_colorize_text() to alter button colors in a Bootstrap sub-theme. I ...
0
votes
1answer
36 views

how to change h2 tag for div in block_view

I've created a block like this function mymodule_block_view($delta = '') { if($delta == 'myblock') { $block['subject'] = 'mytitle'; $block['content'] = myfunction(); } ...
0
votes
2answers
48 views

Block machine name [duplicate]

How do i get the block machine name $block_id programmatically in Drupal 8? $block_id = 'machine_name_to_determine'; $block_config = \Drupal\block\Entity\Block::load($block_id);
-1
votes
0answers
17 views

Is has_js drupal 7 cookie safe even not flag as secured?

Netsparker detected has_js as a vulnerability on drupal 7.
0
votes
1answer
20 views

Template suggestion don't work with a custom menu link (custom route)

In a module I have created a custom link by creating a custom route inside the mymodule.routing.file.yml and the mymodule.links.menu.yml file. In my theme.theme file I have defined a hook_page_alter ...
0
votes
1answer
13 views

Hook_views_query_alter: adding condition with entity reference value

I need to filter a table result based the current user. I added this condition in my hook_views_query_alter function my_module_views_query_alter(&$view, &$query) { global $user; if ($...
0
votes
1answer
27 views

Get Node from link

Within the mymodule_preprocess_views_view_row_rss(&$variables) hook, we are able to get the link by using $variables['row']->link. However, we are not able to access the node for which that ...
0
votes
1answer
63 views

Would replacing hooks with events be a good practice?

Do you think it would be a good practice to replace hooks with events? I mean dispatching an event inside a hook to subscribe afterwards. For example if you have 20 hooks in your module, is it ...
0
votes
1answer
36 views

Add image to RSS Feed

We are using the Feed Display for a view where we want to display all Articles in a rss.xml file. Below are the View settings. However, we cannot find a way to add an image attribute that meeting the ...
0
votes
0answers
31 views

How to grab taxonomy term with node_presave hook

So I'm running a hook to update the title with values from the node whenever the node saves. I want to update part of it with a taxonomy term but when I try to get the term from the entity it says it ...
0
votes
1answer
44 views

Pass hidden fields using drupalSettings to Twig template

We have a paragraph field (field_pr_custom) on the Basic page content type that has a custom twig template, pr-custom.html.twig. In the twig template, we need to pass in an array inside of a <...
0
votes
1answer
24 views

Validating a node body

hello i am trying to validate the content of the node body for certain text having some trouble with it. it outputs an message "array". function test_form_alter(&$form, FormStateInterface $...
0
votes
2answers
27 views

Change Selectlist to Radio button [closed]

I creation a view with sort Criteria who sorting product the problem when i click in i save i see in page a selectlist but i want to change selectlist to radiobutton , ps: i create a ...
0
votes
1answer
43 views

How to add css class on click of CKeditor table button?

We are using the CKEditor module provided from Drupal 8 (v8.6.2). There is a need to add a css class to the table when it is added to the Body field (text formatted, long) after someone clicks on the ...
0
votes
0answers
28 views

hook_views_data_alter to turn a text-titles body field content to “bold”

How it would look a hook_views_data_alter to turn a texts "body" content to "bold". This means adding an html code element to the content of the body. For example: "First name: is simply dummy text ...
0
votes
1answer
31 views

How to limit access to vocabulary term by role?

We have two roles: Reviewer and Editor along with two content types: Basic and Article. We have a couple vocabulary terms and taxonomy fields on each content type. Currently only users with Administer ...
0
votes
0answers
27 views

Programmatically Alter Billing/Shipping Address form

I am using Drupal Commerce 2.11 and Drupal 8.6.9. I need to make a simple edit to the address forms in the checkout - changing the #empty_option of the "locality" select boxes. However, this is ...
0
votes
0answers
54 views

How to combine two date fields and alter its value programmatically based on field value?

I have two fields field_start_date and field_end_date and under manage display section I have set the field format for field_start_date as F d field_end_date as - d Y I need to combine the two fields ...
0
votes
1answer
27 views

Link field is removing query parameters

We have an Article that a link field, field_link. When we create a new page of type Article, we set the link field to have a URL of www.example.com/somepath?someid=123345 and label of View. When the ...
0
votes
0answers
24 views

Is there a hook invoked after user confirmation?

This question asks it (presumably for Drupal 7), but the solutions all appear to be specific to D7 and not applicable in D8, so that's effectively a different question. It appears that ...
0
votes
1answer
52 views

Bulk update pages that use old URL alias by content type

We have a content type, Basic Page that recently had the URL pattern changed from www.example.com/page/page-title to www.example.com/page-title. Under the Pathauto settings found at /admin/config/...
0
votes
1answer
28 views

How can I use postsave method extending WebformHandlerBase for submitting to account fields [closed]

I created a webform handler class extending from WebFormHandlerBase: The method, postsave has the following code: public function postSave(WebformSubmissionInterface $webform_submission, $update = ...
0
votes
1answer
28 views

Trouble redirecting users after implementing LDAP

We had a feature on our site where we redirected users with certain roles to a particular landing page upon logging in. In a custom module, we implemented hook_user_login(\Drupal\user\UserInterface $...
0
votes
2answers
75 views

How do I run hook_views_data_alter()?

So I have already read and followed everything I could find on that issue: putting my_module_views_data_alter(array &$data) in my_module.views.inc file in the root directory of my_module, ...
0
votes
2answers
42 views

Properly merge array values

We have the following mymodule_preprocess_node hook where we add two arrays with two key-value pairs. In twig, we would like to merge the values. How would we merge the two arrays in twig? Here is ...
-1
votes
2answers
55 views

How do I force the download of a .zip file, with contents retrieved using drupal_http_request()?

when i do this curl request my files are getting saved in drupal root instead of getting downloaded to browser in the bottom. can anyone help me what wrong am i doing here. below is the code i'm using....
0
votes
1answer
27 views

How to change the 'Quantity' label in commerce-order-item-add-to-cart-form

I'm trying to modify my 'Add to cart' form, changing the 'Add to cart' button text and the 'Quantity' label: if(strpos($form_id, 'commerce_order_item_add_to_cart_form_commerce') !== false) { $...
2
votes
2answers
48 views

Automatic username generation from name fields at registration

Drupal core 8.6.5 I am trying to change the user registration process to omit the username field and generate the username from the first name and last name. Since I am new to Drupal and want to ...
0
votes
1answer
16 views

Theme preprocess for module's template variables using dynamic path

I am doing templating for a module that adds a block in the module's folder so that the template can be there, and it may be overridden in the theme if desired. I want the module to support different "...
0
votes
0answers
15 views

Get path of advanced aggregator files

Is there an easy way to get the files? I would like to send the aggregated files over to a debugging service but drupal_get_js() isn't supported anymore. Is there other way to fetch them?
1
vote
1answer
79 views

How do I implement hook_views_post_execute

I am attempting to modify the output of view programmatically using hook_views_post_execute. I created the usual module structure (in this case using drupal generate:module. I am able to use other ...
1
vote
1answer
51 views

How many libraries is too much before there is a performance issue? [closed]

We are using Paragraphs module to allow for selecting of up to 15 different Paragraph Types. As part of this, each one requires its own CSS and JS since they are vastly different. We already have a ...
0
votes
2answers
143 views

How to load paragraphs fields in hook_form_alter to disallow access?

I have a field inside a paragraph referenced in an taxonomy term. /** * Implements hook_form_alter() */ function custom_general_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $...
0
votes
1answer
15 views

Print custom field in user edit form in block

Following code prints user edit form in block: function notifikacie_custom_block_info() { $blocks['user_profile'] = array( 'info' => t('User profile edit'), 'cache' => DRUPAL_NO_CACHE, )...
0
votes
1answer
28 views

How can I change the value of a field in node / [id] / edit?

I should change the value of a field before it is rendered. I tried with [NAME_MODULE]_node_view but it is not invoked when I edit the node. Thank you so much.
-1
votes
1answer
43 views

How to hide checkbox 'Notify user of new account' for roles who can add user

Have scenario in Drupal 8, where Editor role can add users with dummy mail and sends login info through phone SMS to added users. Hence, the checkbox 'Notify user of new account' should be hidden ...
0
votes
0answers
15 views

Proper Schema file for integer and select

We have a custom module, mymodule that has an admin form where it stores field of type: number and select. I need to create a mymodule/config/schema/mymodule.schema.yml file, but don't know what to ...
0
votes
2answers
24 views

Get taxonomy terms added to nodes

I am trying to get all the taxonomy terms added to a node. How would I get only the taxonomy term values that are added to a code in a mymodule_preprocess_node hook? Current term list: value1 (tid=1)...