Questions tagged [hooks]
Use it for the mechanism that allows to extends module's functionality without editing its code.
2,672
questions
1
vote
1
answer
134
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\...
-3
votes
0
answers
30
views
How to update/convert stored field value in webform database from am to pm in Drupal 10
I have a field in database with datatype as integer, in my custom module I had to convert the date to readable format in d/m/y, the value is inserted to a custom table field using strtotime(date('d/m/...
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/*.
-2
votes
1
answer
53
views
How can I hide a specific region according to its url?
I need to hide the footer region on all pages with url /people/. Something like with the blocks you put show only in /people/*.
-2
votes
0
answers
17
views
When I integrated simplesamplphp 2.0.6 with drupal 9.5.11 (simplesaml_auth 3.3) , website went down and getting below error "This page isn’t working"
I have installed simpleamplephp and integrated with wso2 it is working fine. but when I try to integrate simplesamlphp with drupal using simplesaml_auth I'm having issue.
In my settings.php i have ...
0
votes
0
answers
26
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/####/...
1
vote
2
answers
81
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 ...
1
vote
1
answer
71
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 ...
-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-...
0
votes
0
answers
31
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 ...
0
votes
0
answers
35
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('...
0
votes
1
answer
50
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 ...
1
vote
1
answer
41
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 ...
-1
votes
1
answer
100
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....
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 ...
0
votes
1
answer
51
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\...
1
vote
0
answers
28
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 ...
0
votes
1
answer
34
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 ...
0
votes
1
answer
17
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:
$...
0
votes
1
answer
56
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 ...
-1
votes
1
answer
73
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 ...
0
votes
1
answer
126
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 ...
0
votes
2
answers
149
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 ...
0
votes
0
answers
22
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 :
...
0
votes
1
answer
152
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 ...
0
votes
0
answers
35
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 (...
0
votes
0
answers
42
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 ...
2
votes
2
answers
161
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 ...
0
votes
1
answer
45
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 ...
0
votes
1
answer
88
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 ...
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 ...
0
votes
1
answer
93
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'...
0
votes
0
answers
37
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 ...
1
vote
0
answers
104
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 ...
0
votes
2
answers
79
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, ...
-2
votes
1
answer
118
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()->...
2
votes
1
answer
207
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 $...
-1
votes
1
answer
90
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();
...
0
votes
0
answers
37
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 ....
0
votes
0
answers
23
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 ...
0
votes
1
answer
43
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 ...
0
votes
1
answer
135
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 ...
-2
votes
1
answer
76
views
How can i subscribe/unsubscribe to a simplenews newsletter programmatically?
I have the following code to set subscriptions to a simplenews newsletter on or off:
$user_load = User::load($userID_current);
$newsletter_subscriptions = [
'newsletter1' => 'on',
...
1
vote
2
answers
286
views
Hook post update not found
I have a problem with the drush updb command which does not find the hook post updates of my custom module.
I noticed that the module install saves the module's name string here in database, table &...
0
votes
2
answers
263
views
Attaching a library to only one custom module
I wrote a sample custom module (juniper) and created the corresponding juniper.libraries.yml file to link the CSS and JS. I am trying to load this library only on this module pages (/juniper). However,...
0
votes
0
answers
11
views
Why might a panel pane print a block as class="panel-pane pane-block..." vs class="block block--views..."?
I apologize if the wording for this question title does little to explain my problem. I'm so deep into not understanding an issue I'm having trouble describing it.
To preface, I'm quite a noob with ...
1
vote
1
answer
35
views
Module template for a comment field is not triggering comment_preprocess_field
I have a custom module in which I am trying to override a comment field's template in Drupal 9.3.
In my module file I have defined the hook_theme to override the core template in use. (comment.html....
0
votes
0
answers
35
views
Headless and custom node / entity access
I struggle to set up custom access rules for "nodes" that are viewed via the
jsonApi
entityQueries which response via json endpoint
What I try to achieve:
I need to skip a node, that ...
0
votes
1
answer
94
views
Why does this code to create a dependent dropdown not work?
I am trying to implement the dependent dropdown option in Drupal 7 from this URL http://w3shaman.com/article/creating-ajax-dropdown-drupal-7. When changing the first dropdown value, it is showing the ...
1
vote
1
answer
46
views
using hook_form_alter() to change year range of datetime select widget, with deltas for multi-value fields
I have multiple date fields on a node form for which I am using the select widget. The year select list has a range of years that is far too wide for our purposes (1900-present), so we want to limit ...