Latest Drupal related questions

Score: 0
How can show a message for products that are not in stock?
ye flag

I am implementing custom stock management in Commerce. I followed the following steps.

  1. I have added a stock integer field in product variant.

  2. I have written a event subscriber which reduce this stock field value after purchasing.

    public static function getSubscribedEvents() {
      $events['commerce_order.place.post_transition'] = ['orderCompleteHandler'];
    
      return $events;
    }
    
    /**
     * Reduces the stoc ...
Score: 0
Display fields from entity reference revision, without indexing them
in flag

Scenario (simplified)

  • A content type with a number of fields.
    • One of the fields is (optional) single-value entity reference revision, pointing to a custom entity type with more fields. There are 3-4 fields (the 4th only occurs in one bundle).
    • One of the fields is an entity reference, pointing to a taxonomy term.
  • A search index for the main content type.
    • Search server uses search_api_solr.
    • So ...
Score: -3
jwa avatar
How can read/write information from HTML?
gd flag
jwa

I have a content type that includes 2 URL links.

  • The first like: previousURL = /blog/day9
  • The second like: nextURL = /blog/day11.

So I can easily switch from the current page to a previous or a next page.

The problem is when I change the language from the default language to e.g. french the links should be changed to /fr/blog/day9 and /fr/blog/day11.

I have no idea what functions to use for reading an ...

Score: 0
GeorgeCiesinski avatar
How do I switch from PostgreSQL to MySQL
mv flag

I set up a website using Drupal 10 and PostgreSQL but due to a communication delay, I just found out from the server team that the database on the staging/live servers is MySQL and not PostgreSQL. I now face the issue of switching my site to use MySQL instead.

My goal is to switch the database from my local PostgreSQL database to my newly created local MySQL database so that I can easily migrate  ...

Score: 0
John Paul Mariano avatar
View Rest Export includes comments in json
es flag

View Rest Export returns a JSON with comments. How can I disable comments?

screenshot

Score: -2
ImagoTechStack avatar
How can I avoid forms are saved as drafts?
pw flag

I used Drupal 9 webform module to create forms , Each form has Submit button and Save as draft button, Below is the configuration for the form , enter image description here When I submit the form it save as draft ,

screenshot

But when I open it from result section and submit it saved properly without save as a draft . Is there any setting to stop that? Is it because of some configuration ?

Score: 0
mfairhurst avatar
Override the page title with a value from an API response
gt flag

I built a custom Drupal module. The module fetches data from a 3rd-party API and builds a block. I need to use a value from the API response to override the title (and head_title) of the page that the block is placed on.

I tried saving the value to the node in the Block controller:

$node = $this->getContextValue('node');
$node->page_title_override = $apiValue;

And then using that from hook_prep ...

Score: 0
Scultetus avatar
After upgrading, some blocks do not display when the page is reloaded. Is it a cache issue?
om flag

I have an application running on top of Drupal. After upgrading to Drupal version 10.1.0, some blocks are presented once but fail when page is reloaded, displaying a blank page. The pages were created as content and the menu links point to those pages. Blocks are restricted to the corresponding page and must render when the page is displayed. This works perfectly from Drupal 8 to 10.0.10, but in Drupal  ...

Score: 0
Marco von Frieling avatar
Go back button in review step gets misplaced by PayPal smart payment buttons
as flag

I'm using Drupal 10.1 with Commerce 2.36 and a custom checkout flow with the multistep checkout flow plugin. I added Paypal checkout later. On the order information step the "Continue to review" button is rendered inside div.layout-region-checkout-footer and thus gets a bottom margin. But on the review step the "Go back" button/link is rendered after the div.paypal-buttons-container inside the div.layou ...

Score: 0
kazah avatar
Loading webform in modal is too slow
in flag

I have webform with near 130 fields (text, entity checkboxes, radios, composite, etc)

Use it in modal:

<a href="/my-form?title={{node.id}}" class="webform-dialog" data-dialog-options="{&quot;width&quot;:465,&quot;resizable&quot;:&quot;false&quot;,&quot;hide&quot;:&quot;fadeOut&quot;}">click to open</a>    

It tooks near 9 seconds to load it.

Inte ...

Score: 0
Eiki Hanai avatar
Node save button can be clicked while there is still running javascript which leads to unexpected behavior
tk flag

We have Group module installed and a custom field. To be more specific, we can set a value of this field from a dropdown list depending on the selected group.

The behavior is as follows:

  1. Open content creation or editing screen
  2. Select group
  3. Wait until the list of custom values in the dropdown list is updated and select the necessary one
  4. Save

However, there is a problem in such case:

  1. Open content crea ...
Score: 0
Chris Rockwell avatar
Getting existing composer managed site to legacy-project composer managed
de flag

[Update] I seem to be making some actual progress by just replacing the the composer.json with https://github.com/drupal/legacy-project/blob/8.9.x/composer.json and then doing a composer require [all the projects]

I'm trying to clean up an older site that wasn't well cared for with regards to managing composer dependencies. I have deleted the core and vendor directories, and composer.lock and am now t ...

Score: -2
Yehia Gamal avatar
Internal 500 after upgrading the server to Debian 10 with PHP 8.2
pa flag

I haven't dealt with Drupal before, but I needed to upgrade the server from Debian 10 with PHP 7.3 to Debian 12 with PHP 8.2. The website throws 500 errors.

I added debugging lines on the index.php file and I got these errors.

Deprecated: Return type of DrupalCacheArray::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillC ...

Score: 2
How to override a contrib module's FieldType plugin?
cn flag

I'm trying to override a FieldType plugin provided by the Field Encrypt module:

class EncryptedFieldStorageItem extends FieldItemBase {

I created my own class, MyModuleEncryptedFieldStorageItem, and put it in my_module/src/Plugin/Field/FieldType/MyModuleEncryptedFieldStorageItem.php.

Now I need to inform Drupal that I want to override the Field Encrypt module's EncryptedFieldStorageItem class wi ...

Score: 2
How to localize your own contrib module
lc flag

Things have changed since I last localized a Drupal contrib module of mine. In D9/10, having a translations folder with .po files no longer seems to be the usual route. Yes, it can be done for local custom modules by specifying the location in the info.yml but I'm looking for a solution for regular, d.o hosted contrib modules. Right now I don't even need many languages, just one, the (Commerce) module in ...

Score: 0
gmak avatar
Why isn't this working?
cn flag

I'm trying to take the data from a webform submission and create 2 nodes. I've looked at various examples, but I cannot figure out why this isn't working. Can anyone help? Thanks in advance.

My file structure looks like:

srs srs_webform.info.yml srs_webform.module src Plugin WebformHandler SRS_WebformHandler.php

//srs_webform.info.yml
name: SRS Webform
type: module
description: Create Nodes on webform su ...
Score: -5
DevelopmentQueries avatar
Permission Denied and Symlink failed, fallback to use mirroring
ad flag

In the Drupal multisite application, I upgraded to Drupal 10. But when I try to update the database it throws me a permission denied error, so I deleted the contrib, vendor and composer lock file and then ran composer update here symlink fails.

When i run Drush cr it clears the cache but when i run Drush updb it throws an permission denied error.enter image description here

enter image description here

I tried several methods to reoslve the issue https://co ...

Score: 1
alhemist avatar
Why does Drupal harden permissions of the /web/sites/default directory and files?
sh flag

I understand that Drupal hardens permissions of the /web/sites/default directory and its files, each time that the system_requirements() function is called, typically after each composer require operation.
The particular hardening is removing the write permission from the user of the Drupal file tree, and to soften that hardening one would have to do chmod u+w web/sites/default.

If I understand correct ...

Score: 0
drush in ddev says [preflight] Package "drupal/core" is not installed
us flag

Whatever command I run using ddev drush , I am always getting the response " [preflight] Package "drupal/core" is not installed". But drupal is already installed and website is working fine.

Score: 0
Delford Chaffin avatar
Public Access to Private Files
gg flag

I have a content type that allows one or more file attachments and these are set as Private so that access to them can be controlled. A small percentage of these files I also want to be publicly accessible and would prefer not to upload them twice.

Is there a way to either:

  • create a link to a file that bypasses the access control?
  • give the option to choose public/private when the content is created?
  •  ...
Score: -1
DevNooby avatar
How can I alter the value returned from a hook?
nz flag

I installed the Two-factor Authentication (TFA) and the TFA Basic plugins modules.

I want to alter the value returned from tfa_basic_tfa_ready_require(), which is a hook implementation, in a custom module.

/**
 * Implements hook_tfa_ready_require().
 */
