Latest Drupal related questions

Score: 2
How to remove a css file from an already-overridden definition?
US flag

I want to create a custom theme and remove a css file from diretory themes/stable/css/filter.caption.css from Stable theme. I found this file in stable.info.yml

libraries-override:
  filter/caption:
    css:
      component:
          css/filter.caption.css: css/filter/filter.caption.css

From my_custom.info.yml

libraries-override:
  filter/caption:
    css:
      component:
        css/filter.ca ...
Score: 0
Baud avatar
Sub request doesn't take care of the language
sa flag

I have defined a route as follow:

mymodule.node_summary:
  path: '/node/{node}/summary'
  options:
    parameters:
      node:
        type: 'entity:node'
  defaults:
    _controller: '\Drupal\mymodule\Controller\NodeSummaryController::content'
    _title: 'Summary'
  requirements:
    node: \d+
    _entity_access: 'node.view'

Then I have created the following controller:

class NodeSummaryControl ...
Score: 1
inertiahz avatar
Module template for a comment field is not triggering comment_preprocess_field
ng flag

I have a custom module in which I am trying to override a comment field's template in Drupal 9.3.

In my module file I have defined the hook_theme to override the core template in use. (comment.html.twig), which works, but it is not triggering the comment_preprocess_field hook in comment.module which then assigns the comment variables to the template.

My module file hook_theme is:

function MODULE_t ...
Score: 0
May  avatar
Get taxonomy and check if published?
zw flag

I am trying to display taxonomy programitcally. The problem is, all taxonomy is displayed whther published all not. How can I filter only published taxonomy.

I use this code to get taxonomy.

$tree = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree(
  'vocabulary_name',
  0,
  1, 
  TRUE               
);
 
$results = [];
 
