Latest Drupal related questions

Score: -4
DrupalDev avatar
Running a custom cron job
sm flag

I'm trying to implement a newsletter subscription on Drupal 10 that will send an email to all the subscribers automatically. I work in a restrictive environment where I'm not allowed to use custom modules and the choice of modules available is pretty restrictive so I cant hook the cron job using modules. Is there anyway I can implement a cron job from scratch or hook it using the theme file. I've though ...

Score: 0
Mixed Taxable line item don't work
us flag

I have a cart with 1 x Food (non taxable) 1 x Electronic (taxable)

Currently both items are being taxed.

I need the GST and QST to only tax the taxable items.

What is the proper setup?

Score: 1
Smartsheet eng avatar
Adding a class to a URL object
um flag
function mytheme_preprocess_menu_local_tasks(&$variables) {
  if (!empty($variables["primary"]["entity.node.edit_form"]["#link"]["url"])) {
    $url = $variables["primary"]["entity.node.edit_form"]["#link"]["url"];
    assert($url instanceof Url);
    $nid = $url->getRouteParameters()['node'];
    $node = Node::load($nid);
    if (_mytheme_some_condition($node)) {
      $attributes = (array ...
Score: 0
gillarf avatar
What is the order item view path?
us flag

I need to allow admins to print off individual order items (line items) that relate to a specific product, and allow them to print off the order item using Entity Print. the order item has customised data in it that they need to print off.

However, I cannot work out what the path to view the entity is. I tried /commerce_order_item/{id}, /commerce_order_item/bundle/{id} and variations, but to no a ...

Score: 1
Views Data Export: Plaintext field contains HTML entities
cn flag

I have a CSV export which is done by the "views_data_export" module. When exporting, a plain text field which contains a double quote ends up with a " HTML entitity in the CSV file. This doesn't make sense, and when Im importing this file, this leads to problems.

I'm actually working with Drupal 9.5.10 and different entities, but was able to reproduce this with a fresh Drupal 10.1 installation. I ...

Score: 1
CJ Catalano avatar
How do I parse a path alias?
xk flag

I have the following code in my page.tpl.php file.

<?php $path = drupal_get_path_alias($_GET['q']); ?>
<?php if ($path == 'about-us'): ?>
  <div class="container">
    <h1> about us!!!!</h1> 
  </div>
<?php endif; ?> 

This works for /about-us, but not for /about-us/abc.

What code would work for all the paths under /about-us?

I've messed around with arg()

Score: 0
Mira chalak avatar
How can I add a custom field?
eg flag

I am using layout paragraph module. I have a "section" paragraph with the layout paragraph behaviour. I want to add a field Background color to the section.

Should I add it inside the layout configuration form in the same way https://www.drupal.org/docs/drupal-apis/layout-api/how-to-register-layouts adds a textfield, or should I add the background color field to the "section" paragraph?

Score: 1
Ravi avatar
Show the Quantity field on the product page but hide it on the catalog page
sa flag

I created an "ABC Book" product, whose URL is https://example.com/product/1. I added the Quantity field from Administration > Commerce > Configuration > Order item types > Default > Manage form display > Add to cart.

The field appears on the product details page (https://example.com/product/1).

I created a view to display all products on a page (https://example.com/shop). The fiel ...

Score: 1
Show all attributes
us flag

I need All my attributes to display on the page. Like this: https://www.lowa.ca/fr/produit/renegade-gtx-mid/

So if you select a color, you still see all sizes. With their availability Also if you select a size, the available colors are available to click for that size.

Do you have any clue on implementing this on Commerce 8.x.2.36?

Score: -3
Reddy Rohit avatar
How can I embed PHP code in HTML?
ml flag

I want to execute few curl commands from my Drupal site using PHP.

Idea is to create a custom content type that accepts php code. I understood from the internet I have to create a file "node--page.tpl.php" and add the below code in this file.

  1. Will this actually work?
  2. If yes, at which path should I place node--page.tpl.php file?

Code:

<!DOCTYPE html>
<html lang="en">
<head>
     ...
Score: 0
Ryan Schwab avatar
Composer.lock does not match project versions
pl flag

I have a drupal site developed using the core-recommended project, and I maintain the site using the recommended practices on drupal.org.

Recently after adding a new developer to the project, Composer is now showing the wrong versions of modules and not updating them.

For example, with the Font Awesome module:

  1. Composer.lock shows version 2.26 is installed.
  2. composer info drupal/fontawesome shows 2.26 a ...
Score: 0
Mohcine Achak avatar
I see some weid WordPress urls in my "Recent log messages", but i am using drupal
tr flag

Lately i am having an issue with Drupal, i don't know how to solve it, i get too many "page not found" errors, but when i check the log, i found out that all of those URLs are Wordpress URLs, as you may see the in attached images.

What could be the issue?

wordpress urls

Score: 0
Victor Pudeyev avatar
Why does content disappear for logged in users?
mm flag

I have two examples of this. One, I'm using the Umami demo profile, and the pre-header language selector disappears for the logged-in user. I would like the language selector to be visible at all times.

Two, I created a view that shows published articles tagged (1) current issue, (2) sketches. This view works as intended for anonymous users, but the view renders nothing for logged-in users.

enter image description here

What s ...

Score: 0
Charlie Boy avatar
MSSQL - How to get a list of documents from a node that is using a space and a view?
gp flag

I have a list of documents that are associated with a node of type space. The space has a page with a view and filter to list documents only related to that node.

I'm trying to query the database to get just that list of documents from the files table. FilesTable

My question is when Views are involved with spaces how can i retrieve that list from the database?

Appreciate any insights!

Score: 0
asma supih avatar
how to update metatags using metatag_manager?
pl flag

I have drupal 10 installation, I am trying to update robots metatag for old articles/pages, I am writing an update_hook .

I found this really clean way to get the metatags parameters :

$metatag_manager = \Drupal::service('metatag.manager');

First, get the tags from the entity (usually from a node):

$tags = $metatag_manager->tagsFromEntityWithDefaults($node);

and then generate the meta tag values:

Score: 1
Rene avatar
Paragraph Entity Query returns too many results
cn flag

I'm trying to find a paragraph that have a certain taxonomy term value and on a matching parent node. I tried the code below, but it always returns over 30 values, when really only one paragraph entity is possible. Not sure what I'm missing.

$query = \Drupal::entityQuery('paragraph')
    ->condition('status', 1)
    ->condition('type', 'player_assignment')
    ->condition('field_year_seaso ...
Score: 0
Tercio Lacerda avatar
How to assign a paragraph to a node correctly?
tf flag

I'm currently facing an issue while trying to link paragraphs to a content type in a newer version of Drupal. I have data from an older Drupal website that I need to migrate to a more updated Drupal version. I'm using the JSON:API to achieve this, but I'm encountering problems in associating paragraphs with a specific field in the content type.

Here's an overview of the process and the code invol ...

Score: 1
Mahesh Gudapakkam avatar
Fatal error: concerning DrushStyle::warning not being compatible with SymfonyStyle::warning
ng flag

I just upgraded our site from Drupal 9.5.9 to Drupal 10.1 (following instructions from here - https://www.drupal.org/docs/upgrading-drupal/upgrading-from-drupal-8-or-later/upgrading-a-composer-based-site).

Upon launching the site right after I received these errors

The website encountered an unexpected error. Please try again later.

Drupal\Component\Plugin\Exception\PluginNotFoundException: The "node_typ ...
Score: 0
Tasneem avatar
How to change the default database driver to the SQLite option in profile installation?
br flag

I have two database driver options in the "database setup" step while installing a Drupal project from a custom profile. By default, the MySQL database is selected.

enter image description here

But I want it to choose SQLite database as default, like this:

enter image description here

How can I do that in my custom profile?

Score: -1
Ali Rizvi avatar
Can not get the module by composer
cn flag

My Drupal Version is 9.5.10 PHP Version 8.1.18 I am trying to get the module: composer require 'drupal/rocket_chat:^3.0'

But unsuccessful: Problem 1

  • Root composer.json requires drupal/rocket_chat, it could not be found in any version, there may be a typo in the package name.

composer.josn

    "name": "drupal/recommended-project",
    "description": "Project template for Drupal 9 projects with a reloca ...
Score: 1
Override contrib module's template for an admin module
us flag

I need to override a contrib module's template for an admin module. For example, the webform_composite module has hook_theme() in its module file.

/**
 * Implements hook_theme().
 */
function webform_composite_theme() {
  return [
    'webform_composite' => [
      'render element' => 'element',
    ],
  ];
}

and a template in its templates folder at

modules/contrib/webform_composite/templates/ ...
Score: 0
Baud avatar
How to fire the autocomplete after input reach 3 characters
sa flag

I am setting a view for the autocomplete feature of a widget with the following code:

function my_module_field_widget_entity_reference_autocomplete_form_alter(&$element, FormStateInterface $form_state, $context)
{
  $field_name = $context['items']->getName();
  if ($field_name == 'my_field_name') {
    $element['target_id']['#selection_handler'] = 'views';
    $element['target_id']['#selecti ...
Score: 1
Vanish avatar
Hide field programmatically in "manage display"
hm flag

I develop a contrib module. I added a new field to "user" entity. I need to hide this field from display in "manage display"

I run this code

$entity_view_display = \Drupal::entityTypeManager()
  ->getStorage('entity_view_display')
  ->load('user.user.default');
if ($entity_view_display) {
  $entity_view_display->setComponent('field_myfield', [
    'region' => 'hidden',
  ])->save();
}
Score: -1
Sukanya Sathyan avatar
Using common database for multiple developers in local environment gets slow
id flag

When use the common database to develop in local environment for multiple developers in one Drupal 9 project is getting too slow. This issue occurs on Drupal sites only, others (Wordpress, Laravel, Codeigniter and slim) are working fine with the same database from the server and found that not an network and server issue. In our scenario, we want to use a common database for multiple developers in our  ...

Score: 0
Andrés Chandía avatar
How to avoid converting URLs to links?
cn flag

Using CKeditor5 in Drupal site... is there a way to avoid converting a specific URL to link in a specific page or paragraph? How?

Update: explanation

I have a paragraph where I give the bibtex to copy; one of the entries of the bibtex is an url which has to be presented like in this picture: enter image description here

But CKeditor5 presents it this way:

howpublished = {\href{<a href="http://www.chandia.net/corlexim"&gt ...
Score: 1
David Barrett avatar
Can the Webform Table Element row span 2 cells
jp flag

I created a webform and added a table element as per the information from Webform Composites vs. Tables | Jacob Rockowitz

My table has 4 columns & 14 rows. The bottom 3 rows will only have 3 cells. I need to column span the 1st cell to span 2 columns on these 3 rows. As shown in the image below.

I believe the table is built using the twig template from the table.html.twig file in my custom theme.  ...

Score: 0
in hook_views_pre_render, how to get the current display of the ViewExecutable
ca flag

I have this code:

function my_module_views_pre_render(\Drupal\views\ViewExecutable $view) {
  if (isset($view) && $view->storage->id() == 'myview') {
    // Do something.
  }
}

This runs my code for all displays of my view, hoever, if I have page_1 and page_2 displays, and I only want to pre-render page_2, I can't figure it out:

I am looking for something like this:

function my_module_ ...
Score: 0
Why am I getting "Page not found" for a simple "hello world" custom page
br flag

In my custom module, ed_helper, I have this ed_helper.routing.yml:

ed_helper.my_page:
  path: '/mypage/page'
  defaults:
    _controller: '\Drupal\ed_helper\Controller\EdHelperController::myPage'
    _title: 'My first page in D8'
  requirements:
    _permission: 'access content'

In ed_helper/src/Controller, I have this EdHelperController.php:

<?php
namespace Drupal\ed_helper\Controller;

use D ...
Score: -2
shubham jain avatar
How can I override the emulsify libraries in a .theme file?
tk flag

I want to override the emulsify libraries in a .theme file.

I have used all the default theme hooks in the theme file, but they do not work. The following code work in a custom module.

function custom_module_system_info_alter(array &$info, Extension $file, $type) {
  $namespaces = [
    'base' => '00-base',
    'atoms' => '01-atoms',
    'molecules' => '02-molecules',
    'organisms' =>  ...
Score: 0
cossinner avatar
Why should a Drupal copy be extracted in the web directory?
gg flag

I am trying to create a multi-site using Set up a multisite, but I do not understand the reason for step 1.2.

Why should a Drupal copy be extracted in the web directory?

There doesn't seem to be anything written about this.

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.