function tfa_basic_tfa_ready_require($account) {
  if (tfa_basic_tfa_required($account)) {
    drupal_set_message(t('Login disallowed. You are req ...
Score: 0
alhemist avatar
How to simply inherit all Olivero regions into my sub-theme?
sh flag

I am trying to create a subtheme for the Olivero default theme.

My problem is that not all Olivero regions are inherited into the sub-theme.
For example, some of the regions that are missing are "Content Above" and "Content Below".

To create the sub-theme, in /web/themes I have added the following files:

globalrs.info.yml

name: globalrs
type: theme
core_version_requirement: ^8 || ^9
description: Glo ...
Score: -3
alhemist avatar
I have deleted Redirect module and have lost alias-to-alias redirects as well as the ability to show aliases in some nodes
sh flag

I uninstalled and removed the Redirect module using these commands.

vendor/bin/drush un redirect
composer remove drupal/redirect

This caused me to lose about 15 alias-to-alias redirects.
I have also noticed that now, if I visit /node/1 and click on a link to /node/2, its path alias (/node/my-second-node) is not used.

Would re-installing the Redirect module be enough, or must I retrieve data from a bac ...

Score: 2
alhemist avatar
Is it logical to give a homepage an alias?
sh flag

Drupal allows us to give a URL alias to any node (example.com/my-alias). The "Home page" node is not an exception.

Is it logical to give a homepage an alias?
Shouldn't we just keep it "/"? i.e. without an alias?

The question spans over Drupal logic or web building standards, SEO and user experience. I know it might be a bit to broad, but I think it's worth asking.

Score: 1
fin avatar
Rest API show No route found for GET error
th flag
fin

I'm using Drupal 9.5 to build my api inside my custom module. When I test the API URL on the browser it show me a message

message: "No route found for "GET /api/v1/api_resource""
<?php

namespace Drupal\demo_api\Plugin\rest\resource;

use Drupal\rest\Plugin\ResourceBase;
use Drupal\rest\ResourceResponse;

/**
 * Provides the API resource for the mobile App
 *
 * @RestResource(
 *   id = "demo_api_res ...
Score: 0
Custom datetime field is treated as a string in Views when filtering
cn flag

I have added a datetime field using BaseFieldDefinition::create() to my custom entity:

BaseFieldDefinition::create('datetime')
         ->setLabel(t('Target date'))
         ->setCardinality(1)
         ->setRequired(TRUE)
         ->setSetting('datetime_type', 'datetime')
         ->setDisplayConfigurable('form', FALSE)
         ->setDisplayOptions('form', [
           'type' => 'dat ...
Score: 0
Sarah C avatar
Show field in a Views row as selected in the option for a custom Views Formatter
za flag

I have created a custom Views formatter to make an accordion. Each accordion item is a row. I added a custom field for the user to select which field would be used for the title of the accordion item.

Inside {% for row in rows %} how can I get the value of the field chosen in the options? I thought maybe {{ row.accordion_item_title }} would work, but it does not.

I have seen Theming Views in Drupa ...

Score: 0
Why doesn't the list of modules at /admin/modules show module versions?
in flag

I'm similarly investigating possible causes for /admin/reports/updates never showing any updates except for Drupal core and Zurb Foundation, nothing else is ever listed. composer outdated "drupal/*" shows a ton of available updates. This is Drupal 9.5.9.

Here's the composer file:

{
  "name": "drupal/recommended-project",
  "description": "Project template for Drupal 9 projects with a relocated document ro ...
Score: -2
Tara-Byte avatar
Bulk Upload - which is the best to use
ml flag

My office is migrating from a standard HTML built site to Drupal 10. We have one set of data with corresponding pdf files that is large (over 16k individual entries). We have attempted to use a few of the bulk upload options available but none have worked out. Is there a suggestion on one that would work the best? The data that we need to upload comes has multiple years and a pdf with each entry.

Score: -3
JaSiMi avatar
Modernizr - uncompressed JavaScript and CSS files warning in SEO
bo flag

I'm using Drupal 9.5.9 version.

I have enabled Aggregation for css/js files under "admin/config/development/performance". But, in page view source, I can see, core modernizr js file is not compressed.

Page view source screenshot attached

Due to this one uncompressed js file, am getting more errors/warnings in SEO tool. Can you guide me how to compress/aggregate this file, please?

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.