Latest Drupal related questions

Score: 0
Patoshi パトシ avatar
Creating content on via REST API using POST: proper formatting of json?
kr flag

I'm trying to do a POST to create content on my site, but I get an Access Denied for creating field: changed even though I am an administrator role. When I remove the "changed" field in the JSON I get the Website encountered an unexpected error error. I assume my JSON format is incorrect. I got it from doing a GET on one of the published nodes, and just removed the nid and uuid values in the JSON.

 ...

Score: 0
Kevin avatar
Using StreamedResponse for AJAX?
in flag

I am looking for a way with a Form API form in Drupal to have an #ajax event on a form field. When submitted, this calls a remote API.

How can I stream the response out to the screen without the request being terminated before completing the stream read?

I thought maybe I could do this in the #ajax callback:

  /**
   * {@inheritdoc}
   */
  public function getResponse(array &$form, FormStateInterface ...
Score: 2
liquidcms avatar
How to create a group of sub tokens off an entity type?
us flag

I am trying to create sub tokens in a group off of existing Users token (sometimes referred to as "chaining"). So there are 2 parts to this. Creating the subgroup off the existing User tokens group and creating tokens within that group. I really only need the hook_token_info() part of this; not the actual token code.

I am trying to create a set of tokens of the form: [user:state:{token_id}]. Exam ...

Score: 0
Override a field in a taxonomy terms view
us flag

I have a taxonomy terms view, filtered by a vocabulary. I would like to add the dashes before the term name like in the Parent terms field on the edit term page. The code in TermForm.php does that when creating $options using str_repeat based on the item's depth.

This is the code from TermForm.php:

$tree = $taxonomy_storage->loadTree($vocabulary->id());
$options = ['<' . $this->t('root' ...
Score: 0
Anders avatar
Is it ok to share a comment field with multiple content types?
bo flag

Imagine I want to convert individual forum threads (topic + comments) into a content type 'Blog post' to preserve them for the long term.

In order to make this work, the comment field of 'Blog post' needs to be identical to that of 'Forum topic' (this is a limitation of the conversion module currently in beta). Thus I simply re-used the comment type comment_forum also for 'Blog post', which works fine.

Score: 0
Alex avatar
Replace Tokens from Webform Submission in DOCX
ua flag

This is my first question here at Drupal Answers and I try to be as precise as possible.

I'm using Drupal 9 and the current version of the webform module. What I am trying to do is replacing tokens (placeholders) in a DOCX file with values submitted with a webform.

To get this work I wrote a custom Webform Handler. This handler provides a file upload where I submit the DOCX that contains the placeho ...

Score: 0
Config split is imported only every second time of jenkins job run
ng flag

I have some weird behavior with drush cim when running from a jenkins job. It seems like a config split is only imported every second time or so when the job is run. The update skript containing the drush cim does work fine on local ddev sites and with other splits on other environements.

Jenkins does the following:

export stage=dev
sites=$(find "$project_dir"/web/sites/ -name "*.domain.de" -type l -p ...
Score: 0
My product variation is not shown on the entity form
kn flag

I have many products coming from a migration. This is working for most of the products, but for some of them, the /commerce/modules/product/src/Plugin/Field/FieldWidget/SingleVariationWidget.php widget is empty.

First, I thought that the product didn't have any variation. Turns out, it does.

After some digging, I've found that the formElement function inside SingleVariationWidget isn't retrieving only th ...

Score: 0
Disable pre-populated fields in webform
in flag

I have form created with Webform module, some fields are enabled for pre-population, so in some cases I use URL parameters to pre-populate them.

The thing is that I need to forbid users to change pre-populated fields (ether to disable them, or to hide them).

I checked field conditions in Webform configuration, but there's no option for this.

How it's possible to resolve this?

Score: 3
Enable a module with sample config that depends on a theme
in flag

I have a submodule that provides some prepared configuration via config/install. The goal is to have devs enable that module to get a preconfigured set of content types complete with preconfigured fields, form displays, view displays, language settings, pathauto patterns, etc. The reason why this is all in a module and not a profile is because it's opt-in, i.e. devs may or may not want this preconfig ...

Score: 0
maynardsmith avatar
How to dynamically set Test mode for a Webform_CiviCRM Contribution using Stripe Payment Processor
jp flag

This is in Drupal 9.5, CiviCRM 5.60, Webform 6.1, Webform_CiviCRM 6.2.

I have a webform which is allowing a Contact to make a CiviCRM Contribution - for example a simple Donation. If I manually set the Contribution into Test mode, then I can perform the payment process with a test card number, without actual money being involved. I would like to be able to programmatically set Test mode during  ...

Score: 0
Libbna Mathew avatar
Getting error while importing the fields in Google Analytics Reports module
in flag

I have installed Google Analytics Reports module latest version, enabled the GA reports data API and created a service account credentials on developer console. Then I have downloaded the json file of service account and uploaded in the GA reports module configs and also added the property id. But now when I am importing the fields I am getting this error. enter image description here

I have checked the logs also and it says

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  ...

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.