Latest Drupal related questions

Score: 0
liquidcms avatar
Why does adding #element_validate give warning about invalid callback?
us flag

I have code that adds #element_validate to all fields of a certain type (Link fields).

$form[$field_name]['widget'][0]['#element_validate'][] = '_fix_link_field_value';
array_unshift($form[$field_name]['widget'][0]['uri']['#element_validate'][0], '_fix_link_field_value');

This works fine, but I get this warning in the logs every time an entity with this field type is saved.

Warning: call_user_func_ar ...

Score: 0
Generating forms dynamically from json data
pt flag

I have a large set of JSON data which I need to process somehow into forms for users to interact with, fill in data and submit.

However, there are far too many to create all the forms by hand and I wonder if anyone can recommend a module/package which I can use to create such large number of forms dynamically.

Below is a very small sample section of json data, each section in the json needs to be pr ...

Score: -4
LeJuanChis avatar
Error importing configuration
pa flag

[error] Drupal\Core\Config\ConfigImporterException: There were errors validating the config synchronization.

The <em class="placeholder">language.content_settings.media.instagram</em> setting depends on the <em class="placeholder">media.type.instagram</em> setting which will not exist after import.
The <em class="placeholder">medical_network.settings</em> setting ...
Score: 0
Giuseppe avatar
How get the language the current language for a REST request considering detection\selection settings?
br flag

I'm on D.9.4.x.

I'm writing a custom REST resource and I'd need to get the "current language id", in compliance with the "Detection and selection" site's settings (screenshot below).

I can't find a service\method that gives this information. I could e.g.

$user_language = $this->currentUser->getPreferredAdminLangcode();

and that would work with the current settings, but would be not anymore correc ...

Score: 0
Joost avatar
Sort views by number of related tags
jp flag

I want to create a view block with related content based on shared terms. For this I created a term reference field inside the content type and created a views where I use a contextual filter Taxonomy term - ID to fetch all nodes sharing the samen terms. I also added a contextual filter to excluded the current node using Content: ID.

This all works great, but I now want to sort the view by the nu ...

Score: 1
Eric Sorum avatar
Comments form won't appear
ax flag

I'm switching a website from Disqus back to the regular Comment module. After installing the module, I can configure it just fine as an administrator and add comments on some dummy articles. But when I test it out as an anonymous user or sign in as an authenticated user, I'm unable to write comments. I can see the comments, but the form to write comments just isn't there.

I ensured that all users ...

Score: 0
gMaximus avatar
How to add/install a new field to all bundles of certain entity types?
sa flag

I need to add a new string field called instagram_owner to all bundles of nodes, media and file entities. If new bundles are created, I need the field on them too. This is what I have so far in my MODULE_NAME.module file.

use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Entity\EntityTypeBundleInfo;
use Drupal\Core\Entity\EntityFieldMan ...
Score: 0
arrr_matey avatar
Excluding individual page components from caching
cn flag

I can't seem to find a straight answer online about whether it is possible to exclude just one component of a page from being cached.

My component appears on all pages of the site and comes from a custom theme function rendered in page.html.twig from the following in mytheme_preprocess_page:

$alerts_renderable = [
'#theme' => 'my_alerts',
];
$variables['alerts'] = $alerts_renderable;

I've tried add ...

Score: 0
Alejandro avatar
Add theme suggestion to a node depending on the menu it belongs to
fj flag

I have a mega menu that displays child menu items when you click on a parent menu item in form of a drop-down menu. The thing is that, this menu, also displays cards as nodes and I want to add a theme suggestion only to this card nodes that are inside the menu drop-down.

I can get the node with a simple MYTHEME_theme_suggestions_node_alter() hook but I don't know how to get the menu item of it.

I ...

Score: 0
Shawn W avatar
How to target buttons to add a new paragraph field
cn flag

In a form_alter hook I'm trying to target the buttons to add a new paragraph but can't seem to target the specific buttons. The buttons are multiple entity references with unlimited cardinality, but for my use case I would like for once one entity is chosen, only that entity can be chosen again in the repeater, which is why I'm trying to disable the other buttons. I want to allow unlimited cardinality  ...

Score: 1
Alejandro avatar
Provide theme suggestions for menu content items
fj flag

For a mega menu, I'm trying to add theme suggestions to every parent menu item / menu link depending on the chosen view mode for that menu item.

