Latest Drupal related questions

Score: 0
Giuseppe avatar
Specific CORS on a custom form POST request
br flag

I'm on D 9.3.x

I have a custom form, e.g.

my_module.my_form:
  path: 'custom-form-end-point'
  defaults:
    _title: 'Custom Form'
    _form: 'Drupal\my_module\Form\MyFormController'
  requirements:
    _access: 'TRUE'

This form is POSTED from an Android app inside a self-hosting html page - so from outside the site server and Drupal, e.g.

<form id="myform" action="https://mysite.com/custom-form-end-p ...
Score: 0
Qaiser iqbal avatar
Render OneAll social login block in a .php file?
ml flag

I am using OneAll social login module for social registration and login. The module's login block works well on any page but not on a .php file. I am trying to render the block in a xyz.php file programmatically. When I try to render it via the following code I only gets The heading text of the block without the Facebook and Google's links.

$blockObject = block_load('social_login_widget', 'social_log ...
Score: 0
abe-cedarian avatar
I need help migrating a mulit-value link field from string w/ 2 delimiters
kr flag

I'm trying to migrate a node bundle from one drupal 9 application to another.

My source format is an XML document.

I'm stuck migrating a multi-value link field.

Both the source and destination machine names are field_quicklinks.

The source value is a string with two delimiters like the following.

"https://www.somedomain.org/somewhere/something.pdf*Something Document^https://www.someotherdomain.org/so ...
Score: 1
Andrew Clemens avatar
How to subscribe to a view render event?
pn flag

I'm writing a module that will inject javascript into the page when a view is rendered. The contents of the javascript will depend on the results returned in the view, so ideally I would have access to that. I'm trying to use event subscriptions to do this. I have the getSubscribedEvents function set up but I'm trying to find a view render event to subscribe to. Is there such an event I can use?

 ...
Score: 1
Jimmyb_1991 avatar
CKEditor 5 Right to Left Support
cn flag

The CKEditor 5 docs claim that version 5 comes with Right-to-left editing out the box. While I am sure this is true, I am struggling to get it to work as such in Drupal 10's version.

I have enabled Arabic on my English-by-default site and have enabled the Language toolbar option in for the text format. While editing the Arabic translation of the site (The UI is now RTL) and have my text in the Arabic la ...

Score: -2
Colorbox and complex modals
do flag

Is it possible to make the colorbox popup take more complex content than just an image and a caption?

On a drupal 9 site I have been asked to modify a simple colorbox gallery to include a long/formatted Caption/story and a title in a responsive two-panel pop-up.

Is such a thing even possible or am I better of building something like this from scratch or with something else?

to expand on the format:

 ...
Score: 0
Statistics counter based on user role
do flag

I need to track some basic usage statistics for a subset of my authenticated user roles in Drupal 9.

Is there a way to make the core statistics counter only count node views based on user roles? The three counters it provides are all I need, I just need them to only record certain user roles.

Score: 1
Drupal Learner avatar
Focus Returns to Field With AJAX Callback
gf flag

I am attempting to complete several AJAX commands based on the value of a field in a node/add form. The commands themselves work. However,when a user is filling out the form the cursor (focus) keeps going back to the field that has the callback when another field is clicked regardless of the value of the field.

In this given case we are trying to see if someone is 64.5 years old and change the fo ...

Score: -3
JM John avatar
Advagg Bundler would NOT spit out same size CSS bundles
mz flag

Trying to make sure Advagg bundler spits out two equal size CSS bundles as it makes a massive difference in initial server response time.

For some reason, Advagg will split files into 2 bundles (first one 4kb and second one 36kb).

On Dev server, it works perfectly with same settings. Both identical systems.

I have tried uninstalling/re-installing a few times with no luck.

On production site, it shows 88 g ...

Score: 0
Check if a value has changed
cn flag

Is it possible to check within a constraint validation if a field value has changed?


namespace Drupal\example\Plugin\Validation\Constraint;

use Drupal\Core\Entity\EntityPublishedInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;

/**
 * Validates the OverriddenButChanged constraint.
 */
class OverriddenButChangedValidator extends ConstraintVa ...
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_ ...

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.