Hot answers tagged

6 votes

Difference between drupal-composer vs drupal-recommended

The important difference is that you should use drupal/recommended-project as it is recommended and officially supported. drupal-composer/drupal-project is outdated for Drupal 8+ and should only be ...
user avatar
  • 7,123
4 votes

DrupalDateTime::createFromFormat() returns the wrong time value

I can see nothing unexpected. Midnight in UTC is 8 PM the day before in New York, at least in the summer time. Timestamps are always UTC. This is the reason why your second attempt $from = ...
user avatar
  • 88k
3 votes

Convert field from string_long to text_long

Here's the solution I came up with based on the example code provided by https://drupal.stackexchange.com/users/71454/miststudent2011. I had to adapt it a bit for this specific case: /** * Convert ...
user avatar
  • 640
3 votes
Accepted

Behaviors are only executed on some pages, while on others jQuery is not defined

Your inconsistent results are because core/jquery is being included on some pages by other libraries, and in these cases everything works fine, but you're seeing errors when there is no other library ...
user avatar
  • 7,123
3 votes

Lando local dev site tabs link to live

@Clive's comment was on track. I'm using the Domain modules and under Domain Source Settings, it was not set to disable link rewrites for these routes. This site is 2 years old now and I don't recall ...
user avatar
3 votes
Accepted

Do I have to sanitize value parameters in a QueryInterface::condition statement?

As shown in Writing secure code for Drupal / Use the database abstraction layer to avoid SQL injection attacks, it's not necessary to sanitize user input used in the condition() method, as long as the ...
user avatar
  • 94.1k
3 votes
Accepted

How can I hide a block from regions?

Block configuration entities need a region, but not blocks in general. Twig Tweak can generate the block config on the fly and doesn't need them to be stored in the database: {{ drupal_block('...
user avatar
  • 88k
2 votes
Accepted

Why Drupal is slow on WSL

Not exactly Drupal related, but nonetheless: If you are on WSL1, upgrade to WSL2. The reason for the slowness is WSL itself. There is a file performance IO penalty on Mac and Windows due to how ...
user avatar
  • 26.5k
2 votes

Add a placeholder to search input text field

Thanks for your help @Kevin So I edited my (MYTHEME).theme file and added that and it works: function mytheme_form_search_block_form_alter(&$form, &$form_state) { $form['keys']['#attributes']...
user avatar
2 votes
Accepted

Configuration import continues to list items as 'importable'

This happens, unfortunately. It can happen by a module that was enabled in the past and it changes the configuration but wasn't refreshed by the developer. Most of the time this appears when you ...
user avatar
2 votes
Accepted

What does scaffolding files for drupal/core do when I do a composer require <module>?

The purpose of scaffolding files is to allow Drupal sites to be fully managed by Composer, and still allow individual asset files to be placed in arbitrary locations. From: https://github.com/drupal/...
user avatar
  • 14.7k
2 votes

How can I add Composer to an existing site?

The linked documentation says: For sites created on Drupal 8.8.0 or later Even if you installed Drupal 8.8.0 from the tarball, Composer was pre-installed. So you should be able to manage your site ...
user avatar
  • 88k
2 votes

Run hook_preprocess_node only for main page

If the other nodes are rendered using a different view mode, you can check that $variables['view_mode'] is 'full' or the view mode used for rending nodes on /node/[nid]. Otherwise, you can verify the ...
user avatar
  • 94.1k
2 votes

Embedding a text chunk in the text-area of two or more nodes

This is an answer to the original question of "How to put a node of content type B inside a node of content type A?" There are a lot of ways to do this, but the most common is probably an ...
user avatar
1 vote

How can i preprocess variables php to js

To pass data from PHP to javascript, you need to attach the data to the render array of your block (or alternatively to some other render array via preprocess functions). You can see an example here: ...
user avatar
  • 2,690
1 vote

DrupalDateTime::createFromFormat() returns the wrong time value

DrupalDateTime::createFromFormat() is basically a wrapper for PHP's createFromFormat. A search of the PHP docs reveals this comment: createFromFormat('U') has a strange behaviour: it ignores the ...
user avatar
1 vote

DrupalDateTime::createFromFormat() returns the wrong time value

I tried different snippets, but they all output a time for June 12, not for June 13. echo DrupalDateTime::createFromFormat('U', strtotime('last week monday'), new \DateTimeZone('America/New_York')) -...
user avatar
  • 94.1k
1 vote

How to set value on drush updb running and get that value on hook_update_N, to call specific function?

It's not possible because drush updb doesn't accept a parameter that is passed to hook_update_N() implementations, which makes sense, since the only parameter accepted from hook_update_N() is an array ...
user avatar
  • 94.1k
1 vote
Accepted

AnnotationException for no apparent reason

If @Annotation is missing from the documentation comment for the Drupal\language\Annotation\LanguageNegotiation, in the file containing that class, then it's a problem of corrupted files that need to ...
user avatar
  • 94.1k
1 vote

AnnotationException for no apparent reason

When I look at my Drupal 9.4.0 code the class "Drupal\language\Annotation\LanguageNegotiation" is annotated with @Annotation: web/core/modules/language/src/Annotation/LanguageNegotiation.php ...
user avatar
  • 88k
1 vote
Accepted

Installing configuration from a module that is tracked in configuration on deployment

You have to remove the module’s exported config first then re-add it along with the module activation. Technically all you have to do is remove the module’s configuration from active configuration, ...
user avatar
  • 2,790
1 vote

Programmatic webform redirect on submission not redirecting

The issue was the setting in the UI for the webform confirmation. Instead of selecting redirect to a URL (which is actually what it needs to do), 'none' should be selected, which then adds a ...
user avatar
1 vote

Error with Entity Bundle Classes

Entity bundle classes go in /mymodule/src/Entity/Bundle/MyClass.php. To easily generate the bundle class and see what may be wrong, try the drush command drush generate entity:bundle-class and follow ...
user avatar
1 vote

How to show a view instead of the node when the user click on the title

The way I see it, you have two options here: Replace the front page with a view of nodes, in the view render fields, and set the title of the display to link to the subsite for the node. Use ...
user avatar
  • 14.7k
1 vote
Accepted

How to display in a block the media used in a node?

Media images that are embedded with CKEditor into a text field are referenced using <drupal-media> tags. These tags are parsed by an input filter when the node is rendered. So, as far as I ...
user avatar
1 vote

How to add class to paragraph fields through preprocess hook?

Come from the other way. Come from the field. Check the parent entity (paragraph) type and then add the classes: /** * Implements hook_preprocess_HOOK(). */ function ...
user avatar
  • 15.9k
1 vote

Trim or strip spaces around the email or username on the login page

In your_module.module You create form alter if there is no any (e.g. HOOK_form_FORM_ID_alter()) you add a validation callback to a field of the whole form (e.g. array_unshift($form['#validate'], '...
user avatar
  • 239
1 vote
Accepted

Create custom admin theme removes theme-primary-local-tasks from admin view

When you install a theme Drupal tries to build a block layout automatically, but the result only works for front-end themes. For admin themes you need to provide a default block layout. See the ...
user avatar
  • 88k
1 vote

Always keep admin UI in the same language when translating content

Enable Account administration pages in language detection (don't change the priorities, the setup out-of-the-box is optimal). This adds a second language selector for admin pages to the user profile. ...
user avatar
  • 88k
1 vote
Accepted

Broken Image styles don't generate

I was using the "convert" effect on all image styles on my website which has an issue in Drupal 9. This patch fixed the issue for me.
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible