Latest Drupal related questions

Score: 0
Mark Edwards avatar
Passing parameters to view blocks in Twig
pl flag

Running Drupal 8.9.18

I have a string that I want to pass to a Drupal block for use in a contextual filter. In a twig template I have a view that creates a simple list of the terms to use. I extract the string from the result array, map the required string to a variable that I pass as a parameter to another view block:

{% set view-output = drupal_block('views_block:view1-block_1') %}

{% for item in v ...
Score: 0
How to access data in Twig in module extended template
us flag

I'm new at developing Drupal. I'm using Drupal 8 and I want to display datetime fields in a special way.

Here is how my module_name.module and template file looks like:

function module_name_theme($existing, $type, $theme, $path) {
  $variables = [
    'field__node__field_course_date__course' => [
      'template' => 'field_node_field-course-date_course',
    ],
  ];

  return $variables;
}
Score: -1
Interlated avatar
How to add a new field in a feed AfterParseBase?
km flag

Parsing a CSV file, and the goal is to take an input column and turn it into two Drupal fields. The last 3 characters of the BondId field becomes a new field called TrancheId.

The BondID field looks like

enter image description here

The CSV source field that is not in the input data is mapped

enter image description here

Code to add a field

class CbiFeedAlterSubscriber extends AfterParseBase {

 /**
  * {@inheritdoc}
  */
 public function applies(ParseEvent $e ...
Score: 0
Functional test for emails (subject and title)
bo flag

Question: How can a Drupal Functional Test (extenting BrowserTestBase) check for a certain Mail-Subject and Mail-Body defined in hook_mail in a custom module ?

Context:

I have a custom module which sends an email to certain people in case a new node of a certain bundle is created.

There is a Functional Test (BrowserTestbase) for this in the same way the User Module is doing it for Core:

https://api.drup ...

Score: 1
Autoload helper classes in tests/src/ for phpunit in contrib module
in flag

I am working on a contrib module with phpunit tests.

Currently there is no composer.json or phpunit.xml or installation routine in the module itself, instead one has to run the functional and browser tests from a custom drupal site, where the module is installed in web/modules/contrib/*. So far this works.

Now I want to use helper classes in tests/src/Helper/, in namespace "Drupal\\Tests\\$modulename ...

Score: 2
How to get the description text from metatag field
jp flag

A content type in my Drupal 9 instance uses the Metatag module. I want to extract the 'description' metatag value and include it in a twig template (for the node).

But when I look at the variables available, it looks like field_metatag contains PHP serialize()-ed code.

I want to do something like

<div class="the-description">
  {{ node.field_metatag.description|e('html') }}
</div>
Score: 0
thomas avatar
LDAP integration not working with Drupal 9 (using Ludwig as a composer alternative - was working under Drupal 8)
cn flag

I 'm having a problem since updating to Drupal 9, with regards to LDAP integration. Previously, while on Drupal 8, I had successfully integrated my schools LDAP for users authentication, using the appropriate contrib module. However, after updating to Drupal 9, LDAP integration has stopped functioning, and whenever a user tries to login, they get a white screen error "The website encountered an unex ...

Score: 2
Greg Sims avatar
Why does Programmatic Node Unpublish not Work?
us flag

We recently upgraded to Drupal 9.3.0 using a Composer file layout. The resulting website is working correctly and is now running in the publish domain. We have a set of utilities that we run as Drush scripts. One of these unpublishes content that we do not want google and other search engines to find -- yet.

I moved into the directory that contains composer.json -- one level above the webroot. ...

Score: 0
How to use views query alter to show filtered content according to tags
in flag

I am new to Drupal and started learning hooks. I am trying to use hook_views_query_alter to show related content to user according to it's preferred tags.

function related_content_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {
  if ($view->id() == 'filtered_content') {
    $user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
    $getPrefTags = $user->get('field ...
Score: 1
Michael Chen avatar
Use Node title as default value in alt field of field_image migration
nl flag

I've been working on a D7 to D9 migrate project, and encountered an issue around field_image's alt value.

The D7 site does not have all the field_image alt tag setup, so we'd like to use the imported Node Title as a replacement if the value was empty.

The migration config file works, all other fields are imported perfectly. Just the alt tag didn't make use of the replacement of '@title' instead (I s ...

Score: 0
Jhon Manny Loto avatar
Non-translatable fields can only be changed when updating the current revision
gb flag

I can't save the translation content and this error message is displayed after hitting the save as draft: Non-translatable fields can only be changed when updating the current revision.

Here's the steps I performed: 1.) Click edit tab on the original language, and edit the content, then save as draft. Actual Result: The content was successfully saved 2.) Go to translation tab and edit the transla ...

Score: 1
Restrict a Media field to allow selecting only a certain file extension in an existing Media Type
pk flag

Is there a way to restrict a Media field using an existing Media Type (File) in a Content Type to permit only a certain file extension in that instance?

In particular, I need a subset of the permitted files types in the 'File' Media Type - just PDFs, without affecting the Media library or the 'File' media type.

I've tried creating a new Media type (in addition to Audio, File, Image, Video) and added ...

Score: 1
Error when trying to view revisions
do flag

Using Drupal 8/9. When trying to view previous revisions I am getting the following error:

Error: Call to a member function getType() on string in clc_d8_theme_theme_suggestions_page_alter() (line 13 of /var/www/html/wrc/web/themes/clc_d8_theme/clc_d8_theme.theme)

It refers to this code:

function clc_d8_theme_theme_suggestions_page_alter(array &$suggestions, array $variables) {
  // Add content ...
Score: 1
How to apply nofollow and target_blank on external links in text created with CKEditor?
cn flag

When I create a node, I often need to add links to external websites in the text.

I want all the external links to open in a new tab and I want them to have a nofollow.

The body field uses CKEditor.

How do I apply nofollow and target_blank on external links in text created with CKEditor?

Score: 0
Yuseferi avatar
Permission for publish field on a translation
cg flag

the website is a multilingual website, and the Publish field is checked as translateable. user one, can see the Publish checkbox on translation and can change it.

but in the other role (let's call it content admin), when editing the translation all fields are there and editable but only the "Publish" checkbox does not show for the user.

I almost gave all translation and edition permission to the "conten ...

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.