Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Use it for the mechanism that allows to extends module's functionality without editing its code.

0
votes
3answers
37 views

How to check the value of a field if its empty within preprocess

Is there a way to check if the value of a field within the preprocess is empty? I'm getting an Error: Call to a member function isEmpty() error during the process function ...
0
votes
0answers
12 views

How to Replace Value of CKEditor Field via Custom Module

Drupal 8.x I have a custom module and I am trying to wrap any string beginning with a hash tag in an 'a' tag via RegEx. MYMODULE.module: function MYMODULE_preprocess_node(&$variables) { if ...
0
votes
1answer
25 views

Edit field in contentType B when creating or editing node of contentType A

I need to edit a field in contentType B when I create or edit nodes of contentType A. I know it's possible to use rules for this but I need to have more control so I want to do it in my own module. ...
-1
votes
0answers
20 views

Problem after updating Media module to latest version [on hold]

I have updated Drupal core to 7.59 and Media module to 7.x-2.20. When I try to upload image through media browser, I get this error: Notice: Undefined index: #ajax in function ajax_form_callback() ...
0
votes
0answers
15 views

Exclude in result search node Content Type and Language

I'm use this module Search Exclude I want exclude content type and filter to by languague. Search Exclude (Node) I use this module because is practice, simple and easy compared others module of the ...
0
votes
1answer
16 views

How to alter the owner/authored by field to the current user when using quick_node_clone

Using Drupal 8 with quick_node_clone module. When a node is cloned I need to change the 'owner' or 'authored by' value to the person who is cloning the node. There is an opportunity of manually ...
0
votes
1answer
22 views

node API hook that can be used to alter fields before loaded by Views?

I need to use a node API hook to alter some node content before it's displayed, in Drupal 7. It just occurred to me though that if I used hook_node_view() it will not effect the output of a View ...
0
votes
1answer
36 views

How to display custom user_field in user.twig

I created a custom user field -field_interes and I want to print this field in user.twig. Anybody can help me with this problem? {{ content.field_interes }} does not work. Thank you!
1
vote
1answer
12 views

Theme Preprocess Conditional Field Display

Looking for a way to preprocess two fields. I am trying to hide Field 1 from display if Field 2 has value. If Field 1 has value and Field 2 has value display Field 2 only. If Field 1 has value and ...
0
votes
1answer
30 views

Invoke javascript in hook [on hold]

I have create a hook to alter page funcionality. It's posible invoke javascript function in hook. I test this function but i had this error --> Call to undefined function alert() ...
0
votes
0answers
11 views

Setting the default value of the country field in an address with tokens and hooks

I would like to set the default value of the country in the Drupal address field (address module) with a country that I have collected in another process on my site. It would be great if I could "...
0
votes
1answer
21 views

How do I redirect to a certain page from user profile page

I have created a hook and redirected the users after login from the login page to a certain page. But when I go to /user/login after a successful login will redirect me to the user profile page (/...
1
vote
1answer
29 views

Can You Use HOOK_node_builder() to Set Custom Node ID?

Drupal 8.x How do you set the node id in HOOK_node_builder()? Is it even possible? There is a similar question here: Specifying a custom node id when creating new content, however it is a different ...
0
votes
1answer
43 views

html.tpl.php for a View (machine_name)?

how can I assign my own html.tpl.php to a view (machine_name) via a preprocess-function (template.php) or a hook? If my view is called "foo_view_machine_name_bla", which contains 50 views-pages with ...
0
votes
1answer
18 views

When does hook_menu run?

I need to edit the hook_menu function in my module. I need to add a new link to a menu, and edit the path for an existing link. Is this possible without creating a whole new module? The only ...
0
votes
0answers
39 views

After an unsuccessful form validation the ajax callback is not found

In the hook form alter I have a validation function calculate_allocation_form_alter(&$form, &$form_state, $form_id) { if ($form_id == 'node_work_plan_form') { $form['#validate'][] = '...
0
votes
0answers
34 views

How to handle multiple submit handlers of a webform

I have a webform and added a custom submit handler using a plugin and added another remote post post handler I want to add the submit data to my custom table and if the data is saved successfully then ...
1
vote
2answers
36 views

How to pass variables to overridden Twig template located in module?

I'd like to pass a variable to an overridden Twig template that is located in my custom module (not in a theme). Following this answer and this answer, I wrote this code in mymodule.module: function ...
0
votes
2answers
27 views

Node add form set entity reference default selection based on content from another type node

I wrote module with hook_form_alter to modify node_forum_form, i.e., node/add/forum form. One forum field is a taxonomy entity reference, field_topic. I want to set the field_topic selection based on ...
1
vote
1answer
33 views

Programmatically Create an Array of User Objects and Print in Twig Template

MYMODULE.module: function MYMODULE_preprocess_node(&$variables) { if ($variables['node']->bundle() == 'content_type') { $currentUserUID = \Drupal::currentUser()->id(); ...
0
votes
0answers
28 views

Using hook_form_alter() to add the “Select a value” option in the select list of a required field where it is not present [duplicate]

For some select fields, the "-Select a value-" option is not present when the field is made required. The first value on the list is presented. This is the case for, for example (and not limited to)...
0
votes
2answers
44 views

How to redirect from url with trailing slash to one without?

We are using redirect v8.x-1.2 with Core 8.5.6. When generating URLs, we are finding that a trailing slash (/) is added to the end of the URL and it is creating a 503 error code. How would one ...
0
votes
1answer
37 views

Using hook_form_alter() to add the “None” value in the select list of a required field

When a field is required, Drupal removes the default "-None-" value. However, also for a required field, "-None-" is very valuable as it requires the user to make a deliberate selection (put the ...
0
votes
1answer
26 views

How to remove field from form and configuration?

We have a custom module, mymodule that has a form, mymoduleForm with two fields: enabled content types and urls. We no longer need the enabled content types field on the form and want to remove it ...
1
vote
1answer
16 views

How to create custom template suggestion, when there is no hook suggestion?

I would like to create different templates for different nodes, but I cannot see any hook suggestion with theme debug. This is the template from quiz module. So in theme debug it looks like that: <...
1
vote
1answer
60 views

How do you override the add or edit node for a particular content type

I want to format the editing or adding form for the article content type. i.e. node/add/article path and editing the same article. I copied over the node-edit-form.html.twig template from core/modules/...
0
votes
1answer
16 views

Reassign $view_mode using entity field passed to hook_entity_view_mode_alter()

I'm using baseFieldDefinitions to create my custom entity form. With gracious help here, I've been able to successfully generate a radio button on the form which lets the user select what view mode to ...
1
vote
3answers
102 views

How to use helper/private methods with a .module file?

Let's say I use a hook with a lot of code inside. To improve readability and reusability I'd like to use helper/private methods. However, a Drupal .module file is not a class. The idea is to split ...
0
votes
2answers
18 views

Theme hook_menu_alter not being called (create theme only page)

Its been quite a while since I worked on Drupal 7, but I'm hitting a snag. First please understand I only have access to the theme, I cannot create a bunch of custom modules. Now, I want to add a ...
1
vote
1answer
27 views

“hook” name in module doesn't seem to work, Drupal ignores it

I've been at this for days, but I finally think I maybe kinda sorta found part of the problem, maybe...but I don't know how to fix it. I'm working on a Drupal site with the CiviCRM module running. I ...
0
votes
1answer
46 views

How to add the paragraph parent field in the theme suggestions alter

I've been spending a couple of hours from debugging the paragraph properties using kint and var_dumper however, the page is freezing and I'm unable to see what are the properties and methods available....
2
votes
2answers
42 views

Pass Preprocess Values From Custom Module to Custom Form

My use case: I would like to create a unique textfield per region in a custom form. MYMODULE/MYMODULE.module: function MYMODULE_preprocess_region(&$variables) { foreach (array($variables['...
2
votes
3answers
69 views

Hook_form_alter for changing field labels doesn't work of user registration page

Can anyone tell me why this isn't working (in the below code, or other factors preventing the insert by the hook)? I don't get an error message or page, the field labels are simply not overwritten......
0
votes
2answers
29 views

Custom submit handler stops working when checking route

I'm trying to setup a custom submit handler, so I can change the redirect URL after submitting comments. Edit: I just want to send users back to the page they were viewing to begin with, but it's a ...
3
votes
2answers
67 views

How to add twig template suggestions per display mode with custom module?

I have a custom module where I am trying to use custom twig templates based on the user view mode. The templates files I am trying to add to my theme are: user.html.twig user--compact.html.twig user--...
0
votes
1answer
27 views

How to display current pages the media entity is referenced during deletion?

We are using Media Entity module that provides a Document media bundle. On our Article content type, we have created an Entity Reference field to Media that is set to Document media bundle. When you ...
0
votes
0answers
11 views

How can I use hook_custom_theme in maintenance mode?

I use hook_custom_theme to use different theme on a specific page. And also this page is online even when site is in maintenance mode with hook_menu_site_status_alter. When site is online, that page ...
0
votes
0answers
12 views

Possible to load newly implemented hooks without flushing the cache?

Curious if there is a better way than flushing/rebuilding caches to get a D8 site to recognize a new hook implementation. For instance, I just implemented hook_link_alter(), but it seems like overkill ...
2
votes
1answer
90 views

What is the difference between getValue() and referencedEntities() to fetch paragraphs?

What is the difference between using getValue() and referencedEntities() in order to get the paragraph on a node? See example below. Both examples are used in a node template such as node--page--full....
0
votes
1answer
36 views

Showing a message for specific content type

I'm trying to show a message for specific content type through a new module, on Drupal 8.3.0. (I'm a beginner.) This is part of the code I am using. File test_module.module (updated code, still not ...
1
vote
3answers
52 views

hook_node_view_alter not working

I'm hoping to finally find some solutions here. I'm new to custom module development in Drupal and I'm trying to learn the basics. What I'm trying to do is use hook_node_view_alter, however even at ...
0
votes
2answers
33 views

How to change theme template for the same block that is loaded twice on the page?

We have created two menu blocks: main_menu (region=main nav) and main_menu_footer (region=footer) that are added to all pages. They both are displaying the same main navigation menu except ...
0
votes
1answer
36 views

Trigger Emails/Handlers on Webform submissions update

Is there a way to trigger the Emails/Handlers, When webform submission has been updated. I'm using webform_mailchimp as a handler. When I'm submitting a new record, handler is working fine and I can ...
0
votes
0answers
13 views

Feeds remove item with certainly conditions

Good day I have a problem with the side of developer with certainly conditions i need remove a item from source. for example i have in source nid and phone1 and phone2 but if phone2 is the same ...
0
votes
0answers
18 views

How can I alter the result of a view search?

I am building a view block with a full-text search filter and it's working fine. But now I want to get rid of some of the search results when the user searches for some certain keywords, how should I ...
0
votes
1answer
27 views

Adding link to the main help page

I have created an help page for my module function amu_hal_help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.amu_hal': return 'some content'; ...
0
votes
1answer
25 views

'hook_entity_operation_alter', but for users [closed]

I'd like to customise the Operations dropdowns on /admin/people The documentation for hook_entity_operation_alter() says the second parameter should be: \Drupal\Core\Entity\EntityInterface $entity: ...
0
votes
3answers
43 views

How to change the title and add a placeholder to password and confirm password field through hook_form_alter?

How can i remove the label of the password and the confirm password field through hook_form_alter functionality ? Tried the below: $form['pass']['#title']= t(''); $form['pass']['#description']= ...
1
vote
1answer
69 views

How can I change a field cardinality?

I have two content types: Person and Office with existing content. The Person content type has an entity reference field to Office nodes, which only allows a single reference. I need to change this to ...
0
votes
0answers
8 views

Render form, hide alle form fields and then show some of them

I'm trying to render the user profile form in a block since i want users to be able to quickly edit certain fields of their user profile. Rather than manually hiding all the fields that they should ...