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.
1,767
questions
2
votes
1
answer
205
views
How can I specify the relation type between two entities?
I am new two Drupal
Trying to create two entities, Post and Category (This is for tests purposes)
A Post can have one Category, and a Category can have multiple Post
Here is my implementation of the ...
2
votes
1
answer
1k
views
How to get the description text from metatag field
A content type in my Drupal 9 instance uses the Metatag module. I want to extract the 'description' metatag value and include it in a twig template (for the node).
But when I look at the variables ...
2
votes
2
answers
2k
views
Form with two submission buttons
I try to create a form with two submit buttons and each button will use a different function: the default submitForm function and a custom submitFormEndSession function. So I have this code:
class ...
2
votes
1
answer
672
views
Add a custom variable to an existing block
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 ...
2
votes
1
answer
723
views
How to use entityQuery with custom field type?
I am working on building a query for nodes that have a few custom fields (field types). The fields are custom build in a custom module with a custom schema. When I execute the query:
$query = \Drupal:...
2
votes
1
answer
38
views
Where is "click sortable" set for a field?
I am trying to properly fix a bug in D8/9 core which removes the ability for link fields to be "click sortable" in a Views table.
I know I can do a views_data_alter hook to set the field as &...
2
votes
1
answer
942
views
How target specific version of fork based merge request (MR) patch
I'm upgrading the core from 9.1.7 to 9.2.5, however there's a patch I don't how to upgrade.
This is the relative issue. The file 2897638-48.patch is currently used.
The patch's work meanwhile proceed ...
2
votes
1
answer
771
views
Migration of a custom Rest API using PATCH/POST
I had a custom REST API working with Drupal 8 perfectly. After upgrading to Drupal 9.2.X, the Patch and Post methods of this custom REST API stopped working. Now they throw the following exception.
...
2
votes
1
answer
67
views
Change priority of different aliases with the same aliases
There is vocabulary, let's call it forum tags which contain all forum tags,
Also, in Forum, the link for the Forum container using a similar tag pattern for the forums.
for example,
Term name : ...
2
votes
2
answers
241
views
How to expand NodeForm so new argument can passed to it
I have a content type called service request, which have some conditional fields that each might appear or disappear based on an other field value called service type.
I have used conditional field ...
2
votes
1
answer
748
views
How can I add a comment form?
I'm using views to display the fields of nodes. I prefer to use fields because it allows me to use relationships (bring in author profile picture etc.). Adding the Content: Comments field shows the ...
2
votes
2
answers
163
views
Managing backward compatibility
It seems (correct me if I'm wrong) that there are some classes or services that must be used in relevant cases in Drupal 9 that are not present in Drupal 8.
For example, New in Symfony 4.3: Simpler ...
2
votes
1
answer
2k
views
What is the recommended way for using PHPUnit?
Installing Drupal 9 with the drupal/recommended-project Composer package ships without PHPUnit. Why? (In Drupal 8 it is included. The documentation only tells about Drupal 8.)
Which version of PHPUnit ...
2
votes
1
answer
184
views
How to programmatically grant access to view unpublished content with a special query string?
In my application, I want anonymous users to be able to view an unpublished node but only if they append a special code to the URL. For example:
www.mysite.com/node/123?code=Hx23ufG38
I figure I can ...
2
votes
2
answers
465
views
Edit index config (Search API) programmatically and get the status index updated
I have a site with 14 pieces of news and 44 basic pages.
I have created an index (Search API) with this bundle:
and this is the index status (the content is already indexed during cron):
When I ...
2
votes
1
answer
68
views
What is the equivalent of field_view_field()?
I am working on some code where I need to get some fields from a node. For the body, I want to display the summary, or the trimmed body if the summary is not there.
I found an example on the web using ...
2
votes
1
answer
187
views
How can you cache a form render array?
I have a custom module which builds a set of complicated forms, and these forms are built dynamically (the option lists for certain SELECT items, for example, are fetched via an API call). Some of ...
2
votes
2
answers
90
views
How do I display user signatures in comments?
Drupal 7 has a "personalization" section on ...admin/config/people/accounts
If this exists in Drupal 9, I'd love to know where it is.
The goal: enable signatures for user accounts.
If it's ...
2
votes
1
answer
939
views
Get the real filename of file entity
I'd like to get the real filename of a file entity.
My code is like this
$filenames = [];
foreach ($entity->$field->referencedEntities() as $image) {
// Filename.
$media = ...
2
votes
1
answer
2k
views
How do I programmatically add images to a node?
I have a content type to which I added an image field. The database has a custom table with different columns, including the image ID.
Previously, I created a batch that writes data from this table to ...
2
votes
1
answer
487
views
How to enable a module on a ResourceTest?
I'm running a functional test that extends the ResourceTestBase however it is throwing the following error:
ServiceNotFoundException: The service "cache_tags.invalidator.checksum" has a ...
2
votes
3
answers
231
views
How to check if secondary database definition exists
Can anyone please help me on how to check if secondary database is set. If not throw an error.
I am currently defining database connection as below.
Database::getConnection('default', 'sqlite')
I am ...
2
votes
1
answer
2k
views
How to solve "Mismatched entity and/or field definitions", specifically, "The URL alias field needs to be installed"?
After migrating from 7.89 to 9.3.12 this warning appears:
ENTITY/FIELD DEFINITIONS Mismatched entity and/or field definitions
The following changes were detected in the entity type and field ...
2
votes
1
answer
452
views
how to extend existing drush command class
Can anyone please let me know how to extend existing drush command class.
I am writing a custom module which provides custom content entity and created a devel generate plugin similar to ...
2
votes
1
answer
509
views
Cannot resave nodes with entity->save(), no particular error
I'm trying to write a drush command to resave all the nodes on my site.
I searched for a module and found the Resave All Nodes module, but its drush command isn't ready yet. So I decided to try to ...
2
votes
1
answer
512
views
Can routing use parameters already in the URL?
I'm actually using D9 to build a system with entities using sub-entities.
The main entity system use the following path : /item/{item}
Each sub entity is related to a main entity and use this path : /...
2
votes
1
answer
157
views
What is the difference/purpose of 'content' and 'elements' keys, in preprocess?
I'm using hook_preprocess_node and looking at $variables. I can see there's two similar keys: content and elements. I see that there's a comment in the core code:
// Helpful $content variable for ...
2
votes
1
answer
2k
views
Programmatically get a full page html rendering of a route/page
We provide our content via APIs. At times we use the Views Restful approach, and at times the JSONAPI.
We need to add an API field on nodes that is a full HTML rendering of that node's page according ...
2
votes
1
answer
1k
views
How can I load a template from a custom module on a certain page?
I have a page at path /user/{id}/module, and I'm trying to have Drupal load a custom template from my module when this page is accessed.
The twig debug output shows suggestions for the template name ...
2
votes
1
answer
181
views
Unique constraint on several entity fields fails when >1 jsonapi POST requests happen right after another
In a fully decoupled drupal 9 project I have a custom entity type and added a unique constraint for several fields just as described here. This works well and adding a second entity with the same ...
2
votes
1
answer
337
views
Block Settings inside Form
Please I need help with my code. I have a form and a block created programmatically. The block embeds the form to show it on the frontend. The block also has some settings (form preffix text). I want ...
2
votes
1
answer
397
views
How get the view mode\third_party_settings of a field inside hook_preprocess_image_formatter(&$variables)
I'm on D9.
I've added a custom option to the image field formatter following Drupal guidelines
In the preprocess of the field I can get the settings I've created:
function my_module_preprocess_field(&...
2
votes
1
answer
166
views
How do I get rate and configuration values?
I'm stumped. How do you get values off of the shipment method config? For example I have a the Flat Rate shipping method "Express". I want to get the raw config form values stored on that ...
2
votes
1
answer
96
views
How to verify if a custom logo is used?
How can I check whether the site is using the default theme logo or a custom logo?
When I use the Twig debug tools to dump the site_logo variable, I only get the path of the logo, which doesn't tell ...
2
votes
1
answer
153
views
Unable to delete a tempstore that contains an en dash or an em dash
I am trying to delete a shared temporary storage for a key containing an en dash or an em dash.
$keyword = '2020–2021';
$tempstore = \Drupal::service('tempstore.shared')->get('my_module_name');
$...
2
votes
1
answer
621
views
How can I get IntelliSense/Intelephense to look inside a Drupal Docker Container?
I am developing a Drupal site using the latest official Drupal/PHP/Apache Docker image.
I have some local directories mapped to inside the Drupal container as expected (modules, profiles, sites, ...
2
votes
1
answer
544
views
How do I populate report page using a controller?
I'm following this tutorial on creating a report page for a custom plugin, but note that I'm using Drupal 9, and not Drupal 8 as per the tutorial.
I've created a report() method inside my ...
2
votes
1
answer
1k
views
How do I render search block form in theme template?
I've customized the search block in "block--search-form-block.html.twig" and it works using block layout on Drupal 9. Is it possible to render the Search Block directly in page.html.twig?
I'...
2
votes
1
answer
57
views
How do I fetch versions of a module compatible with latest core version?
I've been using the endpoint https://updates.drupal.org/release-history/[module]/[version], where [module] is the module name and [version] is its version (as 8.x or 7.x). This endpoint, however, ...
2
votes
1
answer
64
views
Removing data from an entity type
I am trying to remove a problematic payment gateway module and getting the following message when trying to uninstall it:
There is data for the bundle Authorize.net (Accept.js) on the entity type ...
2
votes
2
answers
87
views
How to show menu tab only for certain node type?
I have the following,
In the routing.yml
mymodule.cache_clear:
path: '/node/{node}/cache'
defaults:
_form: '\Drupal\mymodule\Form\APICacheClearForm'
_title: 'Cache Clear'
requirements:
...
2
votes
1
answer
86
views
Using Drupal's Core classes as services
I have rather a general question that would help me to undestand using services in Drupal 8+ and when it is worth to do so.
I have found a useful method createFromRoute which is part of
namespace ...
2
votes
1
answer
469
views
How to write in a ckdeditor textarea with Cypress?
i'm trying to create a new node in Drupal 9.
But all my attempts so far have failed when it comes to writing the body text.
The body text is a Ckeditor5 field. I can't write there with Cypress.
I ...
2
votes
1
answer
228
views
CKEditor 5 - access PHP plugin configuration from JS plugin?
I have provided a CKEditor 5 plugin a PHP configuration class. I am able to set and store configuration for the text editor plugin now, but do not know how to access that configuration value(s) from ...
2
votes
1
answer
285
views
How to create configurable plugins under a plugin manager?
I have a custom plugin type and annotation. The purpose of it is so people can develop their own clients for an API integration, and tell the system which plugin to use to perform these actions. I am ...
2
votes
1
answer
330
views
Why is MethodNotAllowedException thrown when an image is uploaded with CKEditor 5?
After updating Drupal to 9.5.3, I had this warning: Deprecated modules found: CKEditor.
So I upgraded from CKEditor to CKEditor 5 following this documentation.
After some setup on text formats, I made ...
2
votes
1
answer
343
views
I am trying to add a simple pager to my controller, I have managed to get the row limit (5) to be printed but not to see the next or the previous [duplicate]
<?php
namespace Drupal\drupal_block\Controller;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Database\Connection;
use Drupal\Core\Controller\ControllerBase;
use ...
2
votes
1
answer
1k
views
Why does this custom CKEditor plugin produce the toolbarview-item-unavailable error?
I have 2 modules in active development with the purpose of learning how to develop custom plugins for the Ckeditor5 wysiwyg.
On both modules, I am stuck on the following problem. The error pasted ...
2
votes
1
answer
984
views
How to programmatically invalidate the cache of every node
I have a form submit function that is meant to invalidate the cache of every node if a specific field is altered. Here's how I'm attempting it.
$config = $this->configFactory
->getEditable('...
2
votes
1
answer
299
views
How to temporarily override configuration?
I want to be able to contextually modify configuration variables, i.e. within a page controller.
Example
I have a custom ad module which besides other settings has an option to globally disable or ...