Questions tagged [9]

Version tags should be used only for questions that apply to a version only, not to merely say what version a site is using.

Filter by
Sorted by
Tagged with
13 votes
3 answers
1k views

Require v8 only contrib module with v9 patch

Given I have Drupal 9 composer installation with composer-patches plugin and given a contrib module with a stable v8 release, but no v9 release (not even dev branch) and given that contrib module has ...
user avatar
  • 4,909
12 votes
2 answers
5k views

Command to install Drupal 9 with Composer

The latest version of Drupal 8 can be installed via Composer with the following command: composer create-project drupal/recommended-project mynewproject What is the equivalent command to install the ...
user avatar
11 votes
1 answer
521 views

Should I use Drush or Drupal Console with a new site?

Between Drush and Drupal Console, which seems to have similar functionalities, which one should I install?
user avatar
9 votes
2 answers
697 views

Use custom content entity theme suggestions in own module?

I have a custom content entity called 'offer'. I've added template_preprocess_offer() and offer_theme() to the offer.module file. function offer_theme($existing, $type, $theme, $path) { return [ ...
user avatar
8 votes
2 answers
847 views

Set SameSite=strict for session cookies

I'm trying to figure out how to set the SameSite cookie attribute for Drupal 8 session cookies, but I can't find a solution. I thought SessionConfiguration might give me enough options, but it seems ...
user avatar
7 votes
2 answers
5k views

How can I verify users the first time they log in?

I was reading this article. I would like to know how logging in with the REST API in Drupal 8 works. By default, when users log in, Drupal will verify username and password. After the login, the ...
user avatar
  • 726
7 votes
3 answers
7k views

How to programmatically assign user roles

I am assigning a role to user by this code: $user = user_load($user->uid); $role = user_role_load_by_name("10-dis"); $user->roles = $user->roles + array($role->rid => $role->name); ...
user avatar
  • 686
6 votes
4 answers
479 views

Is it better to use the latest version released 1 month ago, or use the older but still supported version?

I am going to create a new website: Is it better to use the latest major version recently released, or the previous still-supported version? For example, if Drupal 9 were released one month ago, ...
user avatar
  • 94.1k
6 votes
2 answers
830 views

Is it bad practice to use the same hook twice?

I'm working a quite a big project and I use hook_entity_update() in three of my modules. I do this to keep my project structured and have different functions of my site in different modules. Is it ...
user avatar
  • 892
6 votes
1 answer
202 views

What method should I use instead of Drupal\Core\Entity\Query\Sql\Query::addExpression()?

I am using Entity Query to select nodes of two different types. The fetching seems to be working, but I to sort the returned values. Both the content types have different date fields. I know I could ...
user avatar
  • 101
5 votes
2 answers
919 views

Does the built-in PHP web server have disadvantages over other local development alternatives?

When watching Install Drupal for Local Development, I leant that Drupal 8 and Drupal 9 come with a built-in PHP web server that can be set up quickly by cloning the core and running php -S localhost:...
user avatar
  • 2,498
5 votes
3 answers
574 views

How can I restrict external URLs in link field to allow only certain domains?

After creating a Link field and use the Link with service icon format, I find out that there is no option to restrict external URLs to external domains that I want For example, if I only want to allow ...
user avatar
  • 75
5 votes
1 answer
525 views

How to add a js script as type="module"

How to add type="module" to script added in MODULENAME.libraries.yml when i do: my-library: version: 1.x js: js/App.js: { } I get <script src="/modules/custom/MODULENAME/js/...
user avatar
  • 6,557
5 votes
1 answer
412 views

Locked myself out after enabling misconfigured Google Authenticator

I somehow managed to lock myself out of a Drupal 9 installation after setting up TFA with Google Authenticator login. So, i know my user1 name, my user 1 password, but TFA doesn't allow me backend ...
user avatar
5 votes
1 answer
73 views

Extending contrib module filelog service class displays PSR implementation error

I wanted to override the logger.filelog service from filelog module to make use of my own parser. An error occurred through drush cim and drush cr when the new custom module that overrides the service ...
user avatar
5 votes
0 answers
143 views

How does the Geolocation content of a page filter is a Views block?

I have a website with Drupal 9 and the Geolocation module : https://www.drupal.org/project/geolocation I created a content type with a Geolocation field that contains coordinates. My website uses the ...
user avatar
4 votes
1 answer
486 views

How do I override a single JavaScript file used in a library?

