Latest Drupal related questions

Score: -1
Matoeil avatar
How can I import data from XML into a content type using the Migrate module?
za flag

I have activated the Migrate, the Migrate Plus, and the Migrate Tools modules. I have then imported a migration file at /admin/config/development/configuration/single/import.

id: beetween_jobs
label: 'Migrate beetween jobs from XML file'
migration_group: default
source:
  plugin: xml
  data_fetcher_plugin: http
    # 'simple_xml' is configured to be able to use the 'http' fetcher.
    data_parser_plu ...
Score: 2
stckvrw avatar
How do I safely mark the listener as passive and keep it working?
gb flag

I'm trying to optimize the website performance according to the Google PageSpeed recommendations. One of the advices is to set touch and wheel event listeners as passive, which is shown for the core/assets/vendor/jquery/jquery.min.js file and its a.addEventListener(n,g) line.

When I add {passive: true} to the line a.addEventListener(n,g,{passive: true}), some elements on the website using jQuery s ...

Score: 0
websoft avatar
Set the menu link description in hook_entity_presave()
cn flag

How do I update the menu link description with hook_ENTITY_TYPE_presave()?

I can print out the menu link title and menu link description with the following code.

kint($entity->menu['title']);  
kint($entity->menu['description']);

I only want to update the menu link description when the menu link title is not NULL so the menu link will exist. In fact, I'm wanting to copy the menu link title into th ...

Score: 1
Custom form password validation / strength enforcement
au flag

I have a custom form that would create user. The form is rendered with Form API and is using PasswordConfirm element, but it doesn't seem to validate the password against the default password rules (e.g. number of characters, combinations of characters).

How do I apply the default Drupal password rules to my custom form's password confirm field in the form validation method?

Score: -2
Rick avatar
Unable to pull image inside twig file
us flag

I am trying to show image via view twig file and below is my lin eof code:

<img width="220" height="112" src="{{ file_url(content.field_thumbnail_new[key]['#item'].entity.uri.value )}}" alt="{{ item.alt }}" />

When inspecting, I see the below:

enter image description here

any help on how this can be fixed pls?! I am using D9.

Score: 0
Dong Pham avatar
How to replace default value of field?
cn flag

I have a custom module.

enter image description here This is form_alter function:

 $form['article'] = [
    '#type' => 'textfield',
    '#weight' => -1,
    '#title' => t('Search Product from Magento: '),
    '#autocomplete_route_name' => 'magento_drupal.autocomplete',
    '#ajax' => [
      'callback' => '_select_ajax_form',
      // 'wrapper' => 'my_unique_id',
    ],
  ];

In the _select_ajax_form func ...

Score: 0
stckvrw avatar
Can't add an image extension to the field_image of the Article content type
gb flag

I need to upload an image with the webp extension and add it as the main image of a content item with the "Article" content type. Since its field_image doesn't have the webp extension by default, I've added the extension to the "Allowed file extensions" input at the managing tab of the field_image.

When I check the row with the name='field.field.node.article.field_image' in the config DB table, I s ...

Score: 2
Giuseppe avatar
buildForm: how differentiate between page reload and ajax callback?
br flag

I'm building a custom form in Drupal 9, which has some ajax callbacks.

During the buildForm I need to load some extra data via a rest call to an external service, which then I put inside a private_tempstore variable.

I'd like to avoid to call the rest end-point during the ajax callbacks, and rely on the stored variable.

However, I can't find a way to differentiate between the "load page" case and ...

Score: 0
miststudent2011 avatar
How can I add a constraint to a custom form element?
fr flag

I am trying to create a simple form with a single field. I have a custom constraint created for the validation of a custom field.

I would like to add the same constraint to the form element, instead of duplicating the code from the constraint class in the form validation handler.

namespace Drupal\mymodule\Form;

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;

/**
 * Provides a M ...
Score: -1
Free Radical avatar
How do I get the (integer) uid from the User entity?
kz flag

On the odd chance there was a "getUid()" method for the user entity, I tried it, but got:

Call to undefined method Drupal\user\Entity\User::getUid()

Is there a way to get the uid from the user entity, without loading the full User object?

Score: 3
How can I use core's WebP support instead of the WebP module?
cn flag

According to the change record, Drupal 9.2 supports WebP for better image compression.

I've been using the WebP module on my 9.1 site to serve WebP images, but it has a performance-killing bug and I would like to use Core if possible.

So when I upgrade to 9.2, how can I replace the WebP module with core's WebP support?

I upgraded to 9.2, uninstalled WebP, and searched for WebP options, but couldn't find  ...

Score: 1
Mathieu avatar
How do I automatically fill the subject in the contact forms?
ph flag

I created 2 types of contact form. I disabled Subject in Manage form. I want the fake Subject field not to be displayed in the contact form, and I want it to be filled in automatically.

How do I automatically fill the subject in the contact forms?

There is nothing in the contact form settings to enter static text in the subject field.

Score: 2
How do I programmatically publish the latest revision?
us flag
  1. My workflow is draft and publish.
  2. I create and publish a page.
  3. I create a draft of the page.

There is now the published page, but the latest revision is the draft.

How do I programmatically set as published the latest revision?

This code publishes the node.

$node = Node::load(nid);
// Publish and save the node.
if ($node->hasField('moderation_state')) {
  $node->set('moderation_state', 'publi ...
Score: 1
What is the maximum value you can set the cookie_lifetime to?
pg flag

I have a Drupal 8 site, and in my sites/default/servicel.yml file, I need to set the cookie lifetime to their maximum allowed value. I have searched the internet, but I can't seem to find the maximum allowed value. Is there one? Currently it is set to:

# Set session lifetime (in seconds), i.e. the time from the user's last
# visit to the active session may be deleted by the session garbage
# colle ...
Score: 1
Eldad Shalhevet avatar
How to calculate a field in webform?
br flag

We recently implemented a site on the Drupal environment.

We make considerable use of the amazing Webform system. However, we encountered a need for which we did not see a solution in the existing elements in the Webform.

We need an element that can perform a simple calculation (+ - * /) between other numerical fields and\or pre-set numbers as we choose. So that the person filling out the form will  ...

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.