Latest Drupal related questions

Score: 1
Confirmation message on comment submission
in flag

When a comment is submitted, no confirmation message is shown and I would like to achieve this. I want to show the following message.

Your comment has been added for review and approval.

I tried this code.

function mymod_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  else if ($form_id == 'comment_comment_form') {
    $form['actions']['submit']['#value'] = "your comment has been ...
Score: 0
griz avatar
How can I show tax per line item at checkout?
jp flag

In D7, there was a module named 'Commerce price by components' which allowed us to display a price inclusive or exclusive of tax. I would like to show a detailed tax breakdown at checkout as most of my store's products are tax exempt, but some are not.

Is it possible in D8 to show the a price inclusive and exclusive of tax as two columns in the checkout summary / review table? Or is it possible to show  ...

Score: 0
bigboy avatar
How to open a field value dynamically in a modal dialog on node view?
gu flag

I have a content type with a field, which contains HTML data (a short article).

When viewing a node, I want to have a link (or button, doesn't matter), which will open a modal dialog with the value of this field when clicked.

Content of the modal (fields value) has to be loaded dynamically. In other words, the content of the modal should be loaded in DOM only when (and if) the link is clicked.

This is  ...

Score: 0
Jason avatar
Entity reference field hidden widget or edit disabled on custom form
in flag

I have a custom node creation form I am rendering within a views preprocess hook. In that form I have two entity reference fields. I am setting the [#value] and [#default_value] of those reference fields programmatically.

On form submit the values I've set are created, but only if the fields are "editable" by the user. I want to make the fields "disabled" and/or "hidden" from the user. Not just h ...

Score: 2
Add a custom variable to an existing block
mx flag
JFK

Is there a way to alter the render array of an existing block? I want to do it for a commerce block (cart block) but the question remains for any core or contrib module block.

When a block uses a custom #theme for it's block, is there a way to alter the definition?

Let's say the module defines the following theme :

/**
 * Implements hook_theme().
 */
function commerce_cart_theme($existing, $type, $theme, ...
Score: 1
863 avatar
How to show progress bar twice on one request (with Batch API)
ng flag
863

I have a custom form which handles two different process after submission, let's say

  • Process 1: removing all article nodes
  • Process 2: importing article nodes from csv.

The problem is that each process have to have its own progress bar.So, it should look like:

  • Form submitted
  • Progress bar for process 1 starts(0%)
  • Progress bar for process 1 finishes(100%)
  • Progress bar for process 2 starts(0%)
  • Progress ...
Score: 4
Smartsheet eng avatar
What is the stable9 theme? When should I use it instead of stable?
um flag

https://www.drupal.org/node/3066038

Has this cryptic statement:

However, defaulting to base theme: stable prevents automatic updates to the next major version of Drupal, since each major version may have a different version of "the stable theme"

and proceeds to list these without any explanation.

The READMEs in the relevant directories are no help.

Warning: Themes that opt out of using Stable as  ...

Score: 1
Steve Siddu avatar
How to add class to multiple view-blocks using twig?
br flag

I have four blocks to a view. I want to add class 'fancy-body' to all four blocks. How can I add that.

view_id : categories

display_id's of blocks : block_1, block_2, block_3, block_4

I know, I can add classes by creating individual twig template file for each block. like this,

block--views-block--categories-block-1.html.twig
block--views-block--categories-block-2.html.twig
block--views-block--categorie ...
Score: 0
usmanjutt84 avatar
Integrate SMTP and recaptcha modules with key module
in flag

I am not a module developer. And I am trying to make key module working with recaptcha and SMTP modules as I see in the video tutorial. I have already setup modules and configured keys by adding files in private directory and was also able to show the dropdowns in recaptcha config form for site and secret recaptcha keys by following key's documentation in the hook_form_alter.

However, I am curious to k ...

Score: 0
bigboy avatar
Filter views by field value equals another field of curent node
gu flag

D9.3. All fields are not referenced, they are just simple integers. All data was pulled from a huge external API and it was not possible to create all references.

Just for ease of understanding, imagine a book database website with books and characters. But each character is presented in one book only.

So, book node has field_book_id, which is numeric, unique, but not NID. Also it has a multiple  ...

Score: 0
Steve Siddu avatar
How do I dynamically add filters?
br flag

I have a view_block with the following filters,

enter image description here

I want to change the product tag, Release tag, Document type values dynamically based on url.

if the url is, example.com/mars/21.43.00/ProductGuide, then the filters should change like this

enter image description here

I don't know how to achieve this, any suggestion would be helpful

Thank you!

Score: 1
Altering custom template from code
pt flag

How can I programmatically remove blocks and other elements from a single custom template ?

In my custom modle I have defined a route to a controller which then loads a template which is also contained within the same module. I am successfully loading data from the controller into the template.

My issue is that the template inherits blocks and menu from the active theme which I need to remove but on ...

Score: 1
Make Title field "not required" or workaround how to prefill and hide it (drupal 9.2.8)
ug flag

On my site (drupal 9.2.8) users add content and there is no need to put any information to 'Title' field. I was trying to make this field not required via form_alter in custom module but it did not work:

function yourmodule_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id){
  if ($form['#form_id'] == 'node_somenode_form' or $form['#form_id'] == 'node_somenode_form') ...
Score: -5
Is by design, Drupal headless?
es flag

If I understood correctly, "decoupling" a content management system means separating backend from frontend (having two "modules" for each under the same "program").

If I understood correctly, "headlessing" a content management system is making it to be possible to supply content to at least two different front-end interfaces at once ("two different programs" as may appear to an end user).

I would as ...

Score: 1
Can't save value of custom datetime field
in flag

I'm reaching out because I just can't find out why my custom datetime field isn't saving its value after I submit.

Context:

I've created a field containing two datetime fields. I will use it to add or remove events from an event list, depending on whether they have passed or not (for example if a festival is scheduled from the 12 to the 14 of December, the event will be removed after the 14th).

Events in  ...

Score: 0
Can't upgrade Webform from 5.x to 6.x: "Entities exist of type Webform submission and Webform"
vn flag

I recently updated my site from Drupal 8.9.19 to 9.2.8, and from Webform 8.x-5.28 to 6.1.0.

I'm now trying to deploy this update to my test server, and I'm getting the following error when running drush cim:

 [error]  Drupal\Core\Config\ConfigImporterException: There were errors validating the config synchronization.
Entities exist of type <em class="placeholder">Webform submission</em> ...
Score: 0
Joost avatar
Is it possible to see which modules grants access rights?
jp flag

Working on a Drupal 9 website the module Permissions by term gives an unexpected behaviour.

Trying to find the problem I got stuck. I think there might be another module overwriting the permissions. But I can’t find out which one.

Is there a way to see which module grants what right to a node/user?

Or is there another step I should do to debug these node permissions?

Thanks a lot!

Score: 0
Lambic avatar
Migrating an array of values into multiple entities
ph flag

I'm using migrate/migrate_plus modules to import CSV files and generate entities.

One of the columns in the CSV can contain multiple values like 1|2|3, which I'm converting to an array using:

_jurisdictions:
  plugin: explode
  source: jurisdiction
  delimiter: "|"

I'm then using the array to generate taxonomy terms with this:

field_political_district:
  -
    plugin: entity_generate
    source: "@_ ...
Score: 0
sndr avatar
Load view form with ajax missing ajax functionality
us flag

When clicking an element I get a form which is generated by a view (using https://www.drupal.org/project/editablefields module). The problem is that the ajax functionality of the form is lost (no ajax-processed classes are present). This is the working js code to retrieve the view:

(function($,Drupal) {
  Drupal.behaviors.MODULE = {
    attach:function (context, settings) {   
      $('#test').cl ...
Score: 0
Baud avatar
Drupal::messenger() not working in shutdown function
sa flag

Some time I need to use a shutdown function. Here is a stupid example:

...
drupal_register_shutdown_function('display_message');
...

function display_message() {
  Drupal::messenger()->addMessage('Hello world');
}

Is it possible to display this message as for now, it is not working (even at the nex page refresh)?

As requested I will explain why I need to use shutdown function.

My use case:

We are in ...

Score: 0
Steve Siddu avatar
How to add contextual filter?
br flag

I am working with books in drupal 8. I want to display a specific page("table of contenets") on the sidebar whenever any page of that book is accessed. "table of contents" is a book page. every page of book has two id's.

  • page_id
  • book_id

Page_id is unique for every page but book id is same for all pages. I believe contextual filter based on book_id might solve my issue. but I don't know how to add c ...

Score: 0
Giuseppe avatar
How get the referenced entity inside a field link?
br flag

I'm on D9. I've a paragraph with a Link field. I need to get the referenced entity programmatically.

What I've managed so far is:

       $nid = NULL;
       $field_link = $paragraph->get('field_link')->first();
       $route_params = $field_link->getUrl()->getRouteParameters();
        
        if(isset($route_params['node'])) {
          $nid = $route_params['node'];
        }

       if($ni ...
Score: 0
Hide and unhide custom block programatically drupal 9
cn flag

Hello I have created a module to display a block. I would like to set the block visibity to visible and hidden in the homepage based on a condition.

like this:

edit:


//fetch status from database then check condition
if ($status = 1){
//make block visible
}else{
//hide block
}

I have searched all over the internet and could not find how to make it work.

I have a form that is used to add contents to a ...

Score: 0
Amine avatar
Time spent with custom module
us flag

Can anyone help me with this, I want to activate time spent module on my custom form module, and store the time spent on a field on my form. I think that I could do it on the file timespent.module here.

function time_spent_init() {
  //if user has a role who is going to be tracked, add javascript code
  if (time_spent_user_has_role()) {
    $timer = variable_get('time_spent_timer', TIME_SPENT_TIMER);
   ...
Score: 1
SomebodySysop avatar
How to add view filter programmatically using hook_views_pre_view()
gb flag

I want to add a simple filter to an existing view in Drupal 9. It appears that I can achieve this with hook_views_pre_view(). In every example I can find, including all the "Similar questions" links that come up when entering the title of this post, I see that $view->add_item() is used. See: Add views exposed filter programmatically

However, when I try to run this code:

function sbn_views_pre_view($vi ...
Score: 0
Custom block plugin: Give access to edit form
in flag

I am creating a custom block plugin with custom configuration options (blockForm()).

I would like to allow content editors to edit the configuration of this block, without giving them "administer blocks" permission. Also, I don't want them to create new block instances..

I would like to avoid installing an additional module like block_permissions, as this would introduce a wide range of settings or pe ...

Score: 0
Views: count flaggings per entity-referenced node
pe flag

I have a flag called Collect. (Flag is individual, and enabled on multiple content types.) The flag has an entity reference field to a content type called Bucket. When users flag nodes, they go to a form and select the bucket for the flagging in the entity reference field (field_bucket_select).

Users can view their Bucket list in a view that filters on 'current logged in user' (as well as the con ...

Score: 0
Provide menu link when creating node programmatically and append it to parent menu link
in flag

I am creating a Node programatically:

Node::create([
  'title' => "Some name",
  'type' => "people",
  'body' => $params['body'],
  'field_people_degree' => $params['field_people_degree'],
  'field_people_email' => $params['field_people_email'],
  'field_field_image' => ['target_id' => $this->createImageFile($params['field_field_image'], $params['field_pub_tool_id'])->id()],
  ' ...
Score: 0
Timberman avatar
Link user to a LDAP user
cn flag

I have the LDAP authentication module installed, and have a user that is not able to sign in using LDAP.

In the database I can see that there is no DN string for this user.

I have got the DN string for this user.

Is it possible for me to add this string somewhere in the database, for him to be able to login to drupal again?

Thanks!

Score: 0
Rainer Feike avatar
Create solr_core for search_api_solr 4.x with docker solr 8
in flag

I used to create my solr instance for drupal like this:

docker run -v $PWD/solrconf:/asdentcore  -e SOLR_JAVA_MEM="-Xms2G -Xmx2G" --restart unless-stopped  -p 8984:8983 -t --name asdentDevSolr -d solr:8.11
docker exec -it --user=solr asdentDevSolr  bin/solr create_core -c asdentcore -d /asdentcore

Where ./solrconf contains the files from modules/contrib/search_api_solr/solr-conf-templates/7.x.

With the n ...

The Stunning Power of Questions

Much of an executive’s workday is spent asking others for information—requesting status updates from a team leader, for example, or questioning a counterpart in a tense negotiation. Yet unlike professionals such as litigators, journalists, and doctors, who are taught how to ask questions as an essential part of their training, few executives think of questioning as a skill that can be honed—or consider how their own answers to questions could make conversations more productive.

That’s a missed opportunity. Questioning is a uniquely powerful tool for unlocking value in organizations: It spurs learning and the exchange of ideas, it fuels innovation and performance improvement, it builds rapport and trust among team members. And it can mitigate business risk by uncovering unforeseen pitfalls and hazards.

For some people, questioning comes easily. Their natural inquisitiveness, emotional intelligence, and ability to read people put the ideal question on the tip of their tongue. But most of us don’t ask enough questions, nor do we pose our inquiries in an optimal way.

The good news is that by asking questions, we naturally improve our emotional intelligence, which in turn makes us better questioners—a virtuous cycle. In this article, we draw on insights from behavioral science research to explore how the way we frame questions and choose to answer our counterparts can influence the outcome of conversations. We offer guidance for choosing the best type, tone, sequence, and framing of questions and for deciding what and how much information to share to reap the most benefit from our interactions, not just for ourselves but for our organizations.