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
7 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
27 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 ...
-2
votes
0answers
18 views

Unable to print view result in custom template [on hold]

I have created a view in drupal 8 and then I have created a custom template. where I use the 'views_get_view_result' drupal core api. but no result found. Here my code <?php $view_result = ...
-4
votes
0answers
19 views

Table not showing in database drupal 8

In a custom module in module.install I'm creating two tables in the hook_schema hook. I've uninstalled and reinstalled the module and cleared the cache but the tables still don't appear in the ...
0
votes
1answer
12 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
8 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 the drupal_get_js() is not supported anymore. Any other way to fetch them?
1
vote
1answer
20 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
45 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
1answer
24 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
0answers
9 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
32 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
12 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
15 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)...
0
votes
1answer
50 views

Can I get the absolute path to the frontpage in theme_preprocess_html?

Is it possible to get the absolute path to the homepage or <front> eg: https://www.domain.com/homepage in the theme_preprocess_html hook? I tried global $base_url but it throws an error.
0
votes
1answer
39 views

Convert node URL to absolute

We are using Drupal Core v8.6.2 and we have a url variable in our node--page.html.twig template. While using ksm() and {{ kint() }} we are finding that if we use hook_preproces_node($variables) that ...
0
votes
1answer
29 views

Error: Call to a member function addWhere() on array in hook_views_query_alter()

I'm getting the error 'Call to a member function addWhere() on array' in my hook. Any thoughts? I just need to add WHERE clause to my query. use Drupal\views\ViewExecutable; use Drupal\views\Plugin\...
1
vote
1answer
41 views

Get Link value in Media entity

We have a Media type called Documents that has a Link field called field_link. We need to obtain the URL (external or internal) from the field so that we can use to wrap block elements inside of a <...
0
votes
0answers
13 views

Theme Form Elements

I'm using the following to format field elements in my theme: function theme_form_element($element, $value) { $t = get_t(); if ($element['#type'] == 'checkbox') { $output = '<div class="...
1
vote
1answer
27 views

header and menu is missing from Login module page--user--login.tpl.php [closed]

I am implementing Custom Login module but Header is missing... My Directory is : modules | --- module_name | --- css | --- module_name.info | ...
0
votes
1answer
23 views

How can I get the current node view mode and add to block template suggestion?

In my code, I need to get the current view mode of the node to be able to pass it to be used as a block template suggestion. The function I have set up is able to grab all available view modes, but I ...
0
votes
1answer
45 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
16 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
29 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
28 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
1answer
35 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
37 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

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
77 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
50 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
41 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
30 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
27 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 ...
0
votes
1answer
21 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
68 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
37 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
30 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
39 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 ...
-1
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
39 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
33 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
38 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
34 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
39 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
31 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) { .... ...
-1
votes
0answers
24 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
31 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
111 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 ...