Latest Drupal related questions

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;
 ...
Score: 0
Zoness avatar
How to add an attribute to a paragraph button link?
hk flag

I'm trying to reach a variable with the html attributes of a link in a twig file, which is used for a paragraph link.

If I dump the button content, I can't dump anything past the object array.

{{ dump(buttoncontent['#object'] }}

How can I reach whatever variable is storing the attributes and manipulate them?

Score: 0
Mark avatar
How can I ensure that the Webform module always send emails in the same language as the original submission?
cn flag
  • I have a webform in English, translated into German.
  • I have webform email handlers in English, also translated into German.
  • Different emails are sent based on submission completion, update, and lock.
  • If a user submits the webform while using the site in German, he rightly gets an email in German. GOOD.
  • However, if an admin updates or locks the same submission while using the site in English, the origi ...
Score: 0
Sleepster avatar
How do I display the title of the entities to which the user has no access?
us flag

I created a new content type with entity references to standard pages. I am using the Taxonomy Access Control module to control the access to these pages.

When users view a node of that content type, they unfortunately do not see page titles for which they do not have access (the title is a teaser). I want all entities to be listed (with the links to the pages), even if the users do not have access to a ...

Score: 0
Mink unable to connect to chromedriver
ai flag

I need help from someone who knows about testing web pages with Javascript in Docker containers. I have browser-based testing working and now I have scenarios which don't work without Javascript, so I'm trying to follow the Drupal documentation for running PHPUnit Javascript tests. The problem is that I'm getting

An unexpected error occurred while starting Mink: unknown error: net::ERR_CONNECTION_REFUSED
 ...
Score: 0
How do I programmatically provide an exposed filter value to a view?
in flag

I am validating the creation of a new node in code thus $form['#entity_builders'][] = '_my_node_builder;

In this validation code I would like to check that my_view returns no results when its exposed filter is provided with a string.

In the code at _my_node_builder

  1. how do invoke the view programmatically?
  2. ... providing the view with the exposed filter string?
  3. how do I check the cardinality of the v ...
Score: 0
Darren Whittenham-Gray avatar
Should I "composerize" my installation?
fr flag

So; having been involved with a D7 / CiviCRM build a number of years ago, I started building a D10/CiviCRM build as a project to suggest to my local organisation.

I think I might have caused myself an issue though, as I installed D10 manually, then went on to install CiviCRM using composer.

  • I have D10 installed on my VPS at /var/www/html/[site]
  • I have CiviCRM installed at /home/[user]/

So the questio ...

Score: -1
Argument #1 ($config_factory) must be of type Drupal\Core\Config\ConfigFactoryInterface, array given
cn flag

I'm writing a new module for the community and I have this error and I'm not understand what's going on.

The error:

Mensaje TypeError: Drupal\view_mode_by_owner_role\Functors\ListOfNodeBundles::__construct(): Argument #1 ($config_factory) must be of type Drupal\Core\Config\ConfigFactoryInterface, array given, called in /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.ph ...

Score: 0
JohnC95 avatar
Creating a Custom Content Listing Page based on specific content type or taxonomy terms selected in the node
mc flag

I am trying to create a content type that generates a list of content/nodes based on other content type or taxonomy terms selected within that node in the content type. I have a general content type for Articles and those are tagged with a taxonomy vocabulary for "Category".

This is within Drupal 9.

What I've done so far:

Create a new content type named "Custom List"

Add a field for an entity refer ...

Score: 0
shibasaki_stack avatar
When a custom form is displayed in a custom template, ajax does not work
zm flag

What I want to do

I want to display a custom form with a custom template and use ajax in it to change values in the form.

Problem

Custom template notation prevents ajax from working. I didn't change anything in php, just twig, and tried 2 patterns as shown below. In twig1, when I changed the value of "a", the value of "b" became "hogehoge" and the log was output. However, in twig2, the value of b w ...

Score: 1
user110018 avatar
Why is the service “@url_helper” not found?
tr flag

I am trying to add the query string with the each URL access through the browser. To accomplish it, trying to implement that through the service. But getting no solution in Drupal 9.

mymodule.services.yml:

    services:
      weplant.userlibraryurl:
      class: Drupal\weplant\EventSubscriber\UserLibrarySubscriber    
      arguments: ['@url_helper', '@request_stack']
      tags:
        - { name: eve ...

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.