foreach ($tree as $term) {
  $results[] = $term->ge ...
Score: 2
Matoeil avatar
is it possible to make use of data stored using the user.data service ifor filtering views?
za flag

Allowing a user to bookmark a node i have created

 public function bookmark($nid,$uid) {
    $user_data = \Drupal::service('user.data');
    $bookmarked_nodes = $user_data->get('my_module', $uid, 'bookmark');
    $bookmarked_nodes[$nid] = $nid;
    $user_data->set('my_module', $uid, 'bookmark', $bookmarked_nodes);
    \Drupal::messenger()->addStatus(t('node bookmarked.'));
  }

i would like th ...

Score: 0
ventura avatar
How do I get the product item author id from the order object?
cn flag

I have a website, where users can add their products. After a user purchases a product and pays for it, I want to create some custom logic. I need to know the authors of the individual items purchased. After following this guide I have the below EventSubscriber code

public function orderCompleteHandler(WorkflowTransitionEvent $event) {
  $order = $event->getEntity();
  $items = $order->getItems( ...
Score: -1
orcanic avatar
How to include remote web page
ms flag

I have a simple problem but can't find a simple solution. I want to include remote (dynamically created) web page into Drupal generated page. Previously i used PHP filter module in Drupal, so i would write something like readfile("remoteURL") in CKeditor and that worked fine. Now, i'm searching for something more elegant and more secure but i just can't find it. Anybody knows? Thx.

Regards.

Score: 0
Jay Williams avatar
How do I check if TwigTweak is enabled before declaring a function in a template?
us flag

I am cretaing a theme which uses the twigtweak module to display some views/blocks in some of the templates.

If a person enables the theme before enabling twigtweak module they get an error. For example if I put the following in a template, the site gets a php error 'drupal_entity is an unknown function'

{{ drupal_entity('block_content', 1) }}

So I try

{% if drupal_entity ?? false %}
    {{ drupal_e ...
Score: 1
Baud avatar
How to remove duplicates in view... the return
sa flag

I know that this question turn around in Drupal answers but I couldn't get a working answer for my use case.

Here it is: I have a view which is producing duplicate results (and I understand why) but I couldn't find a way to remove them in the hook views_query_alter

This view is requesting nodes with some filters and a left join (Require this relationship) on a field wich contains references to pa ...

Score: 0
quantumized avatar
How to have Views Attachment show all results of View, including the ones on the next pager pages
ng flag

We have a Drupal 9 View using a GeoField Map to display the results using an attachment. The problem is that we want the map to show all the results, not just the ones on the first page.

Currently, we have the pager set to 25 items per page so the map only shows those 25 instead of all of the results.

In addition to this, the map attachment is then replaced on the next page with the results from the ...

Score: 1
Lambic avatar
Adding custom operations with hook_entity_operation()
ph flag

I'm trying to add a custom entity operation to taxonomy terms of a specific vocabulary.

I've found documentation on using hook_entity_operation() to add the operation, and that works, but I'm not sure what to do from there.

Here's the hook implementation:

function nm_target_entity_operation(\Drupal\Core\Entity\EntityInterface $entity) {
  $operations = [];
  if ($entity->getEntityTypeId() == 'taxonomy ...
Score: -4
yan avatar
Why are terabytes of memory suddenly requested?
lc flag
yan

A couple of days ago I configured my server to use PHP-FPM to use different versions of PHP for different sites. After that they worked fine. Two Drupal 9 sites are using PHP 8.1, other Drupal 7 sites are using PHP 7.4.

Without any changes I am aware of, the sites stopped working. The server log file contains a warning regarding memory usage:

PHP Fatal error: Allowed memory size of 1073741824 by ...

Score: 0
Hanane avatar
Translate ajax form config
mk flag

I have created a form where a user has the possibility to add as many section as he want (via ajax), each sectionhas a field (1 field to make it simple). My question is related to multilingual website, how can I implement the interface that allow translation of this field ? I have done this using a simple form (without ajax) by following the doc https://www.drupal.org/node/1905070 Now I can't find exa ...

Score: 1
Kevin avatar
Storing temporary data in a form AJAX callback
in flag

I have a form submit button that when clicked fires an AJAX callback.

$form['actions']['submit'] = [
  '#type' => 'submit',
  '#value' => $this->t('Title...'),
  '#ajax' => [
    'callback' => '::getResponse',
    'wrapper' => 'wrapper',
  ],
];

In the AJAX callback, I would like to save what the user entered, plus what the API responded with. I have tried using form state storage an ...

Score: 0
Don Pickerel avatar
Why aren't my states showing in the Default field when setting up Order Items Type State Workflow for order fulfillment?
de flag

I'm following the instructions to set up Order Fulfillment States as per Working with state fields but when I attempt to add a new State Field the states specified in my module.workflows.yml aren't showing up as options to set the Default state. I'm not getting any errors, and I ran my yml through ChatGPT to check it.

Here's my yaml.

  id:  teflfill_order_item_fulfillment
  group: teflfill_order_it ...
Score: 0
codesmith avatar
How to check if webform has a draft submission?
cn flag

I'm using hook_webform_submission_form_alter() to prepopulate some form values. When a user saves a draft of their webform submission and comes back to it later, the code in hook_webform_submission_form_alter() is wiping out their saved values. How do I first check if there's an existing draft submission? Using Webform 6.1.

Score: 0
Ionut Gabriel avatar
Why does Drush crash with "SQLSTATE[HY000] [2002] No such file or directory"?
pn flag

I have an error when i try to update my db or install a module with drush.

[info] Try to validate bootstrap phase 5 [0.11 sec, 10.08 MB] [info] Unable to connect to database with message: SQLSTATE[HY000] [2002] No such file or directory. More debug information is available by running drush status. This may occur when Drush is trying to bootstrap a site that has not been installed or does not have a conf ...

Score: 0
VVS avatar
How do I migrate Yii2 passwords?
in flag
VVS

I migrated users from Yii2 to Drupal 9, where there are password hashes like $2y$13$nhBZ37OKp27jJBLgRkFlOuL5ac8Bda5n2XIZTjKON5gKPfIcxh61y genereated by Yii2 with \Yii::$app->security->generatePasswordHash("123qweASD")).

I migrated them 1:1.

Migrating users - advanced password examples says:

If the source system was a PHP based application that used crypt() or password_hash(), these hashes shou ...

Score: 2
Baud avatar
How to display translated fields labels of a node view
sa flag

I would like to display a node in NL. This node is not translatable but I would like to have the fields labels translated in NL.

This rendering occurs in a cron job and is used to render an email in the recipient language (ex: NL).

Unfortunately, the following code output the labels in the current language of the page (if I run it outside the cron) or in the default language of the site from within  ...

Score: 0
mullzk avatar
Modern File Manager for upload and organize documents?
ec flag

Being new to Drupal, I still struggle with its File-Management.

I have the following use-case:

  • Authenticated Users from group 'comitee' can upload files (jpg, png, pdf and docx) to the Server, rename then and structure them in subdirectories
  • Authenticated Users from group 'member' can browse those subdirectories and download the Documents.
  • Optional: Editors can reference to those files in CKEdit ...
Score: 1
WebmasterPF avatar
Adding template suggestions for a view with display ID
jp flag

I need to have suggestions for views to create dedicated template. Actually I've this in my .theme:

function starter_d9_2022_theme_suggestions_views_view_alter(array &$suggestions, array $variables) {
  $suggestions[] = 'views_view__' . $variables['view']->id();
}
function starter_d9_2022_theme_suggestions_views_view_unformatted_alter(array &$suggestions, array $variables) {
  $suggestio ...
Score: -1
Lozi avatar
Orders view personalization
cx flag

Apache 2.4.29 + php8.1 + mySQL 5.7.41 Drupal 9.5.3 Commerce 8.x-2.33

Hi all folks ! I'm trying to personalize the orders view with custumer's name, adress, ... To do that i add the "commande" field in the view with "rendered entity" form, but with that i see all the command's history, commentaries ... despite the fact that i create un special "listing" display format for commands and i hide ever ...

Score: 1
Rafael Silva de Morais avatar
Subtotals with group by
ni flag

I have a view which groups content by date and each row has a field with a numeric value (the worked field in the screenshot below). At the end of each group I would like to display the sum total of the 'Worked' field.

Is this possible in Views?

Example:

enter image description here

Score: 0
mbomb007 avatar
Stripe doesn't see API key after TrustedRedirectResponse
nl flag

I have a controller that calls the Stripe API using stripe-php to create a checkout session.

  /**
   * Checkout using Stripe.
   *
   * @param \Symfony\Component\HttpFoundation\Request $request
   *   The request object.
   *
   * @return \Symfony\Component\HttpFoundation\Response
   *   The response.
   */
  public function checkout(Request $request): Response {
    $stripe_settings = $this-> ...
Score: 0
VardeVim avatar
How can I make include the host?
mp flag

We have a form with CKEditor where a user can compose a news item. When set to 'basic HTML' input, the user can upload an image to insert as part of their input.

Later, I need to get this node body for an email. I can get the body field (what the user put in the editor), which will contain html markup.
However, the image url does not include the hostname. Is there a Drupal way to get the node body ma ...

Score: 1
Klemen avatar
Cache two sets of nodes
fr flag

I have a website where I have some blocks that have one content on all nodes, but different content on nodes with certain NID.

Right now, I have condition in block template based on node ID and blocks have route cache context and node id tags and this works perfectly.

However, this makes a new block cache entry for every NID/route, but in fact, there are only two block variants.

How would one optimize  ...

Score: 0
Grouped date filter with multiple selections
cn flag

I have a view with an exposed filter on a date field. It's a grouped filter by year using the module views_year_filter.

All works as long as I don't enable allow multiple selections. When I enable it and set the option - Any - - this option will not be saved. After a re-opening the filter settings, it's unset again.

And then, with allow multiple selections enabled I get the following errors in my view, ...

Score: 0
Viswa avatar
How to redirect custom ajax form to external url with headers
ck flag

When setting the form with ajax handler like this

  public function buildForm(array $form, FormStateInterface $form_state) {
    //...

    $form['actions']['submit'] = array(
      //...
      '#ajax' => [
        'wrapper' => 'custom_form_wrapper',
        'callback' => '::ajaxCallback',
      ],      
    );
  }

function ajaxCallback() {
  $response = new AjaxResponse();
  $url = "www. ...
Score: 0
Tobias Krause avatar
Check in buildForm method of custom form class if the form was submitted
cn flag

I have created a large form with a class extending FormBase. Many of the elements rendered within the form are only necessary for the user to see - there are not so many really relevant fields in the form but all this data gathering and rendering takes time.

When a form is submitted the buildForm() method is called first and after that the submitForm() method. Then the buildForm() method gets call ...

Score: 0
user24957 avatar
How can I set multi-value datafield on node submit?
bs flag

I would like to calculate and set the fourth (points) subfield of datafield on form submit. In the for each loop, the second and third subfield are used to calculate $points. How can I set/save the fourth value?

enter image description here

function handling_points_settings_submit(&$form, \Drupal\Core\Form\FormStateInterface $form_state) {
 $duration = 0.6;
 $node = $form_state->getFormObject()->getEntity()->toArra ...

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.