Latest Drupal related questions

Score: 2
Testing Drush Commands
bo flag

How to test custom implemented Drush Commands ? Are there any Open Source Examples for Drush Commands with Unit Tests or something like that ?

Score: 0
How to use setConstraints() for a custom constraint on BaseFieldDefinition?
cn flag

I'm refactoring a node content type into a custom entity.

On this entity, I add a datetime field:

$fields['target_date'] = BaseFieldDefinition::create('datetime')
          ->setLabel(t('Target date'))
          ->setCardinality(1)
          ->setRequired(TRUE)
          ->setConstraints(['DateTimeMidnightOnly' => DateTimeMidnightOnlyValidator::class])
          ->setSetting('datetim ...
Score: 2
How to temporarily override configuration?
br flag

I want to be able to contextually modify configuration variables, i.e. within a page controller.

Example

I have a custom ad module which besides other settings has an option to globally disable or enable ads. In general the ads are enabled (\Drupal::configFactory()->get('custom_ads.settings')->get('active') === true).

On some pages (provided by custom page controller) I want to disable ads. There ...

Score: 0
bella avatar
Impact of not doing these updates on the CMS
ye flag

[update][1]

Hello, I am a new hired and tasked to manage a vendor who is supposed to update our website. They have not been doing so, I am not technical enough to know whether these Drupal updates will have a huge impact on us when they are not attended to. I attacked 2 screenshots here and really hope you can shed some lights....very much appreciated.

Score: 0
user108983 avatar
How do I get the value of the Taxonomy Term Description after loading Taxonomy Vocabulary term by Term ID?
cr flag

What would be the best way to render the Taxonomy Vocabulary Term description value? I can render the term id and label/title, but the description seems to need something else that I'm not quite getting.

  // Render ID - working
  $termID = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->load(419)->id();
  
  // Render Label/Title - working
  $termLabel = \Drupal::entityTypeMana ...
Score: 0
SteFairc avatar
Require Workbench Reviewer field
ky flag

For the project i'm working on, I am using content moderation and workbench_reviewer modules. This allows content authors to choose a reviewer (manager) for the next step in the publishing workflow who then receives an email.

The only issue is that by default the workbench reviewer module doesn't have an option to make the field required. For my project I need to make this a required field.

I hav ...

Score: 0
castithan21 avatar
Can't submit/process data from custom multi-value field type?
tf flag

I'm trying to insert some data into a custom content entity I have made containing a custom (unlimited cardinality) field type I created that contains 5 values, a html text value, 2 entity references and 2 integers. I have not marked the field as required and saving data to the custom entity without adding an instance of the custom field works fine, but as soon as I try to save the entity with data from ...

Score: 0
Add granularity to entity query when sorting by a date field
na flag

I'm trying to get an entityQuery to sort nodes by a date field. I want to use hour granularity.

So, if some nodes' field_date values are set to the same hour, these nodes will be sorted alphabetically (by title).

$query = \Drupal::entityQuery('node')
  ->condition('status', 1)
  ->sort('field_date' , 'ASC') // I want this sort criteria to use hour granularity
  ->sort('title' , 'ASC');
 ...
Score: 0
Alexander Benjamin avatar
entity_autocomplete attached via #ajax callback doesn't work
sa flag

I'm serving an entity_autocomplete field via #ajax callback when a checkbox in the form is unchecked.

The entity_autocomplete field shows but there is no autocomplete attached to it.

Here is how I attached it from within ajax callback:

$form['url_301'] = [
  '#type' => 'entity_autocomplete',
  '#target_type' => 'node',
  '#required' => TRUE,
  '#prefix' => '<div id="edit-output"&gt ...
Score: 0
Mihail Novak avatar
Check the active language
us flag

I'm sorry for my bad English. In my node.html.twig I have two layouts for two groups of languages.

  1. English, Ukrainian and Bulgarian
  2. Arabic, Farsi, Urdu I can't check with twig which is the active language to load one of the two layouts. I tried this but it didn't work. Thanks a lot if anyone can help me
{% if language.getId() == 'en' or 'uk' or 'bg' or 'ru' %}

    
        {{ content.field_mt_ ...
Score: 0
Giuseppe avatar
How edit moderated and translated content?
br flag

I'm on on a D9.4.x clean installation, and I am having inconsistent behavior when trying to editing and change the moderated state of a content type which is also translatable in EN and ITA.

If I try the following code:

function test_node_publish() {
  $node = \Drupal::entityTypeManager()->getStorage('node')->load(2);
  $status = 'draft';
  test_node_edit($node, 'new english title', $status);
  tes ...
Score: 0
Pedro avatar
Impossible to use custom fields in twig linked to form
ml flag

I have a form in which I have two date fields and a filter button. This form is included in a custom view in which I have a table that displays data from the database. The date fields are here to filter the data that I display in the table. I use AJAX in my form with a callback function.

What I want to do is adding the data to my form with the callback function, and displaying it in my twig.

My prob ...

Score: 1
Binary Alchemist avatar
uninstall module that depends on relation module, which is disabled
in flag

I am a maintainer of the crm_core module. The Drupal7 version depends on the relation module to provide relationships between contacts. The depend module can not be uninstalled while the relation module is disabled.

Is there a solution? Or, is this one of the limitations of disabling modules, which might be why disable was dropped in Drupal8.

2273255 - Can't uninstall crm_core_relationship when relat ...

Score: 0
Claudia Burman avatar
How to display random banners if the number I need exceeds the amount of vocabulary terms?
im flag

I made a classified ads site in Drupal 6, now I am updating it to Drupal 9. I already have the "ads" part working, defining categories with a taxonomy vocabulary but displaying the ads with a Views page (custom URL).

I have an issue with banners. I succeeded in displaying a block with banners tagged with the same term.

BUT in my old site, using a module called "Advertisement", if I want to display 5 ...

Score: 0
beltazzar avatar
I am having trouble uploading an image in Gutenberg, can I upload it otherwise to the media library?
bb flag

I am having trouble uploading an image in Gutenberg (there is "infinite loading", without error, when I try to upload and eventually no image gets uploaded to the media library).

Can I upload it otherwise to the media library and then just pull it with Gutenberg?

I didn't find where to upload images in admin/config/media/file-system.

Score: -3
beltazzar avatar
How to make Drupal to login and send email via Gmail?
bb flag

I have a Drupal 9 website with a core contact form (I don't use Webform).

I have two Gmail accounts, one by which I want to send email and one to which I should receive the email.

So I need a way to make Drupal log in to my Gmail_account_1 and use it to send email (contact form inquiries) from it to my Gmail_account_2.

I think that in the Linux world this methodology is named sSMTP.

Score: 0
Joost avatar
Filter taxonomy admin overview
jp flag

I want to programmatically filter the taxonomy overview page for admins. I tried doing this with hook_form_taxonomy_overview_terms_alter and even though the filter is working (the user only can see terms of him and connected users) this is not the right place to filter the content.

I found out that the drag and drop function on the overview page is not working when I filter the overview like this. The w ...

Score: 1
Gustav avatar
Add Javascript On Webform Confirmation Page
ng flag

I am using Webform to generate a form on a page. Wherever this form loads, I need to run some javascript to push some data for Google Analytics 4 on two events (any field is focused, form is submitted regardless of validation results).

For that, I am using this code to load my library that contains all the JS.

function mymodule_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $ ...
Score: 0
turpentyne avatar
One label, Multiple values, in a grouped filter item
tr flag

I have an exposed filter on a view, pulling a search API indexed taxonomy field. I'm using the 'grouped filter' to create a dropdown of text options that match taxonomy IDs, and I was hoping to have a label that contains multiple values in, essentially, an 'or' format.

Example: "Yellow" -- "is one of" -- "1234, 3210, 9953" or maybe "Yellow" -- "is one of" -- "1234 + 3210 + 9953"

But right now I don' ...

Score: 0
How to restrict access to comment form and posted comments for certain users
kr flag

I have a content type where comments are enabled. So on node view, I can see the comment form and all the posted comments.

Is it possible to not display the comment form and all the posted comments for a user? i-e

if ($current_user_id === $target_id) {
  // Hide comment form and posted comments
}

I have checked the CommentAccessControlHandler class and the method checkCreateAccess but that function ...

Score: 0
xpersonas avatar
Get Translated Field Label for Entity
cn flag

I have a field I have translated. But I can not figure out how to get that translated field label programmatically. I've found a few posts on here, but none of them work for me.

Pretty easy to get the default field label:

$fieldDefinition = $model->get($field)->getFieldDefinition();
$fieldLabel = $fieldDefinition->getLabel();

Does anyone know a way to get that in 2022?

I thought the answe ...

Score: -3
francky avatar
How to display a block on the home page when the user is authenticated or anonymous?
sm flag

I created two custom blocks. I want to display its two blocks only when the home page view is empty.

I want the custom block with id 11 to be displayed for anonymous users.

I want the custom block with id 12 to be displayed for authenticated users.

So I copied the views-view--frontpage.html.twig template into my sub-theme.

What should I add in the code, to obtain this result ? Thanks

  {% if rows  ...
Score: 0
Shane avatar
Why is my css in my twig template getting ignored when I apply it to a newsletter issue and then email that newsletter to myself?
gu flag

I have created a simplenews Newsletter issue called test1 newsletter.

Newsletter content

In the simplenews-newsletter-body--default.html.twig template file I use for the newsletter, I need to add some CSS styles. This is the file content.

{% apply inline_css %}
<html>
<body>
<div id="email" style="width:600px;margin: auto;background:white;">
  <!-- Header -->
  <table role="presentation" border ...
Score: 0
TIBlock avatar
Can I calculate percentages between two subqueries in addExpression()?
kr flag

I am trying to calculate the results of two COUNT() subqueries in order to produce a completion percentage. In this case I am getting the total number of courses assigned to an entity then comparing that entity with the number of courses completed by a user, then I would like to get the total percentage of courses completed by the user.. I am able to get the count of courses from the first entity, and t ...

Score: 0
What is the use case for "bundle fields" that are independent of an entity type's base fields?
cn flag

So I can define a custom entity in code (quickstart: drush generate entity:content).

I can then use BaseFieldDefinition to define base fields that will be shared by all entities of that type.

However, if my entity has bundles, I may want to define some fields only for certain bundles. It seems this is sometimes called a "bundle field" on drupal.org, and they can be defined in hook_entity_bundle_fie ...

Score: 0
Delford Chaffin avatar
Search Facets - Entity Type
gg flag

I want to create a facet to filter search results by entity type (node and product in this case). I have the entity_type field added to my index ...

enter image description here

And I have a facet set up that seems like it should work ...

enter image description here

The content_type facet works and is set up essentially the same way.

Any idea what I'm missing here? Thanks!

Score: 0
johndoe80 avatar
how to get field image of a referenced entity in paragraph template
ee flag

I made a paragraph with a referenced entity field to a content type called "tools" Actually I can get the title and body text like that :

<h3>{{ content.field_tools_and_services.0['#node'].title.value }}</h3>
<p>{{ content.field_tools_and_services.0['#node'].body.value}}</p>

now, I need to get the field image, I tried to do something like this :

<img alt="{{ content.fi ...
Score: -3
francky avatar
How to replace the default text of the home page, when it is empty?
sm flag

On the Drupal 9 home page, there is a text displayed by default, when no content has been created.

I want to modify the text of this page, when there is no result. I go to the "frontpage" view and add an unfiltered text field in "Behavior when there are no results".

My problem is that it has no effect. I still have the default text that appears.

How to replace the default text of the home page, when it ...

Score: 0
Austin L avatar
Get parent Paragraph Entity from Referenced View
me flag

I have a custom paragraph type - which has 2 fields:

  • Display Mode,
  • View to be rendered

I want to let users choose Display Mode in this paragraph, then I will render view dynamically based on this Display Mode value.

The problem is, it seems there is no way to get this Display Mode value inside view template(views-view-unformatted.html.twig) or hook (HOOK_preprocess_views_view).

Only what I can acces ...

Score: 1
How to set a URL alias for a custom entity type generated with drush?
cn flag

I created a custom content entity type with the command drush generate entity:content. Now I want to set a URL alias pattern at /admin/config/search/path/patterns, but my new custom content entity type is not available. How can I add URL aliases to this type?

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.