I'm aware of the MYTHEME_theme_suggestions_menu_link_content_alter() function but it does not work for me.

Every menu item has a view mode field but since I can't use a hook to preprocess it, I cannot create any theme suggestion for menu items .When I try to us ...

Score: 1
Redirect user to a custom page after one time login
kn flag

If my user click to "forgot password", and email with a one-time login is sended.

When the user clicks the given link, he's redirected to this page /user/reset/$id with the user_pass_reset form (basically containing a single button for the one-time login)

I'd like to redirect to a custom page after the user clicked on the one-time login button, but can't find out why this code doesn't works

/**
 *  ...
Score: 0
Sergey avatar
How to change TIMEOUT for Drush command
us flag

I am working on a website with an extremely heavy database.

As a result, the command drush sql-cli < [db_filename] takes more than default value of 14400 seconds.

I need to find a way how to change this value properly.

I found put that the function I need is setTimeout() from the vendor/symfony/process/Process.php.
I can use it directly in vendor/drush/drush/src/Commands/sql/SqlCommands.php li ...

Score: 0
Shawn W avatar
How to disable or remove entity references with unlimited cardinality once one entity reference is chosen
cn flag

I have a paragraphs field that references multiple entity references with unlimited cardinality. I want to disable or remove the other options once one of the entities is selected. The use case is for a card grid component, only one card type should be available for the grid, so on select I would like to get rid of the additional options. The card grid should essentially only allow for one type of ent ...

Score: 0
Imti avatar
issue in construct function for dependency injection
pl flag

error I am getting : CreateApplicationService::__construct(), 0 passed in C:\xampp\htdocs\drupalwebsite\core\lib\Drupal\Component\DependencyInjection\Container.php on line 262 and exactly 1 expected

I have this below code:

enter image description here

nots sure what is the issue in the construct function. I have done the same POC in another module where I called from form.php and it works. Not sure what I am missing here?

Score: 2
Free Radical avatar
How to hide the comment subject field?
kz flag

In Drupal 7, there used to be a checkbox: "Allow comment title". Unchecking that, and there was no comment title.

I am unable to locate a similar setting in Drupal 9.

I've found: How to remove or hide the Subject field for comments?

It explains how to auto-generate the subject field for a comment. This is not what I am asking. I don't want to display any subject field when showing a comment. If y ...

Score: 1
Thony avatar
Is it possible to override a template from the module where the original is declared
cm flag

I'd like, from within a single module, to have several 'api_field' template depending of the 'field_name' (including the default 'api-field.html.twig' )

Like api-field--country.html.twig, api-field--date.html.twig...

So i did this

/**
 * Implements hook_theme().
 */
