Skip to main content

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
0 answers
22 views

capture card number in the order activity of order page dashboard

I'm working on an offsite payment module, wherein I'm trying to capture the card number(last 4 digit) in the dashboard order activity and in payment tab just like stripe module does. For instance, I ...
DEV_anonymous's user avatar
0 votes
0 answers
48 views

\Drupal::messenger()->addMessage Logs out user automatically

I'm working on a Drupal 10 offsite payment module. I'm trying to show Drupal message whenever order gets placed, declined, or failed. Please see code snippet: module file: Drupal\my_module\Plugin\...
DEV_anonymous's user avatar
0 votes
0 answers
35 views

Customise order confirmation message

I'm working on a Drupal 10 offsite payment module wherein I'm trying to customise order confirmation message with custom message along with payment information such as transaction id, merchant ref ...
DEV_anonymous's user avatar
0 votes
1 answer
25 views

Module theme hook template works only after hard refresh

I have a custom module named abc to simplify explaining this issue: modules/custom/abc/abc.module: function abc_theme($existing, $type, $theme, $path) { return [ 'abc' => [ 'variables' =...
bdereta's user avatar
  • 141
0 votes
0 answers
11 views

Limit Per User Tokens in Drupal Simple OAuth

I'm looking for a way to limit the maximum number of tokens granted to each user in Drupal 10, similar to how we can limit the number of sessions per user using the Drupal Session Limit module. Is ...
Tejas's user avatar
  • 1
0 votes
1 answer
34 views

menu tree behaves differently on two differents sections

i'm maintaining a drupal i didn't developed. I fixed some issues in the menu template (e.g. /themes/custom/{mytheme}/templates/menu--menu-{my-menu-name} ) this template is called at two places in the ...
SupFrig's user avatar
  • 109
-4 votes
1 answer
62 views

Add Javascript to a specific 'Basic page' or node based on its title

In a Drupal 10 site I have a page (content type: Basic page) that needs a small Javascript fragment defined in a Javascript file that was added as an asset to the theme.libraries.yml file. I don't ...
quilx's user avatar
  • 21
0 votes
0 answers
17 views

Clear smart_date time input values after validation error

I have a smart_date field. During creation of a content with the smart_date field, when an error occurs on the time/date such as incorrect format, etc.. I want the values to be cleared. Here is what I ...
Gabriel Fernandez's user avatar
0 votes
1 answer
51 views

How to access #fields in a paragraph which are in the correct order, unlike getFields()

I have a repeatable paragraph in which I have several fields. I use it to build a table. The Manage Display is set to the order I want the fields inside the repeatable paragraphs. If I render this ...
Laurence Cope's user avatar
1 vote
0 answers
34 views

Add machine-name as css class to my blocks

So I would like to give my blocks the internal machine name of the block as a CSS class? I can add the block ID and the block type as presprocess via theme.theme: function xxx_theme_preprocess_block(&...
Bavramor's user avatar
0 votes
1 answer
74 views

Redirect Not Working

I can't figure out why my redirect of the login form submit hook is not working: redirect route: mfa.otp_form: path: "/mfa-otp-form/{uid}" defaults: _form: '\Drupal\mfa\Form\...
Donald Winston's user avatar
0 votes
1 answer
35 views

How to Create a Database Table When Installing a Custom Drupal Module? [closed]

I've included a mfa.install file along with my module (mfa). After a few iterations my module now installs without errors but my two new tables are not added to the Drupal schema. Why? I uninstalled ...
Donald Winston's user avatar
2 votes
0 answers
68 views

Automatically trigger Acquia pipelines job when content is updated

My team is fetching a large portion of our site's content at build time by using the i18n Gatsby plugin and downloading content from Drupal. The content we are fetching at build time rarely needs to ...
Amy's user avatar
  • 21
0 votes
0 answers
16 views

How do I call a custom serializer from a _node_update hook?

We inherited a legacy Drupal project that has an entity called Products. We expose an API endpoint that returns all Products as JSON. Our project uses a module that contains a custom serializer: // ...
RobertAKARobin's user avatar
0 votes
0 answers
35 views

Inline Entity Form - how to set form field value in custom validate function

I have been struggling with this problem for few hours and I am unable to set form field values in a custom validate handler for an Inline Entity Form. Inside _inline_entity_form_entity_form_alter ...
a_negi's user avatar
  • 1
0 votes
1 answer
60 views

hook_cron(): PHP output does not appear

I am (finally) migrating our Drupal 7 sites to Drupal 10. The one problem I have not been able to resolve is output from the hook_cron(). Everything appears to execute, whether running on the browser ...
backtothefuture's user avatar
0 votes
1 answer
77 views

How do I override a core constraint on an entity?

I want to replace one of core's constraints, UserMailUnique, with a custom validator. How can I do that?
Patrick Kenny's user avatar
0 votes
1 answer
127 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
46 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
173 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
35 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
129 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
141 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() ...
user avatar
2 votes
2 answers
383 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
68 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
31 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
350 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
  • 190
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
41 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
333 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
306 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
92 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
37 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
39 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
67 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
52 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
263 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
27 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
85 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
33 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
  • 109
0 votes
1 answer
70 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
26 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
65 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
82 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
403 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
405 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
35 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
510 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
46 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
58 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

1
2 3 4 5
54