Latest Drupal related questions

Score: 0
Change paragraph object for rendering
mx flag

I have a paragraph type with a node ref field that, if you leave it empty, is supposed to show a random node using some defined logic.

I have the code to do the query and get the node, and ideally I'd want to put it on the paragraph object in some pre-render hook so that the paragraph can render normally using its usual config. Something like this (warning: pseudo-codish):

function mymodule_paragraph_ ...
Score: 0
Using migrate (also) to update nodes that already exists in Drupal
cn flag

I am in the process of porting a non Drupal database to Drupal 9. The original database contains, among other things, a table of Books (with the usual infos) and and separate table (don't ask me why) for Travel Books. The former is 10K records, and was successfully migrated from a books.csv to Drupal. The latter (travelbooks.csv) is just 200 records.

What is interesting (sic!) is that most of Travel  ...

Score: 0
stckvrw avatar
How to get node id when update a page related to menu link
gb flag

In my module I use the mymodulename_entity_update() function to listen when an entity is updated:

function mymodulename_entity_update($entity) {
    file_put_contents(__DIR__.'/test.txt', $entity->bundle());
}

When I update an article or a page which is not related to menu link, I receive 'node' as value of the ->bundle() property, as expected.

But if I update a page which is related to a  ...

Score: 0
Francisco Javier Valero Moreno avatar
Why does my JS file not get loaded?
nl flag

I am a beginner with Drupal. I want to include a JavaScript file using a custom module.

I created the .libraries.yml file, hello_world.libraries.yml.

hello_world_js:
  js:
    js/basic.js: {}
  dependencies:
    - core/jquery
    - core/drupal
    - core/drupalSettings

The module .info.yml file (hello_worl.info.yml) contains a reference to the library.

name: Hello World
type: module
description: Say Hel ...
Score: 0
Javier Rey avatar
Base fields vs Config fields?
eg flag

I have an entity and I am not sure what I should use. On the one hand, configuration fields are easier to use via the UI, why should I consider base fields?

By using base fields everything is stored in the same table, would there be any kind of performance improvement if I have many entities?

I can't find anywhere where it is explained why to opt for one or the other. Thank you very much

Score: 0
Free Radical avatar
Listing articles that matches a specific set of filter criteria
kz flag

I have a Drupal 9 site with three roles: Editor, Reviewer and Author.

I use the core Article content type, with one additional field: field_reviewer. It is an Entity Relation to the user that has been assigned the task of reviwing the Article.

Articles may be created by Editors (typically from an article submitted by an external Author), or by an Author that is already a user. Editors has full ac ...

Score: 1
RominRonin avatar
Programmatically set a views filter value on page load (not contextual filter)
in flag

I have created some views for an Events content type with field_start and field_end timestamp fields. One of the displays is for 'Upcoming Events'.

I want to filter only those events whose start date hasn't yet passed. The way to do this with the core views date filter is to choose the 'between' operator, and enter the current timestamp as the 'min' value:

enter image description here

But I obviously want the timestamp to upda ...

Score: 0
Form API States required don't seem to work on a custom form with ajax
us flag

I can't get form states required to work on an ajax submitted form.

Here is some example code. It is taken from the examples module and slightly modified to illustrate the problem.

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    // This container wil be replaced by AJAX.
    $form['container'] = [
      '#type' => 'container',
      '#at ...
Score: 0
Drupal Commerce Canada Post can't get quote
pk flag

I'm using drupal commerce Canada Post on drupal 9, the problem is when I selected shipping method an select Canada Post, there's no return the shipping quote or shipping rate option, I check the log there's an only got a warning error like below

Warning: array_filter() expects parameter 1 to be array, string given in Drupal\commerce_shipping\Plugin\Commerce\CheckoutPane\ShippingInformation->hasRateSe ...

Score: 0
Nicholas avatar
Alter a controller's render array via KernelEvents::VIEW
jp flag

I'm trying to alter a contrib module controller's output via KernelEvents::VIEW. I want to display the output from the controller and append the markup returned from the event handler. This is the code I am using, but it doesn't work as expected.

class BuildAlter implements EventSubscriberInterface {

  public function alterBuild(ViewEvent $event) {
    $build = $event->getControllerResult();
  ...
Score: 0
Add custom buttons to TinyMCE editor toolbar
cn flag

I'm trying to add a custom button to my TinyMCE editor in Wysiwyg on a Drupal 7 install.

I've managed to adapt TinyMCE settings to work in my custom module, like so:

function MYMODULE_wysiwyg_editor_settings_alter(&$settings, $context) {
  if ($context['profile']->editor == 'tinymce')
  if ($context['profile']->format == 'filtered_html') {
    $settings['browser_spellcheck'] = TRUE;
    $set ...
Score: 0
How to associated a webform with all content of a given type— retroactively?
cn flag

The way to associate a webform with all content of a given type is to use the Webform field, and then set the default value (as far as i can tell). A bit of a problem when you already have hundreds of pieces of that content. Field Defaults saves the day— except that it does not bring in the settings for the Webform field, which is essential if you are passing a value from the content to the webform  ...

Score: 0
Cannot access mysql in new docker/docksal/d9 installation
cl flag

I had a D9 installation running in MacPorts. I installed docker and docksal, copied the D9 project to the docksal project folder, and uninstalled MacPorts.

Docksal starts up like this:

Starting services...
Creating network "myproject_default" with the default driver
Starting myproject_db_1  ... done
Starting myproject_cli_1 ... done
Starting myproject_web_1 ... done
Connected vhost-proxy to "myproject ...
Score: 0
MCD avatar
The "Add to cart" button allows me to add more items to the cart than there are in the inventory
fr flag
MCD

I am trying to work on a Drupal 8 commerce site which was built by someone else. I have not used the Commerce Core module in the past.

Product variation has stock field where I enter total inventory I have. On the product page, I can still add more units to the cart than the inventory I have.

However, I get an error stating that "We do not have xx items in stock." but the item are still added to the  ...

Score: 0
How do I fix this error about a missing class?
pk flag

I'm using the Commerce Canada Post module.

The code in the src/Plugin/Commerce/ShippingMethod/CanadaPost.php file uses a CanadaPost\Rating class which isn't defined that namespace and it causes an error.

The src/Api/RatingService.php file contains the following code.

/**
 * Returns an initialized Canada Post Rating service.
 *
 * @param array $api_settings
 *   The Canada Post API settings.
 *
 * @ ...

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.