Latest Drupal related questions

Score: 1
Bytech avatar
Running a hook after node save, or another way to get the file name attached to a node
ls flag

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 getting the file name from $node in the _node_presave hook, but $node does not contain it. What it does contain is the nid. So we're using that with $nodeContent = \Drupal\node\Entity\Node::load($nid) to load ...

Score: 0
Form API: How to add arbitrary render element after specific field?
ru flag

I've got an input field in an entity form which needs quite a bit of extra documentation. This documentation is long and needs computed, contextual information, so a simple field description or #field_suffix just doesn't do it. I also want to keep the ability to move fields around in field UI. I'm trying to create a form_alter hook to inject a render element with my docs right after that field.

I alr ...

Score: 1
Priya Degwekar avatar
Get the value of taxonomy custom user field
gb flag

I am trying to get a taxonomy field in hook_user_insert().

user account

The logic is that if the taxonomy field is selected as none then print warning message along with a success message.

function drupal_practice_user_insert($account) {
  $user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
  $brand = $user->field_add_brand->value;
  if ($brand == null) {
    \Drupal::messenger()->addWar ...
Score: 0
Free Radical avatar
How to inspect the form values in hook_user_update()?
kz flag

In Drupal 7, one could have the following hook_user_update() to return TRUE if the 'roles' has been edited:

function example_user_update(&$edit, $account, $category) {
  isset($edit['roles']) ? TRUE : FALSE;
}

In Drupal 10, the signature of the hook has changed, and we no longer have direct access to the paramter $edit (the array of form values submitted by the user). How do one do this in  ...

Score: 0
How can I overwrite the value of a field in a bundle class?
cn flag

In Drupal 9 I would like to know if it is possible to overwrite the value of a field in a BundleClass. Looking at the Drupal API, I see that it is common to use either hook_entity_view_alter or hook_views_pre_render. The only way I have found is to define a new method:

public function getUpdateFieldName() {
  $value = this->get('field_name')->getValue();
  # Code here ...
  return $code
}

Ho ...

Score: -1
xdobx avatar
Why does Drupal\\Core\\Config\\UnmetDependenciesException occur on install?
nr flag

I tried to Install drupal on a Ubuntu 22.04.2 VM. I route the guest via NAT to my host. Then I created a folder in my webroot and let Apache point to it. After that, I downloaded the installation file via composer to the folder. and surf to the domain in the browser and get routed to the installation site just as expected. I can progress without errors (just a warning about clean URLs, but the installat ...

Score: 1
leandro713 avatar
How to write in a ckdeditor textarea with Cypress?
br flag

i'm trying to create a new node in Drupal 9. But all my attempts so far have failed when it comes to writing the body text. The body text is a Ckeditor5 field. I can't write there with Cypress.

I tried the following line with the following error: "Cannot read properties of undefined (reading 'instances')"

  cy.window().then(win => {win.CKEDITOR.instances["html_body"].setData("<p>HTML body</ ...
Score: 0
loarrin avatar
How can I list ordered items in the custom-made confirmation letter?
la flag

I use a simple custom module to send confirmation emails in Drupal 9 Commerce 2 for a custom order states.

I am basing my module off of the example shown in the handbook. The main module script resides in modules/custom/my_newmodule/src/EventSubscriber, its name is OrderProcessSubscriber.php and its code is as follows:

<?php

namespace Drupal\my_newmodule\EventSubscriber;

use Drupal\state_machine ...
Score: -1
bimsalrobit avatar
Why is cweagans/composer-patches not installing this patch?
id flag

I'm trying to apply different patches but after the command composer install nothing happens. Output:

Installing dependencies from the lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. It is recommended that you run `composer update ...
Score: 0
miststudent2011 avatar
How to create a service for the class with constructor arguments from a vendor package class?
fr flag

I am trying to inject class from FFMpeg in my custom service of a module.

But the class has two constructor arguments. So how can I pass those arguments in my custom service.

my_module.services.yml

services:
  # FFMPEG Factory
  my_module.php_ffmpeg:
    class: FFMpeg\FFMpeg
    autowire: true

I understand that as there are two parameters in the costructor, we need to pass two arguments in service defini ...

Score: 0
How to delete a no longer used custom bin table?
pe flag

I'm testing the cacheAPI with a custom bin. Everything is working. On the other hand, while testing, I created a custom bin with a name that does not suit me.

cache.lorem_bin:
  class: Drupal\Core\Cache\CacheBackendInterface
  tags:
    - { name: cache.bin }
  factory: ['@cache_factory', 'get']
  arguments: [lorem_bin]

A table in DB cache_lorem_bin was created.

So I modified it and another table was c ...

Score: 0
Darren Whittenham-Gray avatar
How do I output an embed of a private file PDF in views
fr flag

What I am trying to do is embed a pair of PDF files on a page using a View; however because they are uploaded to the private file store I think I am on to a loser.

My preferred desire is to have the PDF viewable on the page generated by the View, but that they can be clicked on and downloaded as well.

I am using Drupal 10

I have a content type where the user uploads two separate PDF’s into two separ ...

Score: 2
Binary Alchemist avatar
Convert an existing entity type to revisionable
in flag

I am trying to make an existing entity type (knowledge), from the Knowledge Project, revisionable. I followed these instructions Converting a content entity type to be revisionable. A new table, knowledge_revision, is not created, and and the fields are added to the knowledge table. I am lost on what to do next.

update code


use Drupal\Core\Field\BaseFieldDefinition;

$definition_update_manager = \ ...
Score: 0
Delford Chaffin avatar
People view showing some users multiple times and others not at all
gg flag

I'm seeing some weird behavior in the build-in People view and I'm going to try to explain it.

There are 168 users in my site. If I change the view to show them all (and not paginate), it shows them all fine. If I revert to default pagination (50 per page), it still shows a total of 168 records across 4 pages, but some users are duplicated and others left out.

In trying to understand what is happeni ...

Score: 1
Jaypan avatar
Views: Filter and/or sort by computed field - hook_views_data()
de flag

I have created a computed field, using ComputedFieldTrait. It is working fine, I am able to add the computed on the manage layout pages. I have implemented hook_views_data_alter() to tell Views about the computed field, and I am able to add the computed field to a view.

However, I need to do both a sort and a filter on the computed field.

My question: How do I structure my return value from hook_vie ...

Score: 0
quantumized avatar
Is it possible for a Views Pager Items Count to count the number of field groupings instead of rows?
ng flag

We have a View that uses grouped entities displayed using an accordion formatter. Each according "group" has a varying amount of rows in it.

We would like to display 10 groups per page but if we set the page to display 10 items it may only display one accordion group if that group has 10 or more rows in it.

Is there a way to display a set number of Views grouped fields per page instead of rows?

enter image description here

 ...
Score: 1
Darren avatar
How do I stop Fields being rendered twice for a node with Paragraph Types using UI Patterns?
in flag

I'm using UI Patterns within Paragraph Types which is resulting in the Fields being rendered twice in the theme. I'm using a sub theme of the bootsrap5 contrib theme. I have a custom layout twig:-

{#
/**
 * @file
 * Theme override to display a two-column layout.
 *
 * Available variables:
 * - in_preview: Whether the plugin is being rendered in preview mode.
 * - content: The content for this layou ...
Score: 0
How do I disable caching of a custom token?
pl flag

I have created a custom token which reads values from the Apache Request Headers. It seems to work fine for my testing, but then when another user subsequently accesses the token, it uses my values. It seems that the token value is being cached. How do I disable caching on custom token values? NOTE: because of the use situation, I need to disable caching on the token value (or whole page), not just  ...

Score: 1
Francesco Marchetti-Stasi avatar
Use CSS preprocessor on CKEditor 4 contextmenu
iq flag

I had to customize the look and feel of the CKEditor 4 context menu for our (internal use only) module. So, I copied core/assets/vendor/ckeditor/skins/moono-lisa/editor.css to my_module/css/contextmenu.css, I changed it to my liking, and then I added the following line in src/Plugin/CKEditorPlugin/CustomInternal.php:

    $config['contextmenu_contentsCss'] = '/CLS/modules/custom/my_module/css/context ...
Score: 0
commonpike avatar
How do I programmatically assign a new book when a new node is created?
in flag

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, and for editors to create a new book I ask them to create a cover first. this makes more sense for them. The 'add child page' links will then appear automatically. I know they can select 'new book' o ...

Score: -1
user108721 avatar
Getting old node field value in update hook
kp flag

Hi I'm using the node update hook in my custom .module file in my Drupal 9 site. I have a field called field_amount. And I was wondering if I can access the old value of that field within my update hook and the new value too?

function custom_module_node_update(\Drupal\node\NodeInterface $node) {
  //access the old value of field_amount and the new value
}
Score: 1
somo avatar
What is the meaning of "fields pending deletion"?
bo flag

I have a Drupal 9.5.3 installation which is not customized in any way; no custom modules or themes.

I want to remove the Comment core module but I can't and the reason that is given is:

Fields pending deletion

That's strange because I have already deleted all comments, all comment fields in any content type and all comment types and I can't think of anything else relevant to delete.

What is the mea ...

Score: 0
York Bishop avatar
How to use microsoft graph toolkit within a custom module?
in flag

I am creating a custom module and want to use microsoft graph toolkit, specifically the file-list component (https://learn.microsoft.com/en-us/graph/toolkit/components/file-list). I've created a my_module.libraries.yml file which looks like this:

mgt:
  js:
    https://unpkg.com/@microsoft/mgt@2/dist/bundle/mgt-loader.js: {}

file-list:
  js:
    js/file-list.js: {}
  dependencies:
    - core/drupal
    ...
Score: 0
jacksparrow avatar
Views posts not displaying correctly until clearing the cache
ve flag

I have an issue with a Drupal 8 website. I have some pages that have views listing some contents ( text and images). The websites uses CDN and varnish. The problem is that sometimes, the contents like images in the views display two times bigger on the page and things are scattered all over until I clear the cache (refreshing the page does not solve the issue) and only then everything displays correctly ...

Score: 0
user108721 avatar
Converting date in field-created.html.twig
kp flag

node-created.html.twig to override some html. That works fine. Although the date is being displayed as Thu, 04/28/2022 - 11:39 which I want to be something like May 2, 2023. Is this possible within this piece of twig code?

{%
  set classes = [
    'field',
    'field--name-' ~ field_name|clean_class,
    'field--type-' ~ field_type|clean_class,
    'field--label-' ~ label_display,
    'created-label',
 ...
Score: 0
Why isn't this configuration saving?
us flag

How do I do change configuration when there is a dash in the yml file?

The configuration is the following one.

source:
  plugin: url
  data_fetcher_plugin: http
  data_parser_plugin: xml
  urls:
    - 'private://migrations/migration.xml'

I need to change it to the following.

source:
  plugin: url
  data_fetcher_plugin: http
  data_parser_plugin: xml
  urls:
    - 'private://migrations/2023-05-01/migra ...
Score: 0
Md. Shafiq Hossain avatar
I can't uninstall any module after I uninstalled deprecated modules
cn flag

I have Drupal 9.5 installed and running. I have uninstalled 3 deprecated modules (Aggregator, Color, and RDF). After that, I can't uninstall any module using the user interface. It gives the following error.

LogicException: Missing bundle entity, entity type comment_type, entity id comment. in Drupal\Core\Entity\EntityType->getBundleConfigDependency() (line 885 of web/core/lib/Drupal/Core/Enti ...

Score: 0
ilechcod avatar
Can an installation profile have service.yml files?
in flag

I have a dxp_installer installation profile. I want to use the container injection for a service which I use in hook_install_tasks_alter() to verify the installation requirements. Note that I inject this service in one of my custom install forms construct, and not directly from the dxp_installer.install file.

I have defined this service in the dxp_installer.services.yml file. Now when I add containe ...

Score: 0
Madam Adam avatar
Single product with multiple variation types: set-up for a product (book) that's available as hardcopy and as downloadable file
mx flag

I'm searching for an approach for selling printed books as well as e-books in different file formats with Drupal Commerce:

  1. Hardcopy (variation type 1)
  2. PDF file (variation type 2)
  3. ePUB file (variation type 2)

While variation type 1 works fine as a regular product variation, variation type 2 is working with commerce_license and commerce_file: Product option 1 (hardcopy) will be shipped and will NOT i ...

Score: 0
alphex avatar
Entity select element - referencing taxonomy, displaying and submitting from fields on term
cn flag

I have a form, with your normal suspects of fields... First Name, Last Name, Email, A text area.

But I want to submit data to this form that will help the CRM that receives route it to the right sales person.

This data is in a taxonomy vocab we're gonna call "Service Level"

The terms in this vocab have 3 fields.

  • Name (the normal drupal field you put the term name in)
  • Searchable Label
  • CRM Email Address ...

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.