Questions tagged as ['9']

In Drupal 8, my custom module includes the code
if (\Drupal::service('path.alias_storage')->aliasExists($path, 'en')) {
return true;
}
What should this look like in Drupal 9.2? Seems so simple, but I can't figure it out after reading every post I can find.
I have a multilingual website with taxonomy vocabulary, which terms are not translatable (company names).
But each term has translated meta tags and paths, depending on the selected site language.
For example, term paths:
- /vocab-name/term-name (default, english)
- /de/vocab-name/term-name
- /es/vocab-name/term-name
- /it/vocab-name/term-name
- etc
I can access all of them, metatags are displayed in the c ...
I'm on D9 and I've a paragraph inside a content type node.
I need to hook when the paragraph is deleted to do some custom logic and set up a queue.
I've tried hook_entity_delete
, hook_entity_predelete
or hook_paragraph_delete
, hook_paragraph_predelete
: those hooks run during cron, if the node containing the paragraph is deleted.
However, it seems to me those aren't triggered if an existing paragraph ...
There is a drupal 9 site that has a REST-endpoint that can be accessed for logged-in users (not for anonymous ones).
And, it's necessary to make a GET request to the endpoint using cookie authentication.
Could you clarify, what the correct algorithm of this request is?
I tried to do it two ways.
Way #1.
Send a POST-request to user/login with credentials and get CSRF-token, then use the token in hea ...
I am trying to migrate html code into multiple paragraphs that need to be linked together somehow. My idea is to have them linked my ID that comes from the dataset, maybe using that ID as second source. My code currently creates multiple paragraphs but there is no link between them. The data comes form csv an I am using Drupal 9
TLDR: How to map one column from csv file into multiple rows in mapp ...
I am creating a custom views filter for a custom views field. The following SQL will accomplish the filter I seek:
select nid, moderation_state, content_entity_id, MAX(content_entity_revision_id)
from node inner join content_moderation_state_field_revision on nid = content_entity_id
where content_entity_id = 59 group by content_entity_id
In my views filter plugin php file, I have the followin ...
I have a submit handler to the user form. It redirect the user to a specific page.
use Symfony\Component\HttpFoundation\RedirectResponse as RedirectResponse;
/**
* @file
* Primary module hooks for EHESS Propositions 3 module.
*
* @DCG
* This file is no longer required in Drupal 8.
* @see https://www.drupal.org/node/2217931
*/
function ehess_propositions_3_form_alter(&$form, &$form_s ...
On my Drupal 9 site and Group module. I created a type of group "Blog". I want that in a group, only one node of type "Article" can be added.
How to limit the addition of a single node in a Group?
So a maximum "Article" type node per group.
I have a site with Drupal 9. I have created a taxonomy and I want to personalize the terms pages. In Drupal, there is a view for that, but if I change it, I change all the taxonomy term pages.
I want to create a view to customize each page of the terms. How can I achieve this?
On my Drupal 9 site, I created taxonomy terms in the "tags" vocabulary (the vocabulary and the default field of the "article" content type) :
When I create a node, I select a taxonomy term in the form (for example "ICO"). The node displays the "tags" field :
I want that if the node has the term "ICO", it also displays the parent terms. Like this :
Catégories : Culture geek, crypto, ICO
How can ...

When a comment is submitted, no confirmation message is shown and I would like to achieve this. I want to show the following message.
Your comment has been added for review and approval.
I tried this code.
function mymod_form_alter(&$form, FormStateInterface $form_state, $form_id) {
else if ($form_id == 'comment_comment_form') {
$form['actions']['submit']['#value'] = "your comment has been ...
I have a content type with a field, which contains HTML data (a short article).
When viewing a node, I want to have a link (or button, doesn't matter), which will open a modal dialog with the value of this field when clicked.
Content of the modal (fields value) has to be loaded dynamically. In other words, the content of the modal should be loaded in DOM only when (and if) the link is clicked.
This is ...
I have a custom node creation form I am rendering within a views preprocess hook. In that form I have two entity reference fields. I am setting the [#value] and [#default_value] of those reference fields programmatically.
On form submit the values I've set are created, but only if the fields are "editable" by the user. I want to make the fields "disabled" and/or "hidden" from the user. Not just h ...

Is there a way to alter the render array of an existing block? I want to do it for a commerce block (cart block) but the question remains for any core or contrib module block.
When a block uses a custom #theme for it's block, is there a way to alter the definition?
Let's say the module defines the following theme :
/**
* Implements hook_theme().
*/
function commerce_cart_theme($existing, $type, $theme, ...
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 have a different version of "the stable theme"
and proceeds to list these without any explanation.
The READMEs in the relevant directories are no help.
Warning: Themes that opt out of using Stable as ...
D9.3. All fields are not referenced, they are just simple integers. All data was pulled from a huge external API and it was not possible to create all references.
Just for ease of understanding, imagine a book database website with books and characters. But each character is presented in one book only.
So, book node has field_book_id
, which is numeric, unique, but not NID. Also it has a multiple ...

How can I programmatically remove blocks and other elements from a single custom template ?
In my custom modle I have defined a route to a controller which then loads a template which is also contained within the same module. I am successfully loading data from the controller into the template.
My issue is that the template inherits blocks and menu from the active theme which I need to remove but on ...

On my site (drupal 9.2.8) users add content and there is no need to put any information to 'Title' field. I was trying to make this field not required via form_alter in custom module but it did not work:
function yourmodule_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id){
if ($form['#form_id'] == 'node_somenode_form' or $form['#form_id'] == 'node_somenode_form') ...

If I understood correctly, "decoupling" a content management system means separating backend from frontend (having two "modules" for each under the same "program").
If I understood correctly, "headlessing" a content management system is making it to be possible to supply content to at least two different front-end interfaces at once ("two different programs" as may appear to an end user).
I would as ...

I'm reaching out because I just can't find out why my custom datetime field isn't saving its value after I submit.
Context:
I've created a field containing two datetime fields. I will use it to add or remove events from an event list, depending on whether they have passed or not (for example if a festival is scheduled from the 12 to the 14 of December, the event will be removed after the 14th).
Events in ...
Working on a Drupal 9 website the module Permissions by term gives an unexpected behaviour.
Trying to find the problem I got stuck. I think there might be another module overwriting the permissions. But I can’t find out which one.
Is there a way to see which module grants what right to a node/user?
Or is there another step I should do to debug these node permissions?
Thanks a lot!
I'm using migrate/migrate_plus modules to import CSV files and generate entities.
One of the columns in the CSV can contain multiple values like 1|2|3, which I'm converting to an array using:
_jurisdictions:
plugin: explode
source: jurisdiction
delimiter: "|"
I'm then using the array to generate taxonomy terms with this:
field_political_district:
-
plugin: entity_generate
source: "@_ ...
I'm on D9. I've a paragraph with a Link field. I need to get the referenced entity programmatically.
What I've managed so far is:
$nid = NULL;
$field_link = $paragraph->get('field_link')->first();
$route_params = $field_link->getUrl()->getRouteParameters();
if(isset($route_params['node'])) {
$nid = $route_params['node'];
}
if($ni ...
I want to add a simple filter to an existing view in Drupal 9. It appears that I can achieve this with hook_views_pre_view()
. In every example I can find, including all the "Similar questions" links that come up when entering the title of this post, I see that $view->add_item()
is used. See: Add views exposed filter programmatically
However, when I try to run this code:
function sbn_views_pre_view($vi ...

I am creating a custom block plugin with custom configuration options (blockForm()
).
I would like to allow content editors to edit the configuration of this block, without giving them "administer blocks" permission. Also, I don't want them to create new block instances..
I would like to avoid installing an additional module like block_permissions, as this would introduce a wide range of settings or pe ...

I am creating a Node
programatically:
Node::create([
'title' => "Some name",
'type' => "people",
'body' => $params['body'],
'field_people_degree' => $params['field_people_degree'],
'field_people_email' => $params['field_people_email'],
'field_field_image' => ['target_id' => $this->createImageFile($params['field_field_image'], $params['field_pub_tool_id'])->id()],
' ...
I used to create my solr instance for drupal like this:
docker run -v $PWD/solrconf:/asdentcore -e SOLR_JAVA_MEM="-Xms2G -Xmx2G" --restart unless-stopped -p 8984:8983 -t --name asdentDevSolr -d solr:8.11
docker exec -it --user=solr asdentDevSolr bin/solr create_core -c asdentcore -d /asdentcore
Where ./solrconf contains the files from modules/contrib/search_api_solr/solr-conf-templates/7.x.
With the n ...

I created a custom block with an entity reference to a media field (field_background_image).
In the display settings I have chosen 'Thumbnail' as format and selected a custom image style 'background'.
In my _preprocess_block(&$variables)
function I would like to get the selected format (thumbnail) and especially the selected image style ('background').
How can I load both these information from the $v ...
Using \Drupal::routeMatch()->getParameter()
, it's possible to fetch objects that come from the parameters of the URL.
I'm wondering if it is possible to add values to the routeMatch. For example, if using the Groups module, nodes may be part of a group, however the group is not part of the path. Is there a way to load the group from the node, and add the group to the parameters that can be retrieved ...
I need to add tags as taxonomy terms to already created nodes in 7 languages.
If I do this:
$node = Node::load($nid);
$node->set('field_tags', getTerms($terms));
$node->save();
Just default node in English is updated, however, all terms are created in all languages.
getTerms() - is my own function, which is getting term ids and creating them if they don't exist.
I need to update all node transla ...