function HOOK_block_table_theme($existing, $type, $theme, $path) {
  return [
    'api_field' => [
      'variables' => [
        'fie ...
Score: 1
HarshB avatar
TMGMT translations are not accepted when there is a pending revision in the default translation
sh flag

Can someone please help with TMGMT (8.x-1.14) and Paragraphs (8.x-1.15) modules working together in Drupal 9.4.8 setup.

There is a content type having a Paragraph entity reference revision field. Consider a node is already published. I made a change to the node and Requested for a translation, say JP. I worked on the translation and got it reviewed. Remember that the Original language content is  ...

Score: 0
user108676 avatar
Automatically change the status of Commerce Order
ss flag

Modules Commerce 2 Order and Commerce Shipping Carrier. Can I automatically change the status of order to completed (commerce_order.workflows.yml) when I press the "Send shipment" button (commerce_shipping.workflows.yml)

Score: -1
MK. avatar
upgrade 8.5.15 to 8.9.20 failing
uy flag
MK.

After the upgrade (done via composer) I get the following stack trace:

InvalidArgumentException: Field reusable is unknown. in Drupal\Core\Entity\ContentEntityBase->getTranslatedField() (line 587 of core/lib/Drupal/Core/Entity/ContentEntityBase.php).

Drupal\Core\Entity\ContentEntityBase->get('reusable') (Line: 308)
Drupal\block_content\Entity\BlockContent->isReusable() (Line: 68)
Drupal\b ...
Score: 0
Laurent Gravez avatar
How do I create bidirectional entity references?
th flag

How can I create a bidirectional link in a drupal entity? Let me explain, I have a content type called "software" in which I have a field (entity reference) called "article". When I create my "software" content, Drupal automatically creates a link to my "article" content type, which is fine, but I would like a link to be created in the opposite direction from my "article" content type to my "software" c ...

Score: 0
Iza avatar
Creating dynamic controllers for the same route
bj flag
Iza

I have a route defined as

my_node_action.go:
  path: '/node/{node}/go'
  defaults:
    _title_callback: '\Drupal\my_node_action\Form\Go::title'
    _form: '\Drupal\my_node_action\Form\Go'
  options:
    parameters:
      node:
        type: entity:node
  requirements:
    _user_is_logged_in: 'TRUE'

where Go is extending FormBase.

I want to add 2 different classes: NodeType1Go and NodeType2Go which exte ...

Score: 2
Sujan Shrestha avatar
Why cannot I push code on the project I created?
jp flag

I have created a project on drupal.org. The repository for this project is empty message is shown on the repository page.

screenshot

I used to get the Git push instructions on previous days.

I tried to clone the repository using either the [email protected]:project/ or the https://git.drupalcode.org/project/ link, but I get this error when I run git push -u origin master.

remote:
remote: You are not a ...

Score: -2
user31782 avatar
How to load a dependency in the in drupal 9?
nc flag

I have followed the official documentation, but it doesn't work

global-styling:
  version: VERSION
  js:
    js/bootstrap.min.js: {}
    js/custom.js: {}
    
  css:
    component:
      css/style.css: {weight: 50}
  dependencies:
    - core/drupalSettings
    - core/jquery
    - core/jquery.once
    - core/drupal
    - core/popperjs
    - my_theme/fontawesome


fontawesome:
  js-header:
    header: tru ...
Score: 0
zack cv avatar
How To Resolve Commerce Button Returning Error?
eu flag

I'm using the latest stable version of Drupal Commerce (on Drupal 9), with every module up to date

Problem: When the add to cart button is clicked the site returns message "The website encountered an unexpected error. Please try again later." When I check the log messages it displays the error "Exception: The given entity is not assigned to any store."

Commerce setup

  • Drupal Commerce's architecture, se ...
Score: 0
How can I prevent renaming of files uploaded with JSON:API for a specific field/filename?
cn flag

I created a Profile photo image field on the user entity. This is for a decoupled site where users upload files with JSON:API.

The file field is configured like this:

  • File directory: profile-pics/[current-user:uid]

My app always uploads the file as profile_photo.jpg. But, each time the user uploads a file, it gets renamed: profile_photo_0.jpg, profile_photo_1.jpg, and so on.

If the user uploads a  ...

Score: 0
KVF-IT avatar
I can't load inline jQuery
in flag

I have a Drupal 9 page, where I am trying to load some inline jQuery code, from CKEditor, but it isn't working and I am not getting any error on the console.

This worked perfectly in Drupal 8.

<script>
 window.onload = function() {
  jQuery('.className').fadeOut();
  console.log("HI");
 };
</script>
Score: 0
unity_of_opposites avatar
I am logged in as admin user but I get a message saying I am not authorised to access the Update or Install pages
bf flag

I am not able as user 1 to access the 'Extend -> Update' or 'Extend -> Install new module' pages (I can, however, access the 'Extend -> Uninstall' page). This has only started happening in the last few days.The message I get is:

Access denied You are not authorized to access this page.

I am on a Drupal 9.4.8 distro running on a Siteground remote server. This has only started happening in the l ...

Score: 0
Jonathan1055 avatar
How to run drush using locally modified repo (from github fork)
sy flag

I have my own drush repo forked from https://github.com/drush-ops/drush and have a local clone of this, as I want to start modifying and potentially push back to add a new function. How do I configure a local drupal site to use my local repo? I have tried replacing vendor/drush with a symlink to my repo but that produced the following

PHP Fatal error:
Declaration of DrupalCodeGenerator\Command\Dru ...
Score: 0
user7167081 avatar
How do I load the Bootstrap CSS into a CKEditor template?
cg flag

Just how we add custom theme style, I want to add Bootstrap CSS. Is there a way to do it?

/**
 * Implements hook_ckeditor_css_alter().
 */
function mymodule_ckeditor_css_alter(array &$css, Editor $editor) {
  $css[] = \Drupal::service('extension.list.theme')->getPath('my_theme') . '/css/styles.css';
}

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.