Latest Drupal related questions

Score: 0
levente.nas avatar
How to get fields of a product type using a database dynamic query
kw flag

So I currently have multiple different product types that have varying fields. I was able to fetch all products using EntityTypeManager the following way:

$productStorage = \Drupal::entityTypeManager()->getStorage('commerce_product');
$ids = $productStorage->getQuery()->execute();
$allProducts = $productStorage->loadMultiple($ids);

This works quite well, and I see how this can be used to e ...

Score: 0
Maik avatar
Order receipt mail -> shipping_information variable
ps flag

How can I output the individual information of the variable shipping_information in a template file? For the billing_information variable, I followed How can I get the customer name in an order confirmation e-mail? but that doesn't work in my case.


Hello,

thanks for your answer. I use this template file :

commerce-order-receipt.html.twig

In my estore.theme file i use this code for the billing inf ...

Score: 0
liquidcms avatar
Why is Admin Toolbar preventing modal from opening?
us flag

I posted this a few weeks ago: Why doesn't form submit callback get called? and with @4k4's help was able to get my custom form opening a modal when the form was submitted (see answer posted there). I had to leave this for a few weeks and when coming back to it, it seemed as though my modal no longer opens.

My form submits and the throbber spins, but the modal never opens. I see this console error:

 ...
Score: 1
carlo avatar
List all groups of a user in one row as a multi-field
pk flag

I want to list all the users and groups they are member of in one table, one row per user.

I have a simple view that lists all users in the system. I added relation to group content membership and a "Parent group" field to the view.

I tried aggregation, but no luck.

Lets say we have 3 users (user1, user2 and, user3) and 3 groups (Interest1, Interest2, and Interest3). user1 is not a member of any gro ...

Score: 0
How do I test managed files upload through configuration?
in flag

I have a configuration form in Drupal9 which extend ConfigFormBase that I need to pass through Behat test. To simplify the form, I have only one managed_file fields.