I am trying to override the Search API autocomplete JavaScript file. In mytheme.libraries, I added the following lines. mytheme_autocomplete: js: 'assets/js/autocomplete.js': { } In mytheme....
user avatar
  • 133
4 votes
1 answer
128 views

Mocking Settings (settings.php) within Unit tests

Drupal's Settings class is marked final and has no interface, meaning traditional PHPUnit mocking techniques will not work out of the box. Is it necessary to install third-party tools to be able to ...
user avatar
  • 111
4 votes
1 answer
638 views

What should be used instead of raw filter?

Drupal 9 theming documentation indicates that the Twig raw filter is deprecated in favor of verbatim. The ds-field-expert.html.twig template uses raw to render the input in the prefix and suffix field,...
user avatar
  • 440
4 votes
1 answer
161 views

Drupal 8's last minor release = Drupal 9?

I have read about the planned release date of Drupal 9 is scheduled to be on June 3rd, 2020. I read this documentation about how to prepare a Drupal 8 site for Drupal 9: Prepare a Drupal 8 site for ...
user avatar
  • 143
4 votes
1 answer
107 views

Properly storing an array in a config object

In a config object, I want to store an array of values. The keys matter. The stored value is coming from a checkboxes element, so the array would look something like: ['article' => 'article', 'page'...
user avatar
  • 26.5k
4 votes
1 answer
127 views

Force a single value base field to be in a separate table?

I have a custom entity type (eg: myentitytype), and I would like to add a new base field to it via hook_entity_base_field_info(). As I understand it, single value fields (with a cardinality of 1) will ...
user avatar
  • 733
4 votes
1 answer
388 views

How do I replace drush_set_error()?

Just updating a module for Drupal 9 and Drush 10 and drush_set_error() no longer appears as a function in the Drush code (as far as I can see). What should I be using instead?
user avatar
  • 178
4 votes
1 answer
92 views

Enable layout builder on custom controller page

I created a simple page in a controller class: public function taxonomyPage($term) { return [ '#type' => 'markup', '#markup' => $this->t('<p>Need to render layout ...
user avatar
4 votes
2 answers
382 views

What is the stable9 theme? When should I use it instead of stable?

https://www.drupal.org/node/3066038 Has this cryptic statement: However, defaulting to base theme: stable prevents automatic updates to the next major version of Drupal, since each major version may ...
user avatar
4 votes
2 answers
61 views

Alter comment pager to jump to comment section right away?

I set up a content type and a specific comment type for this content. I set the comment pager to display 10 comments per page. When I now use the pager, I get redirected from the node URL itself www....
user avatar
4 votes
1 answer
123 views

How to prevent a node from being deleted while performing a delete operation?

I want to prevent a node from being deleted while a delete operation is performed on it. For example in administration panel if user clicks "Delete" on the node, the node shouldn't be ...
user avatar
4 votes
1 answer
50 views

What is the difference between Translation language, Translation source, and Original language?

Would anyone be able to explain to me what the difference is between "Original language", "Translation language", and "Translation source"? I think I have a pretty good ...
user avatar
4 votes
1 answer
128 views

How can I have Behat create content with an address field properly filled?

I'm writting a Behat test, where I'm triying to create a content that uses a field address, generated by Address Module. I'm using Drupal 9.0.7, Address Module 1.9.0 and behat 3.8.1. My goal is to ...
user avatar
3 votes
2 answers
533 views

How can I replace a string in a text?

With {{ content.field_myfield.0 }}, I get a text. When I use {{ content.field_myfield.0|replace({"foo" : "bar"}) }}, nothing is rendered and no errors are reported. I also tried ...
user avatar
  • 133
3 votes
3 answers
3k views

Upgrade Devel module and disable Kint

When upgrading from Devel 8.x-2.x to Devel 8.x-4.x in a composer based build, how do I handle the Kint module being removed per Remove Kint module and create a kint dumper plugin in devel? The service ...
user avatar
  • 263
3 votes
1 answer
125 views

How to get the field name in a validation handler?

I have a custom class TextWidget extends WidgetBase Inside it I have a custom validation handler that looks like this: public function validate($element, FormStateInterface $form_state) { $value = $...
user avatar
  • 14.8k
3 votes
3 answers
132 views

DrupalDateTime::createFromFormat() returns the wrong time value

I want to get the date of last monday at 00:00:00 in a specific timezone. When I try this: DrupalDateTime::createFromFormat('U', strtotime('last week monday'))->setTime(0, 0, 0)->setTimezone(new ...
user avatar
  • 26.5k
3 votes
1 answer
173 views

Difference between drupal-composer vs drupal-recommended

drupal-composer/drupal-project drupal/recommended-project Which one is the best option to choose & why? on Drupal 9 composer create-project drupal/recommended-project: /vendor: 4485 files, ~21 ...
user avatar
3 votes
1 answer
868 views

How can I use core's WebP support instead of the WebP module?

According to the change record, Drupal 9.2 supports WebP for better image compression. I've been using the WebP module on my 9.1 site to serve WebP images, but it has a performance-killing bug and I ...
user avatar
3 votes
1 answer
340 views

Reverse entity reference lookup

I have a data structure where content type research has an entity reference field scientists. The content type scientists does not have any research reference entity field though. I can get all ...
user avatar
  • 263
3 votes
2 answers
165 views

How to not show the "has been created" message? [duplicate]

I want to remove the message that is output in the message area when a new node is created. A typical message may look like this. "Article My article has been created." I examine the node ...
user avatar
  • 14.8k
3 votes
1 answer
75 views

How can I override the node template for one multi-site instance?

I have several Drupal 9 sites on multi-site setup. currently all these sub sites use one theme placed in /themes/MyTheme folder. now i need to theme few nodes on site A and site B and this is only ...
user avatar
  • 1,019
3 votes
1 answer
177 views

Custom 404 handling for images

I'm looking for a way to handle 404's on images in Drupal. I have created several subscribers, but none seem to get triggered. My first try was to create subscriber that extends RouteSubscriberBase. ...
user avatar
  • 185
3 votes
1 answer
352 views

Can we add custom CSS class in \Drupal::messenger()->addStatus()?

I did some research regarding adding custom CSS classes in the message but could not find the actual solution. As per Drupal 9 documentation: \Drupal::messenger()->addMessage(t($message)); public ...
user avatar
  • 129
3 votes
1 answer
324 views

How to properly manage field types for a content type created by a module?

I'm a bit confused about two different errors I get, which seem to contradict each other. I guess I didn't register my field types properly. The first one appears when I try to uninstall my module. ...
user avatar
3 votes
1 answer
452 views

Add webform field programmatically

In older versions of Webform (Drupal 7), the function webform_component_insert() can be used to add fields to a webform, for example inside a hook_node_insert() implementation, so they are added when ...
user avatar
  • 2,041
3 votes
2 answers
70 views

String substitution in Views Contextual filter parameter?

In Drupal 9, I have a View called News. The View is displayed at the following path: /news I can edit it at the following path: /admin/structure/views/view/news/edit It has the following Contextual ...
user avatar
  • 1,939
3 votes
1 answer
99 views

Exclude settings from a contrib module on export

I've two environment, dev and staging. I'm using the ReCaptcha module. In the developpement environment, I have some api keys a other config which until now, are exported thanks to drush cex inside ...
user avatar
  • 43
3 votes
2 answers
701 views

How can I query by node title?

In Drupal 7 I had this code to query node fields and its respective title: $query = db_select('node', 'n'); $query->join('field_data_field_internal_institute_paper_i', 'iipi', 'n.nid = iipi....
user avatar
  • 263
3 votes
1 answer
449 views

Disable caching for a front page path processor

I’m working on a project where users can create a book (core functionality). In a simple text field they can connect a domain to this book. This way the book is only accessible via this domain. For ...
user avatar
  • 892
3 votes
1 answer
583 views

Date Field Type - Text Field Widget is Gone?

I am noticing that the Date field type only has the availability of three widgets: Select list Date and time Select list, no time Can someone tell me why the "Text Field" widget is gone? ...
user avatar
3 votes
1 answer
24 views

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

Do I need to sanitize $userinput in this code, Or is it done by Drupal? $nids = \Drupal::entityQuery('node') ->condition('type','my_node_type') ->condition('field_myfield', $userinput) -&...
user avatar
  • 59
3 votes
1 answer
118 views

Which is better way of injecting service to controller with __construct or $instance = parent::create($container)

I'm always using this way of injecting service to controller: <?php namespace Drupal\TestModule\Controller; use Drupal\Core\Controller\ControllerBase; use Symfony\Component\...
user avatar
  • 31
3 votes
2 answers
137 views

How to create a new parent section on the Configuration page?

When one navigates to Manage » Configuration, the page is divided into sections which (in the "Seven" theme at least) shows up in individual boxes. These sections have headings like "...
user avatar
  • 14.8k

1
2 3 4 5
24