Latest Drupal related questions

Score: 0
Sarah C avatar
Get link to content in entity reference field template
za flag

I have an entity reference field set in Manage Display to 'Rendered Entity' and am working with the field's template to conditionally show the link based on the referenced node's published status. I'm using 'Rendered Entity' so I have access to isPublished().

How can I get just the path of the referenced node in the field's template?

Within {% for item in items %}, this works great to get the referenced ...

Score: 0
Ramalingam Perumal avatar
How to get value from object in twig template file?
mx flag

I can print the result object by {{ dump(item.value['#result']) }} in theme item-list--search-results.html.twig template file.

enter image description here

I want to print the body field value("body"=>"value") from the object.

How I will do ? I have tried some other ways which I know

  • {{ dump(item.value['#result']['node'].#values['body'][0]['value']) }}
  • {{ dump(item.value['#result']['node']['#values']['body'][0]['value']) }} ...
Score: 1
Crystal avatar
Barrio Theme 5.5.10 Main Menu submenu does not output list items
tf flag

I need help with the Barrio Theme submenus. I upgraded our site to 5.5.10 to discover the menu has stopped working. In my attempt to figure this out, I recreated a test site locally and installed a Drupal 9.5.5 legacy-project and barrio 5.5.10.

The submenu is not outputting the listing of the submenu. The documentation says all parents must be expandable and they are. I dont know the system is ig ...

Score: 0
miststudent2011 avatar
how to alter entity reference field (taxonomies) field options in hook form alter
fr flag

Can anyone please let me how to alter entity reference field (taxonomies) field options in hook form alter,

Seems the below code doesn't work.

/**
 * Implements hook_form_alter().
 */
function MY_MODULE_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  if ($form_id == 'node_article_edit_form' || $form_id == 'node_article_add_form') {
    $channel_options = [
      '1' => 'Term1', ...
Score: 0
shibasaki_stack avatar
Unable to update node entity fields using custom form
zm flag

There is a certain content type, in which there is a field to enter a node or taxonomy. I want to create a new node for that content type using a custom form and register the node or taxonomy in the entity field.

$form['client_company'] = [
  '#type' => 'entity_autocomplete',
  '#target_type' => 'taxonomy_term',
  '#tags' => TRUE,
  '#selection_settings' => array(
    'target_bundles' = ...
Score: 1
States on input type button broken since core update
kn flag

I've updated my Drupal project from 9.5.3 to 9.5.7, but the submission button's #states property stopped working.

$form['actions']['submit'] = [
  '#type' => 'submit',
  '#value' => 'Accéder au paiement',
  '#enabled' => FALSE,
];

$form['actions']['submit']['#states'] = [
  'enabled' => [
    [
      ':input[name="name_1"]' => ['empty' => FALSE],
      ':input[name="name_2"]' = ...
Score: 1
Jordi Bustos avatar
Why does the error 'You have requested a non-existent parameter "site.path"' occur on module configure buttons?
mr flag

When I click some configuration buttons for example in layout builder UI or the following buttons. enter image description here I get the following error in admin/reports/dblog

Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException:
You have requested a non-existent parameter "site.path". en Drupal\Component\DependencyInjection\Container->getParameter() 
(linea 328 de /var/www/html/core/lib/Drupal/Component/D ...
Score: 0
Sudha avatar
can't get multistep ajax webform work with computed field
sj flag

When ever I use multistep webform with computed field and try to enter data in second page, webform redirect me to first page with validation error. Source code of my webform,

    page_1:
      '#type': wizard_page
      '#title': 'Page 1'
      name:
        '#type': textfield
        '#title': Name
        '#required': true
    page_2:
      '#type': wizard_page
      '#title': 'Test Page'
       ...
Score: 1
arirams avatar
Content moderation and changing node state on default or latest revision
gh flag

I am using content moderation and sometimes I update the moderation state of my entity programmatically in a hook node presave for example. I usually have the entity and I can do $node->set('moderation_state', "needs review"); , however my question is, if for some reason in a controller, I want to do the same thing in a function that doesn't have the node entity as parameter, I wanna load the nod ...

Score: 0
Adding cache tags to custom block
kn flag

I have a custom block which load some taxonomy terms.

When I made changes to my taxonomies, the block isn't loading the new data (due to the cache). I'm passing all my taxonomy tags to my #cache return, but nothing append when I reload my page. I still have to drush cr to see the changes (even tried with taxonomy_term_list, but didn't work either)

Here's a simplified version of my block :

<?php
 ...
Score: 0
Theme a field widget with twig
us flag

Implementing hook_field_widget_single_element_WIDGET_TYPE_form_alter is altering the widget. It makes sense to theme the changes in a twig template. Here's the widget form alter code:

/**
 * Implements hook_field_widget_single_element_WIDGET_TYPE_form_alter().
 */
function my_module_field_widget_single_element_entity_browser_entity_reference_form_alter(array &$element, FormStateInterface $form_state,  ...
Score: 0
Matthew avatar
Which hook will allow me to change links in a page?
ee flag

Which hook would allow me to change each link (given in <a> tags) in content pages and menus and change their attributes?

I need to implement this in a theme that uses Olivero as parent theme and the obvious MYTHEME_preprocess_links() results in a blank white screen (WSOD).

The only hook I've been able to use to change the page content is this one.

function MYTHEME_preprocess_field(&$variab ...
Score: 0
shibasaki_stack avatar
Error when trying to retrieve a term with ajax
zm flag

We are creating a custom form to edit a certain node. We do this above because there are some things that cannot be accomplished with the default form.

I want to use AJAX to populate the fields of the custom form with the values entered in the existing node, as shown below.

$form['client_company'] = [
  '#type' => 'entity_autocomplete',
  '#target_type' => 'taxonomy_term',
  '#tags' => TRUE,
   ...
Score: 0
liquidcms avatar
How to modify the timezone options list?
us flag

I have a date range field in a paragraph which is set to allow setting the timezone. Can someone suggest how I can alter the list of options used to select the TZ?

For the user profile form a simple form_alter exposes the timezone field options but when trying to alter the paragraph form I only see the timezone value already set as #date_timezone.

Possibly I can override the class used to build this ...

Score: 0
Custom webform element saves value as array
ng flag

I have created a custom webform element based on the webform example element. https://github.com/drupalprojects/webform/tree/8.x-5.x/modules/webform_example_element

It is still a simple text field, like the example but does some calculations form the current formid submissions.
Somhow every value entered in my text field shows up as "Array" (basically as the word "Array" in the submissions. I did a  ...

Score: 0
Drale avatar
Stick comments on top
ls flag

I need to stick specific comment on top of others which will remain from oldest to newest. When it's stick on top it's replies must be with that comment.

So

  1. I made links in .module file which will take method from controller
    use Drupal\comment\CommentInterface;
    use Drupal\Core\Url;

    function hook_comment_links_alter(array &$links, CommentInterface $entity, array &$context) {

      ...
Score: -2
How can i subscribe/unsubscribe to a simplenews newsletter programmatically?
us flag

I have the following code to set subscriptions to a simplenews newsletter on or off:

    $user_load = User::load($userID_current);
    $newsletter_subscriptions = [
        'newsletter1' => 'on',
        'newsletter2' => 'off',
        'newsletter3' => 'off',
        'newsletter4' => 'off',
    ];

    foreach ($newsletter_subscriptions as $system_name => $value) {

        $subscrip ...
Score: 0
Zuhair avatar
How can I resolve the "Unique file URI" when using managed_file field in form API with a file name that already exists?
mv flag

I am facing a strange issue with a managed_file field in my Drupal form API. Whenever I upload a file and save the form, and then come back again to upload another file with the same name, I get this error message.

The specified file xyz.png could not be uploaded. The file temporary://xyz.png already exists. Enter a unique file URI.

However, if I try to upload the file again, it gets uploaded successfu ...

Score: 1
david avatar
How can I set view permissions for content type to make it visible to autenticated users only?
ng flag

I want a content type to be only visible to authenticated users.

Now the edit permission dialog only offers permissions for modification, not for displaying the published content.

Until Drupal 9, I've used the Permissions by Term module to limit public access for certain page areas and content types. Since Permissions by Term is not yet Drupal 10 compatible I had to remove it.

Is there an elegant, ideall ...

Score: 0
Alex Misgin avatar
Buying an amount of product X must add a product Y
jp flag

I have a shop where a product (lawn/turf) can only be bought with an additional package (Europalette). When users buy 1-50 items there must be one Europalette packaging automatically added into the cart. If the amount is 51-100, two Europalette packages must be added.

Europalette is also a product the users buy. So both have to be combined as explained before.

I tried the Pado and Vado modules, bu ...

Score: 0
avishek avatar
Where are the memcache parameters set?
pk flag

I installed the Memcache API and Integration module and I can check the memcache report on /admin/reports/memcache.
How can I get the total utilization of memcache servers? Where are those parameters (number of connections) set for each server?

screenshot

Score: 1
ab2211 avatar
Two visible states
it flag

I'm struggling with two visible states. WIth thE UI this is not possible.

I have an extended text/html field, which shall be visible if the following conditions match:

Scenario 1:

System checked AND System everything except Google Kalender and Miscellaneous selected AND branch is NOT Gesundheit... ist.

Scenario 2:

Website checked AND System 2 everything except Google Kalender and Miscellaneous selecte ...

Score: 0
Mykola avatar
How do I display a block after changing its ID?
in flag

I have a custom block. I want to change its ID, but after I changed it from main_menu_block to header_block, the block is not displayed anymore.

I tried to:

  1. Remove the block with the old ID
  2. Change the block ID and clear the cache
  3. Add the custom block on the admin side

The following is the block definition.

/**
 * Provides a 'Header Block' block.
 *
 * @Block(
 *   id = "header_block",
 *   admin_labe ...
Score: 0
How to disable the option time_restriction that honeypot add to the forms
cn flag

In the README file for the Honeypot module, it says:

If you want to add honeypot to your own forms, or to any form through your own

module's hook_form_alter's, you can simply place the following function call

inside your form builder function (or inside a hook_form_alter):

> \Drupal::service('honeypot')->addFormProtection(   $form,  
> $form_state,   ['honeypot', 'time_restriction'] );
Score: -3
Interlated avatar
Avoid adding custom CSS to a node editing form?
km flag

Situation

  • custom module adding styles
  • don't add styles to node editing form

How to avoid adding the style to the editing forms?

function crossfade_page_attachments(array &$page) {
  $page['#attached']['library'][] = 'crossfade/crossfade';
}
Score: 0
user1470118 avatar
EntityQuery to filter values returned based on List(text) field
jp flag

I have a List(text) field that can have multiple values. I am trying to create an entityQuery that returns nodes with specific items are checked within the field. The variable "availableServices" is an array of available services. I tried adding an andconditiongroup but that results in no items being returned. How do I check if a field has multiple values selected?

I've checked and when I search  ...

Score: 0
Alex Smirnoff avatar
Change all generated user/{uid} paths to user/{uuid} and process them without the redirect
mk flag

I need to change all generated user/{uid} paths to user/{uuid} and process them without the redirect. The tricky part is that I need to:

  • Output canonical URLs to user/{uuid} instead of user/{uid}
  • Process them correctly without redirections and custom controllers

How can I achieve this?

Score: 0
Quetzcodecoatl avatar
Trying to filter the results of the entity autocomplete form element
tw flag

Currently, I am working on a module that offers the function for users that belong to specific user roles to be able to write private messages to each other.

In order for the sender to be able to add a recipient to his message, I used Drupal's EntityAutocomplete class and as the #target_type I chose user so that the sender gets to choose his recipient(s) from an automatically generated list of use ...

Score: 1
Pixelstyle avatar
Always charge the most expensive flat rate shipping in an order
vn flag

I have a Drupal Commerce site with two product types. One has free shipping, and the other costs € 3,-. When both products are in the cart, the customer is allowed to choose either of those rates, which is not what I want.

I want to disable the free shipping rate when the second product type is in the shopping cart. On shipping calculation the most expensive shipping should be calculated.

In shipp ...

Score: -2
New Dev avatar
Get MenuLinkContent object values
np flag

get title and link of a menu link object in. I am trying to get title and link of a MenuLinkContent object and below is my code. I want to get title and link value. How I can get the title and Link url without foreach. something like- menu_content[]->title and menu_content[]->link

Defined name spaces

use Drupal\menu_link_content\Plugin\Menu;
use Drupal\menu_link_content\Entity\MenuLinkContent;
 ...

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.