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
1
vote
2answers
80 views

Write complex access control in a reusable way

We deal with nodes representing humans with two important properties: mother and father. Your parents as well as your aunts and uncles should get extra permissions, like to see you in a certain view ...
-1
votes
0answers
18 views

hook_options_list_alter for views

I can't use hook_options_list_alter on views. I'm sharing the same field among different content types. I can limit the options per content type on node page edit page with no problem, but for some ...
0
votes
0answers
18 views

Finding better solution for merge the multiple menu

I have merge two menu programmatically. I have tried with code which is listed below. After using this code it was slower my site and increase large amount of queries passed while every page load. I ...
0
votes
1answer
28 views

How to override Breadcrumb theme template?

I have a custom theme that has base theme: classy setting in the mytheme.info.yml file. When we enable twig debugging locally, we find that the <!-- BEGIN OUTPUT from 'themes/custom/mytheme/...
0
votes
0answers
34 views

Hook into password change on user update

Question in short: How do I hook into password change in order to get plaintext old and plaintext new password when password change is accepted? What I have tried so far: I tried hook_form_alter with ...
0
votes
0answers
14 views

Scenario for validation in two submit times ( the second one validates and shows a previous hidden field)

I'm using alter_form to change 'user_login_form'. The problem is that i'm hidding a field and i want to show it to the user and validate it ONLY AFTER login and pass are validated ( user has done a ...
1
vote
1answer
31 views

adding new validation method using HookEventDispatcherInterface::FORM_ALTER event

I'm trying to add a new validation method for 'user_login_form' using HookEventDispatcher module and events: class MyFormEventsSubscriber implements EventSubscriberInterface { public static function ...
1
vote
1answer
26 views

What is the proper way to show a visitor an error?

I'm using a custom submit handler for a Webform, which POSTs important form data to another API. That part works, but on occasion there may be random network errors that prevent a successful ...
1
vote
0answers
25 views

Hook form alter not working for node edit form

I have a content type called landing_page. If I edit an existing node in the admin /node/31/edit and I inspect the form I see id="node-landing-page-edit-form". I can't get it to work to use ...
1
vote
1answer
38 views

Need to add a JS file into <head> using a custom module with custom twig template

I have created a custom module and created a config page which we need to input the url on that page. Created a twig template within my custom module: <script src={{ js_file_url }}>test</...
0
votes
1answer
43 views

hook_node_update not working

I placed the following function in my custom module. function MYMODULE_node_update($node) { if ($node->type === 'page') { $node->title = 'test'; } } When editing and saving a node of ...
0
votes
1answer
53 views

Use hook_views_pre_render() to change field to url link

I want to use hook_views_pre_render() to read in a view and change a field output to a clickable link. Here is code: function sbn_views_pre_render(ViewExecutable $view) { // https://drupal....
0
votes
1answer
13 views

How do use hook_views_pre_render() to modify view fields

Want to use hook_views_pre_render() to modify a field in view based upon data in another field. Starting with this code: function sbn_views_pre_render(ViewExecutable $view) { drupal_set_message($...
-2
votes
0answers
17 views

How to make popup modal based on page views?

I want to make modal pop up after a visitor has made 3 pageviews on the site to different pages. I'm thinking I should use a cookie to track this information but am not sure how/where to best put this ...
0
votes
1answer
42 views

Why I am not able to add custom validate Handler function for UserPasswordResetForm on form_alter?

I am trying to override default reset password functionality by using hook_form_FORM_ID_alter as below: The below code is written in custom module called usr_registration.module file /** * ...
1
vote
1answer
47 views

How to run alterRoutes on particular condition ? Does it run on cache clear and not on normal Request?

I am trying to implement a feature where I need to run different flow than default flow while the registering user on the site. I am trying to alter the route of "user password reset" for the for the ...
0
votes
1answer
36 views

How to add/remove a permission from a user role to a particular user without modifiying the user role?

Let's say that I have a user role called ARTICLE_VIEW_EDIT which has permissions to view and edit own articles nodes. I have the following 2 cases. I want to give extra permission, delete own ...
0
votes
0answers
42 views

Alter an Entity's field value for only one instance of the Entity on a page?

I'm trying to alter the value of a field within an Entity without it altering other instances of that entity that are being displayed on the page. I've tried hook_preprocess but I can't see how I can ...
2
votes
1answer
21 views

How to dynamically make a field visible?

I'm trying to render a field based on a select value. However I couldn't succeed for now, so here is what I tried: I created a content type with a select field (field_type) var_dump($form['...
1
vote
1answer
62 views

How to add library to Paragraph bundle using hook_preprocess_theme?

I wanted to add a library to a specific paragraph bundle. I know I can do {{ attach_library('my_theme/my-library-name') }} using twig, but that means I have to create a file for each bundle. The goal ...
-1
votes
1answer
18 views

How to Update db field value in hook_menu()?

I'm using Drupal 7, my requirement is to automatically update the node field value in a content type for a condition. I have used Hook_menu() for to get a link and if i use that link my code will ...
0
votes
1answer
21 views

How do I make a form field go back invisble after I uncheck a radio button?

I'm currently building a form where the goal is that the administrator will have to choose between 3 radio buttons. If one click on any of the radios, a specific field shows up (There are 3 fields set ...
0
votes
1answer
26 views

Altering UserPasswordForm redirect with a custom submit

I want to alter the redirect of UserPasswordForm from Drupal’s core, I did this function maubl_user_form_alter(&$form, FormStateInterface $form_state, $form_id){ switch($form_id) { case '...
0
votes
0answers
21 views

What is the appropriate hook for hiding/editing user data?

We have a field on the user that I just need to hide one field from. This user object may be loaded from an API service endpoint or just in a regular login. Is there a hook I can use to obfuscate the ...
0
votes
0answers
50 views

Handle nested Exceptions in delete hook & Ignore DrupalKernel Exception handler

I have functionality that checks if entities can be deleted or not. These entities are vast and most of them are linked together with EntityReference fields. Now in some cases I want to check if an ...
0
votes
1answer
52 views

Preprocess a twig template file

I don't fully understand how preprocessing works I have a twig template /themes/custom/client/templates/content/node--myfile.html.twig that I want to alter I want to show/hide a part of that ...
0
votes
3answers
41 views

Ajax not working in text field

I made custom module that implements hook_form_alter that marks the field_text_field_1 textfield as Ajax-enabled. When a key is pressed inside the field_text_field_1, it should change the value in a ...
1
vote
2answers
31 views

How to change view's field (Custom-Text field specifically) value based on other field value using hook_view_pre_render?

I have created a taxonomy-term view. I have added two fields in a view: term-id and custom-text field. I want to check if term-id has children and depending upon the result, I want to set markup ...
0
votes
3answers
41 views

Strange behavior: Extra css classes are NOT merged with the 'Search Block' form tag classes but with those of BLOCK wrapping the form tag

i'm experiencing such 'strange' behavior with Drupal (v8.7.10) when trying to add css classes to the default Search Form form tag using MYTHEME_form_FROM_ID_alter hook, the classes are NOT merged with ...
0
votes
0answers
22 views

How to use submenu as filter View?

I'm new in Drupal 8, and I want to use submenu as a filter in my page. Example: ParentChild child0 .child1 .child2 When I open the Parent Child page I want that ...
0
votes
0answers
22 views

Custom Fivestar widget does not appear on display settings

I need to create a custom wiget for Fivestars. I create module, and implement hook_fivestar_widgets(). I create css file, images. And it works on Open Server on my PC. When I upload this module on ...
-1
votes
3answers
52 views

How do I programmatically create a webform from a newly created node?

This is the code I am using. function walk_handler_entity_presave(EntityInterface $entity) { if (method_exists($entity, 'getType') && $entity->getType() === 'walk') { $elements = []; ...
0
votes
1answer
20 views

How to move block from a region inside of hook_preprocess_node?

I have added mycustomblock to the header region in our settings (/admin/structure/block). We are using the standard content block and displaying that in the Content region, which is displayed below ...
1
vote
1answer
29 views

How do I know when another contributed module deletes a block?

I have written a Drupal 7 module that adds about ten fields to the block administration configuration form and saves the values for those fields in its own database table. My module does not create ...
0
votes
0answers
16 views

How can i get node type in template.php [duplicate]

I want to configure breadcrumbs depending on the node type. How can I get the node type in a function theme_breadcrumb in template.php? I try it, but it doe't work. function zen_breadcrumb($variables)...
1
vote
0answers
18 views

Geolocation: How do I set conditional markers on the Leaflet view?

I'm using Geolocation to list about 20 pubs / restaurants, but I'd like the user to be able to know if the address is a restaurant or a pub just by seeing the icon. When I created my content type, I ...
1
vote
1answer
49 views

How to stop download in hook_file_download

I'm building a page with different download buttons linked to private zip files. Users have to log in to download. I am using module Permissions by Term to manage who can see which button. I added a ...
-3
votes
1answer
38 views

How to change the length of field from 255 to ilimit?

i have a field in web site but lenght limit this is field is 255 , but client wants to puts more caractere to that field i want to change field from 255 to ilimit . any help please
3
votes
2answers
103 views

How to get node's view mode in hook_page_attachments?

I need to get the node's view mode so that in the mymodule_page_attachments, I can add libraries conditionally if the node's view mode is set to full or default. I tried the following but not able to ...
1
vote
1answer
30 views

How to create node twig template suggestions for one content type?

I need to create a node twig template that is just for the basic page content type that based on a custom field on the content type. We have other content type like Article, Blog, Products that do not ...
0
votes
0answers
25 views

Layout builder - Can't use hook_block_access()

I'm using hook_block_access() so I can apply custom contextual access rules to blocks based on a Node field value of the page being viewed. This works fine unless I build the page using Layout Builder....
0
votes
1answer
58 views

How to get the uncached version of request headers?

We need to programmatically get the request headers using the mymodule_preprocess_page hook. To do this we tried the following, however, because we have CDN, Varnish, and Drupal Cache all enabled, the ...
0
votes
1answer
105 views

How to add custom confirmation page template for a custom URL for Webform (Custom URL for confirmation page) Drupal 8

I want to show custom message on confirmation page (on custom URL). I created a custom URL in *.routing.yml file and added a method in controller class that returns an array : return [ '#theme' =&...
2
votes
1answer
92 views

When should hook_post_update_NAME() be implemented instead of hook_update_N()?

What I found so far is that certain actions are unsafe to be performed inside hook_update_N(), but I didn't find any documentation saying which those actions are. When should I implement ...
0
votes
1answer
46 views

Queue Implementation for third party api

In my website I have a form and which submits data to third party website. that api is available some time and not available some time. I need to create a queue mechanism to insert failed api calls ...
0
votes
1answer
41 views

how to get configuration Entity in Drupal 8

How to get this encircled value in an array using Configuration Entity in drupal-8.
0
votes
0answers
21 views

D8 - hook_user_insert not working [duplicate]

I am facing an issue in Drupal 8 security questions module port from D7. I have a hook called hook_user_insert in D7 which has to be ported to D8. Currently I am not able to get the values in this ...
0
votes
1answer
17 views

How to create a Content Type field that will be only set by query parameters?

I'm using Drupal 7. I want to create an Entity Reference field in my Order content type that will be set based on whatever the query parameter node ID is for my parent node. In other words, the user ...
1
vote
1answer
28 views

hook_update_N() for more than 100 updates or 10 major releases

The documentation for hook_update_N() says the following: Implementations of hook_update_N() are named (module name)update(number). The numbers are composed of three parts: 1 digit for ...
2
votes
1answer
40 views

Is accessing the current node from multiple block plugins on a single page costly from a performance perspective?

I use a combination of Block plugins and panels to populate the layouts of the display modes of various content types. Here's an example: class MyBlockPlugin extends BlockBase { /** * {@...