Questions tagged as ['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.
Score: 2
How to check if path alias exists
in flag

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.

Score: 0
bigboy avatar
How to get language prefix in URL for terms without translation?
gu flag

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 ...

Score: 1
Giuseppe avatar
How to hook on paragraph deletion?
br flag

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 ...

Score: 0
Yakimkin Roman avatar
The sequence of actions upon cookie-authentication to Drupal site
jp flag

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 ...

Score: 0
finnishNinja avatar
Migrating one field into multiple rows
kn flag

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 ...

Score: 0
SomebodySysop avatar
How to use sql MAX() function in views plugin query
gb flag

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 ...

Score: 0
Frédéric Hébert avatar
specific submit handler to user form
us flag

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 ...
Score: 0
mathieu avatar
How to limit the addition of a single node in a Group?
mw flag

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.

Score: 0
mathieu avatar
How can I customize each of the taxonomy term pages?
mw flag

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?

Score: 1
mathieu avatar
How to display the parent taxonomy term of the "Tags" field?
mw flag

On my Drupal 9 site, I created taxonomy terms in the "tags" vocabulary (the vocabulary and the default field of the "article" content type) :

enter image description here

When I create a node, I select a taxonomy term in the form (for example "ICO"). The node displays the "tags" field :

enter image description here

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 ...

Score: 1
Confirmation message on comment submission
in flag

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 ...
Score: 0
bigboy avatar
How to open a field value dynamically in a modal dialog on node view?
gu flag

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  ...

Score: 0
Jason avatar
Entity reference field hidden widget or edit disabled on custom form
in flag

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 ...

Score: 2
Add a custom variable to an existing block
mx flag
JFK

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, ...
Score: 4
Smartsheet eng avatar
What is the stable9 theme? When should I use it instead of stable?
um flag

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  ...

Score: 0
bigboy avatar
Filter views by field value equals another field of curent node
gu flag

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  ...

Score: 1
Altering custom template from code
pt flag

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 ...

Score: 1
Make Title field "not required" or workaround how to prefill and hide it (drupal 9.2.8)
ug flag

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') ...
Score: -5
Is by design, Drupal headless?
es flag

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 ...

Score: 1
Can't save value of custom datetime field
in flag

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  ...

Score: 0
Joost avatar
Is it possible to see which modules grants access rights?
jp flag

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!

Score: 0
Lambic avatar
Migrating an array of values into multiple entities
ph flag

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: "@_ ...
Score: 0
Giuseppe avatar
How get the referenced entity inside a field link?
br flag

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 ...
Score: 1
SomebodySysop avatar
How to add view filter programmatically using hook_views_pre_view()
gb flag

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 ...
Score: 0
Custom block plugin: Give access to edit form
in flag

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 ...

Score: 0
Provide menu link when creating node programmatically and append it to parent menu link
in flag

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()],
  ' ...
Score: 0
Rainer Feike avatar
Create solr_core for search_api_solr 4.x with docker solr 8
in flag

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 ...

Score: 1
How do I get the selected image style from a referenced media field?
cn flag

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 ...

Score: 1
Jaypan avatar
Is it possible to add an entity to the current route parameters?
de flag

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  ...

Score: 0
bigboy avatar
Update node and all translations programmatically
gu flag

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 ...