Latest Drupal related questions

Score: -1
BrandenB171 avatar
How do you break up a .module file?
au flag

I have a .module file that is nearly 1000 lines long. I have functions that i want to reuse from form submission in a cron job. What is the best way to abstract that to a better file?

Score: 1
quantumized avatar
How can we limit the end date selection to +90 days from now on core Date Range widget?
ng flag

We're using Drupal 9's core Date Range module and need to limit the end date selection to no more than 90 days from today.

I've searched far and wide and have not come up with a workable solution. Seems like it should be simple but I'm stumped.

enter image description here

Score: 0
jayaprakash R avatar
Modules are not updating to the latest version
pk flag

I have some websites in the drupal. I need to update the security modules in the old version to the latest version. The list of security modules I tried to attempt is as below

1)colorbox (current - v2.15, updated version - v2.17)

2)colorbox_node (current - v3.5, updated version - v3.8)

3)link (current - not sure, updated v1.11)

4)wysiwyg (current - v2.6, updated v2.9)

currently using drupal v7.78

Score: -4
Interlated avatar
How do I render a radio inside a label?
km flag

The drulma theme has a form-element--type--radio.html.twig template file that is rendering the radio input and then the label.

<div class="control js-form-item form-item js-form-type-radio form-item-age-bracket js-form-item-age-bracket">
  <input data-drupal-selector="edit-age-bracket-12-25" class="visually-hidden 
    form-radio is-link radio" type="radio" id="edit-age-bracket-12-25"
    n ...
Score: 1
Menno van den Heuvel avatar
Get Submission ID in ajax_callback hook / after submitAjaxForm
cn flag

I'm looking to dig up the submission ID in code that I execute in the ajax_callback hook. My code looks approximately like this:

