Latest Drupal related questions

Score: 0
Tyrone M. avatar
Set value in a choices.js dropdown after it's been created
gf flag

Using Drupal 9.4 and choices.js 10.2 (design required a highly styled dropdown that I couldn't do with a standard element). The choices dropdown is created by a view.

When I had the plain select item in place, I could use javascript to set an optional default value for one of the two dropdowns. However, with the choices.js dropdown, I haven't found a simple way to make that happen despite scouring the ...

Score: 2
Prizem avatar
What's the point of using Webform Node instead of directly using a Webform's form?
ga flag

What's the point of using Webform Node instead of directly using a Webform's form?

I have tried both. I see that submissions on a node are not exactly the same as submissions on the direct form, so there's a potential for submissions to get split. If I want people to use the node, but someone finds the direct form, then that can be confusing for people needing to review all submissions.

Is it ok to  ...

Score: 1
Menno van den Heuvel avatar
Views UI javascript is broken
cn flag

I discovered today that the Views UI is broken on one my sites. I'm not sure when it broke, because the Views UI is not one of the things I check after updates. I'm currently at 9.5.3.

My Views UI logs the error "Uncaught ReferenceError: assignment to undeclared variable loadjs", and follows up with a bunch of other errors that I assume stem from the first one.

When I disable JS aggregation the issu ...

Score: -1
How to remove author field from the 'advanced' field group on the node edit form
pe flag

I've got several node edit forms that, in most themes, display the 'advanced' group in a sidebar. I have other plans for the sidebar, though, so I don't want that behavior. I edited some twig and css to make the advanced group appear below the main form, but this is still pretty messy. In particular, we often have to adjust the author field, and I'd like it at the top all by its lovely self... not burie ...

Score: 2
smooresonetrics avatar
Token button missing from CKEditor 5 bar
gp flag

I've recently started using CKEditor 5 on a new site. I've enabled the Token and Token Filter modules, and checked the box on my Full Text format config screen to select 'Replaces global and entity tokens with their values'.

The editor does in fact respect tokens, but there's no button to insert one or select from the available ones, as there was in CKE4. (I had to go find the one I wanted from / ...

Score: 1
rpayanm avatar
Edit index config (Search API) programmatically and get the status index updated
ru flag

I have a site with 14 pieces of news and 44 basic pages.

  1. I have created an index (Search API) with this bundle: enter image description here

and this is the index status (the content is already indexed during cron): enter image description here

  1. When I edit the config, add the Basic page bundle and save it: enter image description here

The index status is updated: enter image description here

I want to do the part 2 programmatically. I tried two ways:

$index = Index::load('my_index');
$index->setOption('datas ...
Score: 0
Jipi avatar
Use exposed filter "Has taxonomy term (with depth)" for a specific field and not the all the content
cn flag

My content type has 2 fields related to the same hierarchical taxonomy.

How can I expose a view filter that allows a search "with depth" on only one of these fields and not on all the content? Is that possible on D10 ?

For the moment, I can only expose a filter that takes into account this taxonomy on the whole content (i.e. the 2 fields together...)

This issue is a perfect example of my case : ht ...

Score: 0
gMaximus avatar
How to add some content every Nth comment?
sa flag

My use is case is that I wish to show an advert every 3rd comment.

The forum module added the comment field to the forum content type. So the field name is comment_forum.

I have a block that contains the embed code for the ads. Using twig_tweak module to render that block in my template using {{ drupal_entity('block_content', '5') }}

I then created a template file called field--comment-forum.html.twig ...

Score: 0
Custom Media type token for specific field
do flag

I have a custom Media type - gallery_image and it has a couple of extra fields, including field_caption. (Drupal 9)

Do replacement tokens for custom Media type fields get generated automatically, or do I have to create one?

I want to pass the token to a colorbox overlay as the preferred caption field.

Score: 0
How to check for content type in hook_form_alter
pe flag

I see from the api and various posts that I can identify a specific form to change using hook_form_alter, like this: hook_form_FORM_ID_alter()

From experience, I know this can be done in the .theme file along these lines...

function MYTHEME_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  if($form_id == 'node_pm_form' || $form_id == 'FORMIDHERE') {
    $form['acti ...
Score: 0
How to get the true client IP when a reverse proxy sets the value in a custom header rather than in X-Forwarded-For (HTTP_X_FORWARDED_FOR)
hk flag

I was working with a Drupal site that sits behind a load balancer and a varnish cache - 2 proxies. The true client IP is not present in the X-Forwarded-For header ($_SERVER['HTTP_X_FORWARDED_FOR') but is present in $_SERVER['HTTP_X_REAL_IP']

The IP that Drupal detects is interestingly from some hostname lookup and not present in any of the $_SERVER variables.

I don't have control over the infrastr ...

Score: 2
Abhi Das avatar
How to handle batch operations when the user machine gets into suspended mode?
sy flag

I'm importing a large dataset into the database using the BatchBuilder in Drupal. It takes more than one and a half hours to complete all the operations in the batch. The process starts with user action on a page, and the progress of the batch operation is shown to the user. We are facing an error on the batch process if there's a connectivity issue on the user side. For example, if the user started the ...

Score: 0
seutje avatar
Apply or expose a filter based on the value of a field in a referenced entity
rs flag

I have a search_api SOLR view of downloads on path /downloads that filters on current language and has a contextual filter on category so /downloads/foo shows downloads that have the category "foo" and /downloads/bar shows downloads with the category "bar".

I want to make it so I can have certain categories not filter on current language and instead show downloads of all languages and expose the  ...

Score: 1
Matoeil avatar
Why precisely the twig raw filter is unsecure?
za flag

Why precisely the twig raw filter is insecure in the drupal context?

What would be an example of a potential threat ?

And what need to be done on the ckeditor field format side to protect potential malicious code, if the raw filter is used ?

Score: 0
Double click action in CKEditor 4?
in flag

I have D9.5 site with CKEditor 4 and media library module. In CKEditor, when I double click on some existing media I get popup to select new media to replace clicked one. After selecting new visually new one replaces old one. Old is not visible any more, but it's still there. I.e. if I click "Source" button I can see both in source. If I switch back to visual mode both are shown. Is this some kind of bu ...

Score: 1
Matoeil avatar
is there a twig filter to correct the HTML?
za flag

the slice filter on html code can generate invalid html that can cause in cascade JS errors

 {% set text = paragraph.field_verbatim_text.value %}
 {% if text|striptags|length > 300 %}
    {{ text|slice(0, 310)|raw }} [&hellip;]<a class="verbatim__suite" aria-label="{{ 'Read the full text'|t }}"
                                                       href="#verbatim-{{ paragraph.id() }}"
   ...
Score: 1
Notd avatar
List of fields to put on a REST call
tk flag

I have a rest resource configured from Rest UI page (let's say /entity/user: POST); I would like to share the endpoint with others devs so they can call the API (create users for e.g.). Where to get the list of fields to put on request body? also their structure (value or target_id..)?

Do you know a contrib module like this one that did the job for D7? https://www.drupal.org/project/rest_api_doc

Is the ...

Score: 0
How can I remove test directories when deploying?
cn flag

When deploying Drupal, there are a lot of files in test directories, none of which are needed in a production environment. There's an ongoing issue to Exclude test files from release packages, but how can I get rid of the test files now?

Score: 1
fclose only creates file at script end when running drush command
cn flag

I'm really struggling with Drupal php memory/file/cache management. I've tried a lot of different ways to avoid memory errors (php 8.1) when writing a multi-megabyte file out. My observation is even though I've tried fflush() and fclose() on a file in previous attempts, the file only gets created at script end, not when I tell the script to create the file. I understand that file open/close is one of th ...

Score: 0
onNotify called 3 times on error returned
kn flag

I'm using the OffsetRedirect.php file to handle the return of my bank when the user pay his order.

Inside this file, i use the onNotify() method

  public function onNotify(Request $request)
  {
    $erreur = $request->get('error');
    $response = NULL;
    //check some logic
    if ($erreur === '00000') {
      //create payment
    } else {
      $erreur_paiement_route = Url::fromRoute('mycommerce.on_ ...
Score: 1
Vitaliy K avatar
How do I debug A block ajax issue on a custom theme?
tr flag

I'm receiving and ERROR " An error occurred while attempting to process /views/ajax?_wrapper_format=drupal_ajax: ajax.$form.ajaxSubmit is not a function" when clicking on link in views block on exposed form using the taxonomy terms and better exposed filters. enter image description here

I have tried already attach the views.ajax library to the exposed filter form. it not sorted the issue. Js aggregation also turned off.

I'm using B ...

Score: 0
Sudha avatar
Why my custom module configuration are not getting created on module install?
sj flag

I have created one custom module with config/install folder. This install folder contain content type yml. Basically on install of custom module new content type should be created. When I use drush en my_custom_module, all configuration are getting imported successfully. But when I do drush cim only module is installed but configuration(mycustommodule/config/install) are missing. Do we need to do any ch ...

Score: 0
Jake13 avatar
Format telephone numbers for values
us flag

I have created a webform with telephone field, the submitted data is displayed in a views table, however the numbers in submitted data are in random format such as 1234567890, 234-987-9870, how do I configure the number field in views to be displayed in (123) 123 1234 format for the existing values and new submission.

Score: 1
Search API Facets: Filtered Results to Map (Leaflet) Shows No Updates to Views Page
ky flag

When using post search results via a Search API Facets for node data, the initial results are displayed as a map content type (Leaflet) but when filtering down to further fields, the results page shows empty (or as set to visitor/location as set in Leaflet style settings in the corresponding View). Ajax is set in Views options. The Facets, Views pane are set within a Panel Page. The paths show initial c ...

Score: 0
Improve performance migration
br flag

I have a custom migration like this

<?php

namespace Drupal\my_import\Plugin\migrate\source;

use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Row;
use Drupal\migrate_source_csv\Plugin\migrate\source\CSV;

/**
 * Extend CSV source.
 *
 * @MigrateSource(
 *   id = "my_source_csv",
 *   source_module = "my_import"
 * )
 */
class MySourceCSV extends CSV {

  /**
   * {@inheritdoc}
  ...
Score: 0
Thomas Tsita avatar
eCommerce Products Permissions per Node
ec flag

Good day

We are building an eCommerce Platform where multiple users can be able to register, login, create, edit and delete their Profiles and Products.

The main feature is to have each user to only have access to their Products, under eCommerce.

So, the challenge is that all users are able to add, edit, update and delete all products created by all users, even when the permissions are set for each use ...

Score: 5
Monkeybrain avatar
How do I import a sync config file into my Kernel unit test?
in flag

How do I import a sync config file into my Kernel unit test ?

Specifically, I have some REST resources in files config/sync/rest.resource.foo.yml,config/sync/rest.resource.bar.yml

At present, when I run \Drupal::service('router.builder')->rebuild() in my setUp() function, it does not add in the routes for these resources, so when I make GET requests to them in the tests, I get 404.

I don't want to ...

Score: 0
divspan avatar
New pages not included in main navigation but display in sidebar
fm flag

I have recently inherited this website and was made aware of an issue where new pages that are added to the main navigation are only displaying in the sidebar. I have followed the steps for adding pages to the main navigation, but have been unsuccessful. I have also attempted to add a page that I created myself, but it only appears in the sidebar and not in the main navigation. I have cleared the cache  ...

Score: 2
ShadowAce avatar
How to duplicate/clone a field in a content type
kp flag

I have a custom content type with an image field. I want to convert this image field into media type. There are already thousands of nodes created with this content type.

One of the ways I've identified is to use the image field to media module. However this creates a clone of the image field. All the twig files and db instances will continue to use the image field.

What I'm trying to do now is to c ...

Score: 0
Cannot apply patch; file not found
br flag

There is a specialized fix to a contrib theme that I am trying to apply. Because this theme is in the .gitignore file, it's incumbent upon me to generate a patch that composer can include. Please note that the dependency "cweagans/composer-patches" is required. Pantheon is using the composer.lock file and I cannot get composer update to find the target file. I built the patch file using diff and modi ...

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.