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

How can i use route from 1 theme into another theme and also altering that route in drupal 8?

Hy, i have an route which belongs theme1 but want to want to alter that route and also use this in another theme say theme2, how can i perform this in drupal 8? code - protected function alterRoutes(...
Anmol Hira's user avatar
-4 votes
0 answers
22 views

How to change image field Label in form_alter [closed]

Tried below ,but didnt work $form['field_image']['widget']['0']['#title'] = 'Custom image'; $form['field_image']['#title'] = 'Custom image';
Fatima's user avatar
  • 1
0 votes
1 answer
72 views

How to alter submission data when inserting a submission

I am trying to alter the data in a webform submission before this is being saved in to the database. In D7 i would do something like this: function mymodule_webform_submission_presave($node, &$...
hasse88's user avatar
  • 65
0 votes
1 answer
34 views

Inject code just after Body tag

I need to inject some code inside of head and body tags. I managed to add code inside of head using hook_page_attachments_alter but I can't do same for Body. Can somebody point me into right direction?...
Dmytro Pastovenskyi's user avatar
2 votes
2 answers
121 views

How can I invalidate the entire cache when saving menu item?

I use the Simplify Menu module. Since changes in the menu are not applied, I would like to clear the entire cache. Unfortunately the following code does not work function ...
Joe Fred's user avatar
0 votes
0 answers
20 views

Remove tag in header: alternate

is it possible to delete a tag from our head tag (see it below) <link rel="alternate" hreflang="da" href="http://mysite.local/page1" /> I looked in interface (...
Dmytro Pastovenskyi's user avatar
1 vote
2 answers
90 views

How can I add a CASE statement in a WHERE clause?

I need to add a WHERE clause to the query altered by a hook_views_query_alter() implementation. The WHERE clause needs to contain the following CASE statement. $sql = "(CASE WHEN node_field_data....
Subhash's user avatar
  • 93
0 votes
1 answer
103 views

Hook for hiding menu links based on user access

I have a Drupal 7 module that uses hook_preprocess_menu_link() to hide menu links based on user access. I am in the process of migrating to Drupal 9, and it seems that hook_preprocess_menu_link() ...
Ali Rizvi's user avatar
2 votes
2 answers
134 views

How to hide CKEditor5 toolbar plugin based on user permissions?

I am using Drupal 10, CKEditor5, and a text format that has a good number of options in the toolbar including the source editing plugin. I have a custom module that defines a custom permission that I ...
Jordan's user avatar
  • 49
1 vote
0 answers
58 views

Modifying a field value in theme_preprocess_node()

I have a content type (exercises) which contains a text field (field_path). In this text field I have a path to a video file. I would like to retrieve the value of this field in theme_preprocess_node ...
HEIA Drupal's user avatar
0 votes
0 answers
28 views

Can't save node when fields are altered with entity_bundle_field_info

I have a node called Program, with a large number of fields and a custom node form. Because of the very complex way we're indexing it for search, I have two fields, award_type and award_goal, which ...
tinkerer_and_putterer's user avatar
1 vote
1 answer
205 views

How can I programmatically trigger a 403 error with a hook implementation?

In a module within a drupal hook I'd like to conditionally trigger a 403 for the user. I could archieve this e. g. by throwing an exception throw new \Symfony\Component\HttpKernel\Exception\...
c1u31355's user avatar
  • 170
0 votes
0 answers
19 views

How can I hide a specific region according to its url? [duplicate]

I need to hide the footer region on all pages with url /people/. Something like with the blocks you put show only in /people/*.
Yohan's user avatar
  • 1
0 votes
0 answers
32 views

Shipping cost is not up-to-date on the order_information page. Checkout page displays shipping properly

It's a Drupal 8 Commerce site, and we just changed the shipping rate from 2,90 to 3,5€ Although the shipping rate appears just fine on the checkout/####/review page, On the checkout/####/...
escozul's user avatar
2 votes
2 answers
176 views

How do I replace hook_field_widget_WIDGET_TYPE_form_alter() with hook_field_widget_complete_WIDGET_TYPE_form_alter()?

I've been using hook_field_widget_WIDGET_TYPE_form_alter() for years. And, of course, in Drupal 10, it has been deprecated. I am trying to add a hook to the file attachments widget. I just want to ...
SomebodySysop's user avatar
1 vote
1 answer
137 views

How to get the Drupal webform submission changed value?

I'm trying to get the webform submission changed data when a form submission is updated in date format to be captured into a custom field. I'm able to get the webform completed value in a custom ...
Jake13's user avatar
  • 49
-2 votes
1 answer
88 views

Constantly creating new Anonymous users

I find that my instance of drupal is always "creating" new anonymous users. I have an even on Create New User that simply logs the name to a file, and it is filled with entries like 2023-10-...
dmgig's user avatar
  • 129
0 votes
0 answers
32 views

Display other user's webform submissions

So, I'm currently programming a module and one of the functions should be that certain users that belong to a specific user group (e. g., 'Counselor') have access to their clients' webform submissions ...
Quetzcodecoatl's user avatar
0 votes
0 answers
36 views

Deny access to pages or nodes base from a database table

I was modifying a 2fa module for restricting users to access other account's page (user/%/2fa) which is working. function custom_2fa_menu() { $items['user/%/2fa'] = [ 'title' => t('...
DevNooby's user avatar
0 votes
1 answer
58 views

Why is the Charts module not working for anonymous visitors?

I'm using the Charts module in my project. I've configured Google Chart in my custom view which needs to be shown to anonymous users. The view is shown, but the chart is not rendered for anonymous ...
zed Blackbeard's user avatar
1 vote
1 answer
44 views

How to share a variable between several preprocess functions in dot theme file

I retrieve config settings that are used in two different regions. How can I get the setting once and then pass it to two different hooks? Now I get the setting in each hook and it seems to be not ...
Andrei's user avatar
  • 15
-1 votes
1 answer
166 views

Displaying parent field value in field.html.twig template from nested paragraphs

See attached please. Using field.html.twig and paragraph.html.twig, Paragraphs 8.x-1.16 Stable release and Drupal 9.5.10 field.html.twig (specifically: field--paragraph--sidebar-button-repeater.html....
rachel_001's user avatar
0 votes
0 answers
25 views

How can I theme a file link in a specific file field? [duplicate]

I have a file field (pdf_via_email). I need to do some heavy theming to the link of this field, so I would like to know how I can create a custom file link template specific to this field. I tried the ...
Il Felice Android's user avatar
0 votes
1 answer
56 views

How to send variables to a custom theme from a custom module

I'm trying to pass a variable from a custom module to a custom theme. I have a Controller class in a custom module <?php namespace Drupal\course_catalog\Controller; use Drupal\Core\Controller\...
Dynamdilshan's user avatar
1 vote
0 answers
29 views

empty variables when i use a region template for a specific node

My goal is to serve the drupal header region on a specific URL so another application can get my drupal header and consume it. my menu is well working, and is called in region--header.html.twig like ...
SupFrig's user avatar
  • 113
0 votes
1 answer
45 views

How to hide terms from entity reference field on node form

I've been searching quite a bit on this already and was not able to find a solution. installation is d10 So on my node I have an entity reference field which is showing Taxonomy terms. Two of those ...
arnemichiels's user avatar
0 votes
1 answer
21 views

['#attributes']['class'] variable is not being rendered on the page

I'm working on an old Drupal 7 site. In the template file paragraphs-item--user-block-paragraph.tpl.php the content is being rendered, but the class is not added to the element. Here is the code: $...
Ben Alan's user avatar
  • 111
0 votes
1 answer
59 views

Override the page title with a value from an API response

I built a custom Drupal module. The module fetches data from a 3rd-party API and builds a block. I need to use a value from the API response to override the title (and head_title) of the page that the ...
mfairhurst's user avatar
-1 votes
1 answer
74 views

How can I alter the value returned from a hook?

I installed the Two-factor Authentication (TFA) and the TFA Basic plugins modules. I want to alter the value returned from tfa_basic_tfa_ready_require(), which is a hook implementation, in a custom ...
DevNooby's user avatar
0 votes
1 answer
229 views

How to set a webform default value for anonymous user?

I have been using hook form alter for a webform, to set a default value for a webform added as a block to a page. Below is the code, the code only works for users who have logged, but for anonymous or ...
Jake13's user avatar
  • 49
0 votes
2 answers
244 views

Changing order of execution of hook_preprocess_html

I have 2 custom modules in Drupal 9, let's called them module A and module B. Each module has a fully working hook_preprocess_html function defined in the .module file. The hook_preprocess_html ...
AlastairHoward's user avatar
0 votes
0 answers
29 views

Help for center Geolocation Polygon Map with Leaflet?

Is somebody knows how to center a leaflet map with a geolocation polygon field? I want to center the drawing of polygon like below but there is just few options which don't help me. To reproduce : ...
FonkyJu's user avatar
  • 11
0 votes
1 answer
255 views

How can I confirm a path is internal?

In my theme's theme file I'm using preprocess_node to create variables for a node based on the section of my site its in, and that's figured out by checking the path's alias. So for example a path ...
fallenturtle's user avatar
0 votes
0 answers
38 views

Inline Entity Form - is it possible to add field from child entity's taxonomy reference field

I have the below structure on my Drupal 9 site: Product content type -- field_product_integration (references contents of type Integration) Integration content type -- field_product_feature (...
Ashok Negi's user avatar
0 votes
0 answers
49 views

Populate field value based on external API response

My custom Drupal 10 module takes the value of an address field submitted by the user during node creation, sends that to an external API, and then fills a taxonomy term reference field based on the ...
twhitefrd's user avatar
2 votes
2 answers
214 views

Deleting entities using Batch API without a form or user interface

In a custom Drupal 9 module, I need to delete entities using Batch API without a form or user interface. The list of entity IDs are generated and the batch is built in hook_views_post_execute(). When ...
bacteriaman's user avatar
0 votes
1 answer
55 views

theme_suggestions_html_alter not being picked

I'm trying to implement a custom template html--front--anonymous.html.twig which replaces html.html.twig. The suggestion is being showed, but its file is not being picked. my_theme.theme function ...
Ricardo Castañeda's user avatar
0 votes
1 answer
112 views

Theming image.html.twig for one paragraph type with custom template suggestion

I have a custom module that when installed, creates a paragraph type called "Gallery". Gallery has one field called "field_gallery_images", which is a media reference. I am trying ...
Droopaluser69's user avatar
0 votes
0 answers
27 views

Why is this hook implementation not working? [duplicate]

I am new to custom modules and hooks and i am trying to connect to a sharepoint site i created to upload pictures of a content i have into sharepoint instead of drupal's file system. My issue is not ...
Rayan Frem's user avatar
0 votes
1 answer
115 views

Altering paragraph field within revision using preprocess hook

I'm using a hook_preprocess function (hook_preprocess_entity_print) to alter the content within a paragraph field prior to rendering (replacing some strings based on a regex). This works great when I'...
Mark's user avatar
  • 133
0 votes
0 answers
41 views

Webform get submission details after or during submission

How can I access the form data during or after submission? Am using Webform REST for the submission of forms, but I don't seem to be able to retrieve the form data. For now, I tried the following ...
Sidney Sousa's user avatar
1 vote
0 answers
163 views

Running a hook after node save, or another way to get the file name attached to a node

We've a D9 site with a custom module which generates and saves CSS code. It takes the name of the file attached to a node, and generates CSS to set it as the node's background. Initially, I tried ...
Bytech's user avatar
  • 111
0 votes
2 answers
118 views

How do I programmatically assign a new book when a new node is created?

For a given content type, if a new node is created and no book is assigned, I'd like to create a new book and assign the new node to that book. (some background - that content type is the book cover, ...
commonpike's user avatar
-2 votes
1 answer
151 views

Set variable for drupal 9 website [closed]

I need to get the hostname and then define a variable which is going to be used in all controllers of the website. I am able to call the code in controller as follows: $host = \Drupal::request()->...
Saili Jaguste's user avatar
2 votes
1 answer
290 views

How to get Paragraph Changed Time?

I know how get User entity changed time ($user->getChangedTime()). Node has the same value ($node->changed), but I need to get this changed time from a Paragraph. When I try this method $...
Pipo Bizelli's user avatar
-1 votes
1 answer
102 views

How do I set a plain text field value to be empty?

<?php function MY_MODULE_node_update(NodeInterface $node) { if ($node instanceof \Drupal\node\NodeInterface) { $nid = $node->id(); $nodeType = $node->getType(); ...
Sundar Raj Ponnulingam's user avatar
0 votes
0 answers
39 views

How to move add button above listing for inline entity form

We're using Inline Entity Form for a project and we have a bunch nested content types. For one of those content types, we want the add button to be above the listing of existing entities of that type ....
agodin's user avatar
  • 93
0 votes
0 answers
26 views

Leaflet custom marker doesn't work on multiple points

I am using Geofield field with Leaflet module. I need to customize the marker and I'm having a problem with content types that have more than one point on the map. While for ctypes that have only one ...
Francesco's user avatar
0 votes
1 answer
58 views

how to alter entity reference field (taxonomies) field options in hook form alter

Can anyone please let me how to alter entity reference field (taxonomies) field options in hook form alter, Seems the below code doesn't work. /** * Implements hook_form_alter(). */ function ...
miststudent2011's user avatar
0 votes
1 answer
172 views

Which hook will allow me to change links in a page?

Which hook would allow me to change each link (given in <a> tags) in content pages and menus and change their attributes? I need to implement this in a theme that uses Olivero as parent theme ...
Matthew's user avatar
  • 101

1
2 3 4 5
54