Questions tagged [hooks]

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

Filter by
Sorted by
Tagged with
0
votes
1answer
20 views

hook_node_access() doesn't work for anonymous users

I am new to Drupal 7, I am still unable to understand hook_node_access operation I am trying to give view access to the basic content types nodes for anonymous users but it is not working. It is still ...
0
votes
1answer
41 views

Hook on drush cache:rebuild

Is it possible to hook on drush cache:rebuild before the command is executed? I've seen some hooks for afterwards, but I am trying to compile my less files into css before cache the is rebuild. I'd be ...
1
vote
0answers
25 views

Views_pre_render How do I get a file's path url if I only have the file name?

I have a dynamically created Views listing page where I display fields from "Collection Items" node type in this order: Item Title Item Status Date Stamp Document (uploaded file. I'm only ...
1
vote
0answers
20 views

Defining some custom permissions with hook_node_access_records and hook_node_grants

I'm trying to figure out the best way to handle some custom permissions with Drupal 8, using hook_node_access_records and hook_node_grants. Here is my setup: I have some nodes of type "group&...
0
votes
0answers
14 views

Optimizing images before saving

I have a Drupal 8 website with customer contributed content. The images uploaded by customers are not optimized, so I am using image optimization pipeline of the imageapi_optimize contrib module to ...
-1
votes
0answers
9 views

how to update salesforce id in drupal 7 on user save

I am sending a user creation request to drupal 7, upon successful creation of the user, salesforce is automatically pushing the corresponding salesforce id to drupal 7. I don't want this automatically ...
0
votes
0answers
13 views

When is [“und”] necessary in pre process hooks?

I've noticed in preprocess hooks that sometimes a field's value is found at - for example: $vars['field_caption'][0]['value'] and sometimes it's at $vars['field_caption']['und'][0]['value'] Which ...
0
votes
1answer
28 views

Create a node when the user is activated

Drupal Version: 8.92 Part 1. I am trying to create a node when the user is activated by the administrator for the first time. However, I am not able to find the right event/hook to execute the code. I ...
0
votes
1answer
36 views

how to insert data to the database table with hook_update_N

i have just create a table inside the file mymodule.install , the database was created successfully but not for the hook_update_N , 8001,8002 and 8003 , they tell me '[success] No pending updates.' so ...
1
vote
0answers
19 views

Pager for custom view query plugin which displays data from external api Drupal 8

Hi I have a requirement to display the data from external api but should not be imported into any entities. What I did is I have written a custom view query plugin which displays the data from ...
1
vote
1answer
19 views

how to add attributes of the parent taxonomy in the DOM?

I am displaying a taxonomy "category" on a node, a view of that node ,and a search facet. This taxonomy has 2 levels. How can i add to the rendered HTMLs, i guess using preprocessing hooks, ...
-4
votes
0answers
10 views

Hook for dropdown field within config pages

In my config pages, I have embedded a paragraph type which in turn has two fields. I want to write a hook for a dropdown field within the paragraph type , where I can show and hide other fields for eg ...
0
votes
1answer
15 views

hook_form_alter add field after submit button to exposed view

I'm trying to add a field that would be displayed after the submit button in the rendered HTML in my hook_form_alter. e.g. $form['include_card'] = [ '#type' => 'checkbox', '#title' => t('...
-1
votes
1answer
66 views

Form in custom module using Controller: The HTML tag form isn't present in Twig

I'm trying to render limited user edit form on custom page using Drupal Controller. In the routing.yml I defined _controller, I do not want to use _form. I want to display on the form e.g. only ...
-2
votes
0answers
22 views

What is the order of execution of node related hooks?

What is the order of execution of node related hooks in Drupal? For example, if I load the node page, preprocess and HTML preprocess hooks are getting executed. What's the sequence of execution?
0
votes
0answers
47 views

hook_entity_predelete never called

I have tried to create a hook that deletes an entity of type notification when the entity of type deadline is deleted, but the hook never gets called. Entities of type notification have one referenced ...
0
votes
1answer
22 views

How to allow multiple values in a single value textfield

I am using views_conditional module for Drupal 7 and would like to use a comma separated array (i think this is called an array?) of values in the "This value" textfield. For example, I ...
0
votes
0answers
11 views

8 Field autocomplete hook [duplicate]

Is there a hook available to modify / alter the title of content in this list ? It's a autocomplete widget. I just want to add the content type.
1
vote
1answer
34 views

How to programmatically reference entities?

I am trying to reference an entity within my hook, so that every time a new entity is inserted, I create another entity referencing the first entity. I have not yet found a working way to reference an ...
1
vote
1answer
31 views

Where are Commerce 2 hooks (or Events) in Commerce 2

I am working on replacing our payment system from D7/DC1 to D8/DC2 and the original code makes use of hooks. I have replaced some of them with events but I cannot find any information on the DC2 ...
0
votes
0answers
13 views

Form #states API by content type

I have a content type A. In this content type, i have paragraph (between 0 to n) with 2 fields. First field is content type select (A, B and C). Second field is based on the first field, only need to ...
0
votes
0answers
16 views

Alter form field inside webforms

I have created a custom module in order to alter a webform that I created in the admin in drupal 8. I need to add ajax function to some fields. My problem is that I can not retrieve the field inside ...
0
votes
0answers
35 views

Add class to button with specific class

I'm trying to add the class 'on-load-click' to any btn with the class 'webform-submit' <div class="form-actions"><button class="webform-submit button-primary btn btn-primary ...
0
votes
1answer
51 views

How to add a field to menus?

I am trying to add an extra text field to the menu entity. My field is showing up and saving input but the input saves for all menus not just the one I entered the data for. This is how it is now: ...
-2
votes
0answers
17 views

Change taxonomy term of node through comments

I have a node with status. Status is a taxonomy with states - open and closed. I need to change the status of this node to "CLOSED" using the drop-down menu and submit on the comment. How do ...
0
votes
2answers
66 views

How to create new entity within a hook?

I am trying to create a hook that creates a new entity('Notification') when an entity of another type is created (either of type 'Deadline' or 'Message'), but I can't seem to figure out how to add a ...
-3
votes
1answer
61 views

How do I unset a field in a node with the help of hook_node_view? [closed]

function test_node_view(array &$build, Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) { updateDisplay(); } function ...
1
vote
0answers
91 views

What is the exact process of resetting a password using Node.js?

I am using Node js as front end and drupal as backend, i am trying to develop a reset password api. As per my finding there are three steps for the same. Request a Password (Send an email with secure ...
0
votes
1answer
22 views

Editable table column data

In drupal 8, I am writing a custom module and in one of the function in controller -I am fetching data from an external API, then displaying it in table format using - foreach($rec as $data) { ...
0
votes
0answers
19 views

Change Dynamic Entity Reference field widget

I am using Drupal 8. I have used the Dynamic entity reference module. Added DER field. I need to change this field widget from autocomplete to a select list. For this, I have used ...
1
vote
1answer
44 views

Filter the list of entities referenced by “Entity reference revisions” field

I have a content type "Slider" which uses an Entity reference revisions field named "Slides" to save reference to various paragraphs that are then displayed on the frontend as a ...
0
votes
0answers
27 views

What’s the right way to create a Webform node when adding a webform?

I am new to Drupal. I want to create a Webform node when adding a webform. I used the code snippet in https://www.drupal.org/docs/8/modules/webform/webform-cookbook/how-to-automatically-create-a-...
1
vote
1answer
47 views

Change field access per user

I am trying to customize the access of user fields. We have an internal list of all users, which all members can access (for things like mail/address/phone number). However, due to privacy, each user ...
0
votes
2answers
21 views

Menu hook callbacks not working for anonymous users

My custom error handler module is somewhat based on the customerror module, but instead of returning markup, my menu callback function redirects based on the original path. It registers error paths as ...
0
votes
1answer
10 views

How to edit the id of a form element of a content type?

I have a content type with a text field that I need Javascript to do some work on (when in the content type add/edit form). I prefer to have Javascript identify the form element by it's id so I would ...
0
votes
1answer
23 views

Output node reference field data in page.html.twig

I have a homepage node-type in which I have an entity-reference field holding 3 references to 3 separate custom blocks. The theme I'm working on requires that my 3 element reference field needs to be ...
0
votes
1answer
60 views

How can I add classes to the rendered “body” field on a content type?

Preface: I don't often work with Drupal, so I may not be using the correct terminology or fully understand the stack. Please bear with me, I'll do my best to be as clear as possible. I want to filter ...
0
votes
0answers
19 views

How to get drupal to check for a twig template in the active theme folder before checking the module folder?

I'm developing a contrib module for Drupal 8 that sends email notifications to group members when new content has been posted in groups they have subscribed to. The module defines some new view modes ...
0
votes
1answer
27 views

How render view with programmatically passed parameters of contextual filter

I am using Drupal 8. Added new view My Vocabulary and created a contextual filter with paragraph ID. Now I need to render the view with passed parameters to contextual filter. What hook to use to ...
0
votes
1answer
11 views

How add conditional required field

Need: If we select a value in a drop-down list field(A), then we need to display and set as required field(B). Note: the field(B) is a date range. I tried to add states with a hook form alter $...
0
votes
1answer
51 views

Commerce hook attributes refresh alter

Commerce 1.x (D7) has a hook _commerce_cart_attributes_refresh_alter(&$commands, $form, $form_state) that allows modules to add arbitrary AJAX commands to the array returned from the Add to Cart ...
0
votes
1answer
16 views

render call in hook_node_presave uses admin theme

I am using hook_node_presave() to render my node and then save the output to a field field_node_cache. However, when I do this, the renderer uses the admin theme, whereas I would like to use the site'...
0
votes
2answers
51 views

Can't get token replacement to work

I have nearly this exact case but as it applies to Drupal 8: Store token replacement values in the database rather than tokens themselves). I have a content type 'article' with a 'body' field ...
0
votes
0answers
17 views

profile2 programmatically add value to field on user registration

I use profile2 to manage user profiles on my Drupal 8 site. In a Profile2 profile I have a field called "field_my_field". When a user registers on my website, I would like to add a value to that field ...
0
votes
0answers
14 views

Access field variable on all pages/content type

I have a content type called "homepage" with some fields, one of those fields is "background color". I can access to this field value with preprocess and change body background inside homepage. Now ...
0
votes
1answer
35 views

How to render HTML output in hook_ENTITY_TYPE_presave()

Upon node save, I want to take the value of a text field that uses a custom input filter and save the HTML-ified final version (what the input filter renders) in a second field. I have two text ...
0
votes
1answer
53 views

How to change date format of a custom entity in an update hook?

In would like to display the created date of a custom entity in the "short" format, whereas currently it displays in some default format. This is in a module that is already in, production so I need ...
-1
votes
1answer
23 views

How to automatically install an image in taxonomy term field every time I install the module

I have a module with a custom taxonomy term called colors. The Colors taxonomy has 1 image field where I can upload a file based on the color names. I wanted the images to be automatically installed ...
0
votes
0answers
18 views

How to avoid creating duplicate media file while creating media programmatically

In Drupal 8 I am creating a content with media image field, I am using theme preprocessor to attach a default image to the media field (if media field is empty) when new content is created. I used ...
1
vote
0answers
54 views

How do you call an install function that did not run during install?

I am using the Currency Taxonomy module to get all valid currencies around the globe as taxonomy terms. On installing the module, I got the taxonomy vocabulary but not the terms. The code to add the ...

1
2 3 4 5
51