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
-4
votes
0answers
17 views

how to run module or plugin functionality on everypage in drupal 8

I have drupal 8 website and I am trying to create google login onetap module but I am stuck to run on everypage and node or article.
-2
votes
0answers
29 views

What should I use instead of hook_init()? [duplicate]

Please help me I need to run my module on initial time. I do same thing I drupal 7 but I am stuck in drupal 8. In drupal 7 I am using hook_init but In drupal 8 having limited hooks and deprecated ...
0
votes
1answer
36 views

hook_field_formatter_third_party_settings_form doesn't fire

I'm attempting to add a checkbox to a field settings form in D9. I have the following code: function my_module_field_formatter_third_party_settings_form(\Drupal\Core\Field\FormatterInterface $plugin, \...
-2
votes
0answers
22 views

How to do query from sql and display result in twig in drupal 8 [closed]

I am new in drupal. I made modul, controller and twig now i need to do query and display result of custom content type on page. Can somebody post me code to see how to do it in which file. Thanks for ...
0
votes
0answers
29 views

Remove duplicated results - Apache Solr

English is not my native language so please be patient. Good afternoon, my Drupal 7 site is currently holding several articles, help topics, and document guides that are versioned, i.e search the &...
0
votes
0answers
23 views

SharePoint online search query in logged-in user context, which is connected through SIMPLESAML SSO (Azure AD IDP) with Drupal application

Below is problem description - I have sharepoint online and its URL is like - https://abc.sharepoint.com Above sharepoint is connected through SSO (Office 365 Azure AD IDP and SAML) I have another ...
-2
votes
1answer
40 views

How do I add a button with a custom redirect to a node view?

I'd like to add a "More info" button to the bottom of a node view. The button should redirect the user to a URL based on the current node, e.g. node/1/info: /** * Implements hook_node_view ...
0
votes
0answers
38 views

Override core files database, statement, connection

I'm trying to turns things in everyway in order to override those core files: Database, Statement & Connection in order to build a simple array of SQLQueries along with their results in order to ...
1
vote
1answer
54 views

How to render a field of a taxonomy term inside a view template?

I'm trying to display an image as a banner above the items of a view (which creates a block). The image is a field associated to a taxonomy term and the view is used to display all items which have ...
1
vote
0answers
29 views

On the password_confirm widget, how do I change the text of “Password”? [duplicate]

By default, the password change form on the user account page looks like this: Current password Password Confirm password This is bad usability because it is not clear to users that "Password&...
0
votes
1answer
30 views

Alter Submit button of specific form [closed]

I am new to Drupal and want to alter a submit button of a node-edit form. So I wrote a basic module to do so. And it also alters the form button of my form with the id=node_hotel_edit_form. But also ...
2
votes
2answers
93 views

Why can't I see <div> tags added to $form in hook_form_FORM_ID_alter?

I want to modify the $form variable in an implementation of hook_form_FORM_ID_alter but can't seem to be able to set the #prefix and #suffix variables on field widget. /** * @file * Implementations ...
0
votes
1answer
36 views

Clear entity cache before render

I secured some file in an s3 bucket using s3fs. My problem is : the "Expires" argument send to build the file URI is not reset each time the object is call in my API. time doesn't change if ...
0
votes
3answers
47 views

Custom 404 page not working

I'm trying to set a custom 404 page but is not working. What I tried: configuration - system - basic site settings and set node path on 404 page -> didn't work add page--404.html.twig to my custom ...
1
vote
1answer
35 views

Change entity reference field widget based on condition?

I am using Drupal 8. In user registration form, I use an entity reference field to a profile. I wanted to display inline entity reference form widget or entity select widget based on role. For this, I ...
0
votes
1answer
17 views

Trigger Crop API programatically after node is created

Hi I am using Image Widget Crop so that users can crop images according to predefined image styles. All would have worked fine without any issues had I been using Drupal in the conventional '...
0
votes
0answers
25 views

Implementing hook_entity_type_build causes 500 error on cache clear

I recently attempted to display custom form modes based on the currently logged in user. My searching led me to implement hook_entity_type_build. However, I am finding that even just having this ...
1
vote
1answer
16 views

What is hook_field_default_fields()?

I'm looking through a Drupal 7 module code in an attempt to understand what it does. It implements hook_field_default_fields(), but I can't find any documentation on this. What does this hook do? I ...
1
vote
1answer
39 views

How can I limit query results in hook_views_pre_execute?

I am developing a Drupal 8 website where I have a block view displayed for certain content types that shows related information from other content types. I need to dynamically limit query results ...
0
votes
0answers
31 views

Display teaser from entity reference field regardless of permissions

I have a Drupal 8 site with entity reference field that references nodes of type Colour. Colour node type is not accessible for anonymous users. I want to show Colour teasers though to all users when ...
0
votes
0answers
22 views

How to show nodes grouped by entity reference?

Im working on a Drupal 8 module that bring nodes with entity references, my array at this moment is showing this: Array ( [0] => Array ( [title] => New Issue ...
1
vote
0answers
23 views

Copy a field's value to another field and modify it

I have content type "Video" When i do a new "video" I have a field "iframe_vimeo" thats it contains a value of the iframe's video link. I want to do some modifications ...
0
votes
0answers
19 views

Drupal Commerce 1: Not getting shipping methods returned

I have to rewrite our company's ecommerce modules to work with our new service, converting it from XML to REST. I have a function that implements hook_commerce_shipping_service_info() /** * ...
2
votes
1answer
90 views

How to modify field value in other nodes after node update?

After node update I need to modify a field value in several connected nodes. As I know, I cannot use hook_entity_update() since $node->save() forms infinite recursion. How can I modify node fields ...
2
votes
1answer
52 views

How I can alter reCAPTCHA script tag in html_head

The reCaptcha module adds a Javascript with hook_captcha(). I want to add another attribute "type" to this script tag. I can't find a hook to achieve this. Here is the code from the ...
0
votes
1answer
31 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
2answers
70 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
32 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
29 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 ...
0
votes
0answers
14 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 ...
-1
votes
1answer
37 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
30 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
24 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, ...
0
votes
1answer
16 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
82 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 ...
0
votes
0answers
48 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
23 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
35 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
35 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
20 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
36 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
52 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: ...
0
votes
2answers
67 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
63 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
100 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
27 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) { ...

1
2 3 4 5
51