$form['card_logo_fid'] = [
  '#title' => t('Image'),
  '#type' => 'managed_file',
  '#upload_validators' => ['file_validate_extensions' => ['png gif jpg jpeg']],
  '#default_value' => isset($companyDataConfig['card_logo ...
Score: 0
techenzie avatar
submitForm not being called when put inside a Custom Block
lc flag

I have been trying to find a fix for this but I haven't been able to. I have tried to put a form inside a custom block to render the form as a component. When the form is submitted it renders the component again but it doesn't invoke the submitForm function. Please review the code and let me know if you guys understand what the problem is.

This is the file structure for the block

NewsletterForm.php

<?php
/**
 * @file
 * Contains \Drupal\ ...
Score: 0
Manav Chauhan avatar
How can I convert the vertical dropdown to horizontal?
pg flag

I created the toolbar with hook_toolbar(), but I want the drop-downs to be horizontal and I get them vertical.

function try_toolbar() {
  $items = [];

  $items['TRY'] = [
    '#cache' => [
      'contexts' => ['user.permissions'],
    ],
  ];

  if (!\Drupal::currentUser()->hasPermission('Access the Commande overview page')) {
    return $items;
  }
 
  $items['TRY'] += [
    '#type' =&g ...
Score: 0
Giuseppe avatar
Alter a route according the current user
br flag

I'm on D 9.4.x, trying to redirect the node.add route to a custom one, only when the current user has the right role\permission.

So I don't think I can't work in the alterRoutes but I probably need to override the controller of that route. In a custom RouteSubscriber I have:

protected function alterRoutes(RouteCollection $collection) {
    if ($route = $collection->get('node.add')) {
      $route- ...
Score: 1
Matt avatar
How to render a twig template in the meta data of a cacheablejson response?
cn flag

In a json response I'm returning some prerendered data. However I got tired of constructing the html by concatenating strings in php and decided to make a twig template for it.

$render_facets_arr = [
  '#theme' => 'facets',
  '#facets' => $data['meta']['facets'],
];
$data['meta']['renderedFacetsTest'] = \Drupal::service('renderer')->render($render_facets_arr)->__toString(); 

However when I ...

Score: 0
John avatar
Add/enable language to Language Module from code
ht flag

I'd like to add/enable a language, just like one would from the admin ui at /admin/config/regional/language/add

but, from code. I've found old options such as locale_add_language which no longer exists, since Drupal 5 or 6. Everything else I can find is in Tests, which seems like a bad route to take and I'm still a little new to Drupal development to understand how to make it happen, or if I should.

Score: 1
Eryk avatar
How do I set/get cookies in a controller (custom module)?
bs flag

I have a module and I need to set a simple cookie (if not exists). And after each request I need to read the value of the cookie and maybe update.

I have read many articles and tried many ways but no success. The only one, which works, returns a "response" object. But my controller should still work, even after response->header sent/saved.

This is the controller code.


namespace Drupal\my_cust ...
Score: 0
Manav Chauhan avatar
How can I bust the cache for the toolbar?
np flag

I am creating a drupal module and here in the module file i created a check on hook_toolbar() function that if there are credentials in the database it will show 4 links in dropdown otherwise it will show only 2 links. Initially with no credentials it shows 2 links but whenever i get credentials and update them in the database i have to clear cache in order to update the tray in the hook_toolbar() in or ...

Score: 0
Stefan Gofferje avatar
Articles are displayed multiple times
cf flag

I have two taxonomies (category, with subcategories, and tags) and a content type (article). An article can be in exactly one (sub-)category but can have multiple tags.

I'm trying to create a view which shows all articles in a category, including all subcategories of that category and, when a subcategory is selected, only articles in that subcategory.

My problem is that the articles show up multiple ...

Score: 1
How to render the correct variation price in catalogs?
us flag

I have a product catalog built using search api, facets, and views like this: https://docs.drupalcommerce.org/commerce2/developer-guide/products/marketing-products/product-catalog-facets. My add to cart form is using the Variation Title widget.

I want to render the product price, and when there's multiple variations I want the price of the variation currently selected to render.

If I add a relationship t ...

Score: 1
pixel5 avatar
Service continues to act as shared when shared is set to false
in flag

According to Symfony docs, doing shared: false on a service should mean that each time you call a service, you get a new instance. However, this doesn't seem to work for me. I am using Drupal 9 which runs on Symfony 4.4.

My services.yml :

services:
  my_module.arbitrary_data:
    class: Drupal\my_module\Services\ArbitraryData
    arguments: ['@another_module.contextual_uid']
    shared: false

https:// ...

Score: 0
lcdservices avatar
What is the preferred workflow for setting up TFA for users?
se flag

I have a D7 site in which I've setup TFA using TOTP. If TFA is not required, the user can login with their user/pwd, visit the profile page, click the security tab, and setup TFA.

However, if TFA is required for their role, the only way they can setup TFA is to have an admin access their user profile and supply them the code to enter into their auth app, then wait for them to provide the code to en ...

Score: 0
Scott Hollenbeck avatar
Unable to enter credit card payment information
mx flag

I just noticed that I'm unable to enter credit card payment information (card number, expiration date, CVV) when going through the Drupal Commerce checkout processing using the Square Connect payment gateway. This was working fine in the past; I'm not sure when it stopped working but it might be related to the newest Commerce Core release on 19 October 2022. The fields are there, but I can't enter text  ...

Score: 0
Jaswin Singh avatar
Nightwatch not executing in Acquia pipeline
jm flag

I'm trying to execute the Nightwatch test on Acquia pipeline for every PR raised

I have created a custom BLT command that executes the test cases of Nightwatch. it is executing fine locally but it fails on the pipeline. The chrome driver is failing to connect. Below is detailed error.

[Tests/Toolbar Api Test] Test Suite

  • Connecting to localhost on port 9515...

⚠ Error connecting to localhost on port 9 ...

Score: 0
Francisco Ramos avatar
How can I make the relation I am using in a view work again?
bo flag

I'm currently migrating from Drupal 7 to Drupal 9, and i'm rebuilding all views (as I can't find a good migration procedure for views from 7 to 9), also trying to understand the changes (this is a side project for a friend, i'm not an expert in Drupal). I'm having difficulties with something I have running on 7. This is the situation on 7:

  • I have a content type named "club" for sports clubs. Amongst  ...
Score: 0
How to set default value of ’Choose Variation” in add to cart forms?
us flag

I'm trying to get variation dropdowns in add to cart forms to have a default value of ’Choose size” or similar that also disables the add to cart button in a way similar to 'out of stock' but with another wording (or just greyed out).

The reason for this is that I’d like to avoid people thinking all variations of a product are out of stock just because the first variation happens to be so.  ...

Score: 1
eric55 avatar
How to hide the tabs on the user account if it is not his account?
ly flag

My users have permission to view other users' accounts. Only the "View" tab page. This is exactly what I want.

On the user account, by default, there are three tabs:

  • View

  • Shortcuts

  • Edit

If I am user A and I go to my account, I see the tabs. If I'm user A and I go to user B's account, I don't go to his tab (it makes sense).

Now if I create a page view (e.g. bookmarks) with a menu tab, for user account ...

Score: 1
Shawn W avatar
How to loop through and build an array from each referenced entity
cn flag

I’m trying to create a card grid component using paragraphs. I have a reference entity which references different card types with unlimited cardinality. I’m able to pull the values from the reference entity with the below code but this only pulls the initial values so I’m only getting data from one entity instead of each individual entity as they are added to the grid. I’m not sure why my for ...

Score: 0
Themetis avatar
How to differentiate the state when a contextual filter is applied?
lu flag

Hello to all the Drupal community. I've recently faced a challenge to visually modify some parts of my view's template for the state when its contextual filter is applied. Some details are as follows:

  • I have a View of the articles previews list. Each article has several tag names (taxonomy terms) applied.
  • This view has a Contextual filter set up to filter the list based on the taxonomy Term (tag name) ...
Score: 0
Samuran Wong avatar
Theming User Address Book Page
ru flag

We are using drupal commerce2 on drupal 9, and I am trying to theming the address book tab (add some classes to layout and fields), /user/*/address-book.

Unfortunately there isn't any twig template in commerce module, anybody knows how to do this (CSS is ok, but I prefer to use twig)?

Score: 2
Why hook_ENTITY_TYPE_access and hook_ENTITY_TYPE_create_access are not fired?
cn flag

I'm implementing for nodes hook_ENTITY_TYPE_access() and hook_ENTITY_TYPE_create_access() for a project and they are not fired even after cleaning the cache many times. I checked the code and there is nothing wrong and there is any message in the logs and I'm logged as Administrator.

Score: 1
FraMan avatar
Programmatically update products
cf flag

I am building a site with Drupal 9 and Drupal Commerce 2 (Drupal Commerce Kickstart).

The site is complete and I have already entered all the products via Feed (there are over a million). Now I'm looking for a way to periodically update the products automatically (prices, availability, etc.)

In an old site that I had made and which was developed with Drupal 7 and did not use Drupal Commerce, it was  ...

Score: 0
Ishmelev avatar
Get all url in visibility request_path in block_content if request_path['pages'] is /node/* or /news/*
cu flag

I am creating a module for the administrator for Drupal 9. The purpose of this module is to show one of the block_content of a certain type in the table as a sample and create 2 links for it: for editing and for viewing (Edit/View).In order to get a link to view, I have to check the display conditions of this block. Let's say the block has display conditions on the page /node/10 - then everything is sim ...

Score: 0
How to render content entity as a token replacement?
us flag

I wonder what's the right way to render entity render array as a token replacement (value). I found 3 different ways in the contrib:

Score: 0
divspan avatar
Can you add background-position selector to masthead images?
fm flag

The theme we are using incorporates mastheads on almost all pages. The images are 1440x625 with a hard coded background-position of top center. I had no hand in developing this theme so I'm really lost. The major issue is that with the masthead image being set as top center on every page, we're having very mixed results with image behavior at different breakpoints.

Is it possible to add a drop-do ...

Score: 0
How to fetch form values for Simple hierarchical select?
ng flag

I have referenced a field with taxonomy by using simple hierarchical module and now I have to fetch the options programmatically to perform some actions on them. I tried to fetch it like the below it didn't work out.

$form['field_delivery_methods']['widget']['#options'];

This worked on shs 8.x-1.0-alpha5 but after upgrading to shs 2.0.0-rc3 its not working. Does anyone help me in understanding th ...

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.