Latest Drupal related questions

Score: 0
Ivan Ginovski avatar
How to reset cache on a specific page by a given URL?
jp flag

In Drupal 7, I found a way to reset cache on a specific page with:

$url = url('<front>',  array('absolute' => TRUE));
cache_clear_all($url, 'cache_page');

What is the equivalent way in Drupal 9?

Score: 1
S.Gou avatar
Node edit form - Is it possible to load entity reference field data on click after the form has finished loading?
us flag

I have a custom node type (let's call it Project) with many fields. Three of these fields are of an Entity reference type, referencing other related nodes (let's call them Project Attachments A, B, and C).

There are sometimes hundreds of A, B, and C Project Attachments. This puts considerable load on the Project node edit form due to many DB queries being run, sometimes causing timeouts. I have a ...

Score: 1
user1470118 avatar
Programmatically add new fields to content type
jp flag

I have a custom module that has a form that allows the user to select various content types. I would like to create fields for those content types programmatically so that after the form is saved, it will add the fields for all of the content types that the user selected.

So my question is, is there a way to programmatically create fields and then save them to the content types? Any direction (tu ...

Score: 0
How to use a Controller method inside a service with dependency injection?
cn flag

I'm using the diff module for a project, this module has a method inside a Controller that I want to use in a service to reuse code. As this time I'm just calling the method like PluginRevisionController::getRevisionIds() but this give me the message:

Deprecated function: Non-static method Drupal\diff\Controller\PluginRevisionController::getRevisionIds() should not be called statically

So, I want  ...

Score: 3
Lurnobis avatar
Looping through child elements in Twig 2.10 without using if
na flag

Currently I need to loop through child elements in my Twig to render dynamic grids properly. I have achieved this by using code similar to this

{% for key, child in element if key|first != '#' %}
  <div>{{ child }}</div>
{% endfor %}

This works exactly how I am needing it to work. However in Twig 2.10 using an if inside of a for is now deprecated and it is now recommended to use eith ...

Score: 1
How can I get a rendered node field value with filters applied?
cn flag
blu

I'm trying to use a REST resource that accepts a node title and returns a JSON interpretation of a single field. This requires raw HTML that I can then use in DOMDocument. To get the rendered value of a node programmatically with filters applied I tried:

$field_value = $node->get('body')->getValue();

However this doesn't apply any of the filters such as converting newlines/carriage returns into

Score: 0
paulvc avatar
Unable to turn on alternative maps styles using Leafleat More Maps
bf flag

I'm trying to change the map style in a Drupal 10 site that I'm building locally.

I have installed and enable the 'Leaflet' and 'Leaflet More Maps' modules.

However when I navigate to the properties of the geofield in admin/structure/types/manage/property/display the 'Leaflet Map Tiles Layer' setting menu only shows OSM Mapnik as an option.

What steps am I missing?

Screenshots:

geofield properties

Leaflet More Maps settings

Score: 1
donbuche avatar
How to translate a link defined in javascript with Drupal.t()
cn flag

I have a template string that contains a link, which I want to translate afterwards throught the Drupal UI:

var html = `<p>${Drupal.t('<a href="/node/16">Check this out</a>')}</p>`

Two questions about that:

  1. What is the correct way to build links in JS that could be translatable, (both the anchor text and the href)?

  2. What should I do with these double quotes? Should I escape them? ...

Score: 0
zack cv avatar
How to get "user pictures in posts" to not be greyed out/ disabled?
eu flag

Setup: Drupal 9 with Claro admin theme and Olivero default theme.

Scenario: When I navigate to admin>appearance>settings>global settings, under the first section "page element display", the first two options ("user pictures in posts" and "user pictures in comments") are both selected but greyed out and unable to change. The second two options below are both selected as well but aren't greyed o ...

Score: 0
Fareed Fattal avatar
How can I dynamically change the default value for views exposed filter based on the terms weight?
mh flag

I have an exposed filter in a view is referencing taxonomy terms from specific vocabulary. The operator allows selecting a term as the default value for that filter. What I want to achieve is to dynamically select the default value when the term weight = 0.

This should allow less privileged roles like Content Contributors to set the default value for the exposed filter by changing the order (weig ...

Score: 1
How can I add term's vocabulary name as body class?
us flag

I already had following codes added, which adds term ID as body class. However, how can I change the ID to term's vocabulary name?

For example:

<body class="term-type-cameras">

/**
 * Implements template_preprocess_html().
 */
function MYTHEME_preprocess_html(&$variables) {
  if (\Drupal::routeMatch()->getRouteName() == 'entity.taxonomy_term.canonical') {
    // Load the term entity and ...
Score: 0
ringitupwiththedongtea avatar
Date filter not working with start date
cn flag

I wish to filter view for node type 'event' by start date > today, or alternatively by >= YYYY, if relative date is not possible. Neither is working. The view SQL see below doesn't apply the filter regardless. In the case of a relative date the filter isn't saved. I am using Date 7x-2.13 and Views 7.x-3.28.

What am I missing in the configuration? Or is this a bug?

enter image description here

enter image description he ...

Score: -1
lynxlynxlynx avatar
How to determine the cause of sudden "content encoding error"s for logged-in Drupal users?
hu flag

One day last week or so, seemingly out of the blue, logged in sessions started to throw content encoding errors. The site still works fine for anonymous users.

useless error

There's nothing in error_log, clearing caches and sessions didn't change anything and throttling the page loading speed shows it actually manages to draw the admin (and CiviCRM) toolbar and part of the page before giving up. The running PH ...

Score: 0
In views, how can I make unpublished comments invisible to users who do not have permission to view unpublished comments?
pe flag

I have a view that lists recent comments. Problem: If an unpublished/unapproved comment is on a published node, the comment is visible in the view even if the user looking at the view does not have permission to view unpublished comments.

I could filter all unapproved comments out of the view, but I want moderators to be able to see them.

How can I make the view respect the permission to view unpubl ...

Score: 2
tahaniau avatar
When does system_requirements function runs?
eh flag

When does Drupal call system_requirements(), which hardens permissions for files and for directories containing them?
Does Drupal call it in each cron run?

Score: 2
Joseph Scoggins avatar
How do I add a query condition to the QueryPluginBase in hook_views_query_alter()?
bd flag

Using hook_views_query_alter() for a view configured as a REST feed, I'm attempting to add an additional filter value to the query, based on the presence of multiple filters passed via the URL.

I need ensure a URL query like /my-feed/?field_my_term_target_id=2761,3101 returns content tagged with 836, for example, as well as the other two terms. So, figuratively speaking, my task is adding or field_my_ter ...

Score: 2
checking route access for authenticated role
by flag

I'm outputting a link, made using Url::fromRoute(). If the current user is anonymous, and the route is not accessible to them, I'd like to show a 'Log in to use this link' text instead, simular to what comment module does.

But I want to show that link only if logging in would actually allow that. So I want to check $url->access() for an authenticated user.

I've tried making a temporary user entity with ...

Score: 2
Hershel avatar
How can you cache a form render array?
cn flag

I have a custom module which builds a set of complicated forms, and these forms are built dynamically (the option lists for certain SELECT items, for example, are fetched via an API call). Some of these forms take 14 seconds to load, whereas a simple "static" form takes 2 seconds.

The data behind the dynamic forms does not change often and so I want to cache the render array of the form, so that  ...

Score: 0
Multilingual site translate languages label for the language switcher
US flag

I have a Drupal 9 site with 2 languages, English and French; French is the default language. Initially, on /admin/config/regional/language, the visible labels are French and English. When I click on Translate, next to English, French is shown as original. When I visit /admin/config/regional/language/edit/en to change the French translation, I set the language to Anglais instead of English; when I go b ...

Score: 2
tahaniau avatar
After any Composer command, does Composer or core set (or harden) the file permissions?
eh flag

After any Composer command (for example, composer create-project, composer require, and composer update), does Composer or Drupal set (or harden) the file permissions?

Score: 1
Is there a way to add / remove items from an unlimited cardinality field in form alter / after build?
ke flag

In a node edit form, I am trying to add items to a multivalue field with unlimited cardinality in a form builder hook, like form_alter or after_build. I can't figure out how to do it, though, at least not very well. For instance, if I fill in the default blank item in form_alter and then add a new blank item, when you click the "Add another item" button, the form resets the items_count for the field to  ...

Score: 1
MrSnrub avatar
How can I prevent a page with PHP content getting flagged in Security Review "Dangerous tags in content" check?
in flag

I am using Drupal 7. I have a page that has a PHP body that I know does not have any dangerous tags. According to the README.txt file in Security Review I need to add this to the "security_review_known_risky_fields" system variable ? Can somebody provide an example on how to do this? I am not sure exactly what the entry in the variable table should look like.

Score: 0
ABHISHEK Joshi avatar
How to enable translations based on domain and path both
jp flag

I wish to apply both, path and domain based translation rules to my drupal website.

For example,

mysite.com/jp should result into Japanese language

mysite.jp should also result into Japanese language

Similarly for other languages as well.

I need both to work somehow, however I think drupal just allows either path or domain, not both.

Score: 0
Sub category wrongly classified to root level and cannot be rectified
us flag

I am using SHS (Simple hierarchical select) which allows the user to create the child term under the parent term by themselves. For example:

root --Canon (parent level) ----5D3 (child level)

When I checked on the taxonomy list, I found those child levels are wrongly classified to root level, instead of their parent levels (the brand).

Even if I changed them to be under the brand manually, it was stil ...

Score: 0
tahaniau avatar
RuntimeException Could not delete /path/web/sites/default/default.services.yml:
ws flag

I have installed Drupal 9 with Composer.

I didn't install any modules, themes or customize anything. It's a plain Drupal installation.

After a few months I did composer update in that website's directory and the process seems to went well besides:

[RuntimeException] Could not delete /path/web/sites/default/default.services.yml:

The website itself is working after this procedure (tested from a browser wit ...

Score: 0
Mr.C avatar
How do I lock down a child theme to use jQuery 3.6.0?
kh flag

My older site uses bootstrap 3 and has been working great when accessed from a mobile phone and the hamburger menu kicks in, but something has happened in jQuery 3.6.2 (In Drupal 9.5.0) that causes the menu click to fire and then immediately close the menu. I can see this when setting breakpoints in the Drupal behaviors script. Looks like some kind of race condition. How would I lock down the child them ...

Score: 2
Alexdezark avatar
How do I cancel an order?
br flag

I am looking for a way to change the status of some orders. I need to be able to cancel orders even if the payment has been validated. In fact, I'm currently using the Commerce Payplug module which places transactions while the Payplug IPN says the transaction was not accepted.

I don't know yet if I'm going to try to fix this module or if I'm going to look for another solution to receive payments  ...

Score: -3
learn4ever avatar
"Your requirements could not be resolved to an installable set of packages."
bd flag

cPanel PHP Version: 7.3

Drupal 8.8

I am trying to install upgrade_status module via composer for the first time in a shared hosting server but I am unable to do that. Below shows the error that I get.

lz@lz [~/public_html]$ composer require 'drupal/upgrade_status:^3.18'

Error

The "composer/installers" plugin was skipped because it requires a Plugin API version ("^1.0") that does not match your Composer  ...
Score: 0
SomebodySysop avatar
sort api solr search using custom view field using hook_views_query_alter()
gb flag

Drupal 9.4.8. Search api solr 4.2.9

I have created a search api solr search in views

enter image description here

One of the fields included in this view is a custom view field: node_date_raw_field

From module hook_views_data():

  $data['views']['node_date_raw_field'] = [
    'title' => t('Node Date (raw)'),
    'help' => t('Node Date raw field plugin.'),
    'field' => [
      'id' => 'node_date_raw_field',
    ] ...
Score: 1
Free Radical avatar
How to export data using POST?
kz flag

I am using Drupal as a backend to deliver data, collected using sensors, and stored in the Drupal database to a mobile app that present the data to the end user.

Drupal records the value from a temperature sensor. When some event happens that changes the temperature, the value is stored in a temperature field in a standard node. I then need to wrap the temperature and use a POST endpoint (defined ...

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.