function webform_to_datalayer_ajax_callback(&$form, FormStateInterface $form_state) {

  /** @var \Drupal\webform\WebformSubmissionForm $form_object */
  $form_object = $form_state->getFormObject();

  if ($form_state->hasAnyErrors()) {
    $response = $form_obj ...
Score: 2
Diatherm Condole avatar
Why is MethodNotAllowedException thrown when an image is uploaded with CKEditor 5?
in flag

After updating Drupal to 9.5.3, I had this warning: Deprecated modules found: CKEditor.
So I upgraded from CKEditor to CKEditor 5 following this documentation.
After some setup on text formats, I made some tests creating a basic page.
When I try to insert one image using CKEditor button, the image appears and immediately I get an error message saying Couldn't upload file: enter image description here After validating the mess ...

Score: 0
Inserting tags into plain text fields
do flag

I've been given a content type with content already populated.

There are a number of headings/title fields in the content type and I have been asked to style a sub-section of those fields.

ie:

<h1>Title for your local service is styled</h1>

has to become:

<h1>Title for your <span class="myclass">local service</span> is styled</h1>

or something like that.

Is there ...

Score: 0
JM John avatar
Initial server response time for different cached pages
mz flag

I have been trying to speed up a Drupal site and measuring speed through page speed insight. What really has puzzled me for last few weeks of experiments is that node pages score an average of 170-200ms on 'initial server response time' while taxonomy pages (which are far more important from SEO speed point of time) take an average of 720-750ms in terms of initial page response time.

(Drupal 7, N ...

Score: 0
tonytheferg avatar
Programatically sort a merged view by a row value
cn flag

I am using the following hook_views_pre_render to merge 2 views_data_export views.

function hook_views_pre_render(ViewExecutable $view) {
  if ($view->id() == 'commerce_orders' && $view->current_display == 'data_export_1') {
    $first_extra_results_view = Views::getView('commerce_orders');
    $first_extra_results_view->setDisplay('data_export_2');
    $first_extra_results_view->execu ...
Score: 0
guest avatar
Form tries to process submit field as entity property
fk flag

I want to create a simple admin CRUD form. I am using the default form.

class TestForm extends EntityForm {

  public function form(array $form, FormStateInterface $form_state) {
    $entity = $this->entity;
    $form['name'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Name'),
      '#default_value' => $entity->get('name')->getString(),
      '#size' => 30,
  ...
Score: 0
mogio avatar
Headless and custom node / entity access
cn flag

I struggle to set up custom access rules for "nodes" that are viewed via the

  • jsonApi
  • entityQueries which response via json endpoint

What I try to achieve:

  1. I need to skip a node, that belongs to an authors user account that is not within running subscription. (the state if a user has a valid subscription is defined by a date value ... so if field_date_subscription_ends is < "now" = "false").

     ...
Score: 0
Rob Carr avatar
Attribute Array to String Conversion Error
us flag

I'm getting this error now on most pages within a complex 9.5.3 site running PHP8.1:

Array to string conversion in Drupal\Core\Template\AttributeArray->__toString() (line 77 of core/lib/Drupal/Core/Template/AttributeArray.php)

The error trace isn't really helping nail this down. Using the suggestion at AttributeArray fails to implode #allowed_tags to investigate the problem attribute arrays, ma ...

Score: 0
Chris avatar
Keep page published or unpublish?
tg flag

Such a simple question I'm sure, but I can't find anything anywhere on this. I ran lots of tests - if the page is deleted the redirect doesn't work, but whether I unnpublish or keep the page published the redirects work ok. (For the main URL, the node and any alias) Not sure whether this is expected behaviour, or maybe a cacheing issue....?

So I guess my question is - which is best practice/likel ...

Score: 0
Quetzcodecoatl avatar
Trying to create a cell when using tables in forms
tw flag

In one of my custom Drupal modules I'm trying to crate a form that also contains a table. One of the table sections looks like the following:

$form['consumption_' . $week]['mood']['title'] = array(
  '#markup' => $this->t('Mood'),
);

for ($i = 0; $i <= 6; $i++) {
  $options = array(
    '1' => t('choice 1'),
    '2' => t('choice 2'),
    '3' => t('choice 3'),
    '4' => t('cho ...
Score: -1
drupaltest avatar
Passing variables to template rendering
lr flag

I want to render "file-video.html.twig" template.

This is the documentation: https://api.drupal.org/api/drupal/core%21modules%21file%21templates%21file-video.html.twig/9.3.x

This is my code:

 return [
                        '#theme' => 'file_video',
                        '#attributes' => ['TEST ATTR'],
                        '#files' => [
                            [
                     ...
Score: 0
Kevin avatar
What is the backend_overridable service tag usable for?
in flag

On some core services, I see they have a tag of backend_overridable. I see this changelog, but is there an example?

https://www.drupal.org/node/2306083

Is that essentially what something like Memcache is doing?

$settings['cache']['default'] = 'cache.backend.memcache';
Score: 1
Binary Alchemist avatar
View of Node revisions exclude first revision of each node
in flag

I have a view of Node revisions. I want to only show revisions that are edits. I want to exclude the first revision of each node.

I think filtering for created <> changed would work, but I could find a filter in views, or a contrib module that does this.

Is there a way to do this without writing a custom view filter plugin?

Score: 1
Alejandro avatar
How can I modify/edit/change the media video controls?
fj flag

I was wondering how could I modify the controls from a media video. In my particular case, I want to remove the "Download" button from the controls, see: Screenshot of a video player with the control options opened

Score: 0
user14409370 avatar
how to create commerce product attributes which gets it's values from a view
nr flag

I want to fill the product attributes select list with data like:

location1 location2 location3

These locations are general and gathered using a custom module. In views I can create a list with these values, but I'm unable to use them as attributes.

Score: 0
How to get the parameters from a URL and a route that is not the current one?
mx flag
JFK

Route from a custom module :

custom.route:
  path: /the/{id}/path

Hypothetical url : /the/53/path

The goal is the get the id value ("53").


So far, I managed to get the route name from the url with

$url = "/the/53/path";

$route_provider = \Drupal::service('router.route_provider');
$found_routes = $route_provider->getRoutesByPattern($url);

In $found_routes, I can find the "custom.route" route na ...

Score: 3
Notd avatar
How to get the current running Drush command?
tk flag

I would like to detect from code the current running drush command. I have some hooks that will be run when I exec some drush commands and want to detect which command is triggering the hook.

I manage to get the info from input() but I want to know if there is a more appropriate way:

  if (PHP_SAPI === 'cli') {
    $command = \Drush\Drush::input()->getArguments()
  }

I would like to have something sim ...

Score: 2
Victor Núñez avatar
I am trying to add a simple pager to my controller, I have managed to get the row limit (5) to be printed but not to see the next or the previous
no flag
<?php

namespace Drupal\drupal_block\Controller;


use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Database\Connection;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Database\Query\PagerSelectExtender;

class DrupalBlockController extends ControllerBase {
  protected $connection;

  public function __construct(Connection $connection) {
      $this->connecti ...
Score: 0
Pin avatar
Change icon style by field value in Leaflet map view
cn flag
Pin

I would like to have different color markers depending on a field value in a Leaflet Map view.

I try to use Replacements Patterns in format > style options > Map Icon:

enter image description here

but I get a "not valid json format" error. What I'm missing? (I know this is possible with OpenLayers module, creating different layers, but not possible to change to it now).

Score: 0
Can a Rules action send an email to all users that have set a flag?
pe flag

I've found some older Drupal 7 info on this, but not much for Drupal 8+ yet. What I want to do:

  • Give users the ability to set a 'notify me' flag on nodes
  • When a comment is added to the flagged node, all users who have flagged it get an email notification

So far...

  • I have the rule set up correctly to allow users in role x to set the flag. It has another action on it that is tested and working.
  • I  ...
Score: 0
rfmarcelino avatar
Add a text field value with AJAX
cn flag

Problem: After an AJAX callback, the text is not inserted in the body field.

Description: I created a fresh Drupal installation. Added a field 'Type' | field_type | List (text) to the Article CT. The goal was that a change in that select would add text to the body field. Here's the ajax_test.module code, inspired by the documentation:


use Drupal\Core\Form\FormStateInterface;

/**
 * Implements hook ...
Score: 0
A-WRI avatar
How can one use the value of one field to enforce a minimum value on another field?
pl flag

I'm making a registration form for an event that will have a "sliding scale" fee system, but with minimum contributions based on the size of their organisation.

I want users to be able to set the size of the organisation that is paying their fee (from very small/volunteer led up to very large, well funded organisations) via radio buttons, and then to choose their contribution using a slider. Idea ...

Score: 0
tcnolan7 avatar
How to compare node and node_unchanged field values in Drupal 8 Rules?
mo flag

I'm trying to compare the value of a custom field, the unchanged value and the saved value.

Basically... if myfield value was "Not Started" and if myfield value after updating the node is "Pending" then send an email to the node author

The event is "After updating a content item of type". I add a condition for "Entity is of Bundle" and a condition Data Comparison with the specific field and value I ...

Score: 2
gzwg avatar
How can I check with if my site is running?
cx flag

Is there a way with Drush or something else to check if a specified Drupal site is still up and running, means fully normal functioning, after automated maintenance/updating in an external script?

Sometimes an update can fail in a script and then there is a none-functional site left. I want to detect that situation. So have a command and the output is the status of the site? E.g.

drush <command> ...
Score: 0
Font style isn't applied on PDF (entity print)
kn flag

I'm using Entity print with my webforms. I've followed those steps https://www.drupal.org/node/2706755 to add the css into my PDF.

My classes are applied (color, padding...), but for some reason, the fonts are never applied on the generated PDF, but is applied on the debug : https://.../print/pdf/webform_submission/10/debug

Font are not applied with CDN @import url('https://fonts.cdnfonts.com/css/apho ...

Score: 1
MSNOP avatar
How to add groupBy option WITH ROLLUP
so flag

With Drupal 9.5.3, a group by like this:

$query->groupBy("myfieldname WITH ROLLUP");

will result in

(...) Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'myfieldnameWITHROLLUP' (...)

... since spaces are stripped.

Is there any other proper way to add the "WITH ROLLUP"?

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.