Hot answers tagged

5 votes
Accepted

Why hook_ENTITY_TYPE_access and hook_ENTITY_TYPE_create_access are not fired?

The problem here is be logged as Administrator, this is because for determining access rights for an existing node, \Drupal\node\NodeAccessControlHandler first checks whether the user has the bypass ...
4 votes

How to hide the comment subject field?

A solution is to copy core's comment.html.twig and put it in your theme's /templates folder and remove the <h3{{ title_attributes }}>{{ title }}</h3> line.
4 votes

How to render a twig template in the meta data of a cacheablejson response?

Use renderRoot() and, most importantly, add the cache metadata of the build array (after it was rendered) to the response, so that the response can be invalidated in cache if necessary: use Drupal\...
  • 91.5k
3 votes
Accepted

Correct schema for an Entity Reference in config settings

Using entity_reference_selection.default:taxonomy_term type is incorrect as this config is used for field settings in the Entity reference type fields. It is defined in the core/config/schema/core....
  • 161
3 votes

Why does adding #element_validate give warning about invalid callback?

#element_validate expects an array of validation callbacks. A callback can either be the function name of a globally accessible function, or an array of a class name and method name. Now I am ...
2 votes
Accepted

Is it possible to override a template from the module where the original is declared

Any template override you want to place in the module folder has to be defined in hook_theme() based on the base hook: /** * Implements hook_theme(). */ function mymodule_theme($existing, $type, $...
  • 91.5k
2 votes

Why does Drupal >= 9.4.7 not allow including .php files in Twig templates?

I faced an same type of issue when updating the Drupal core from 9.4.5 to 9.4.8 Twig\Error\LoaderError: Template "themes/gavias_tico/customize/form.php" is not defined in "themes/...
2 votes
Accepted

Service continues to act as shared when shared is set to false

Thanks to user @Clive 's questioning, it led me to assess this issue as a Plugin problem rather than a Service problem. Since the service is being used in a plugin, and the plugin was being cached (by ...
  • 96
2 votes
Accepted

I'm not quite sure what this error is but it's breaking my site

Can anyone help me in discovering what is wrong? When you look up this part of the stack trace: t() (Line: 81) Drupal\date_range_formatter\Plugin\Field\FieldFormatter\DateRangeFormatterRangeFormatter-&...
  • 91.5k
2 votes
Accepted

How to show the slogan in Olivero?

This is an open bug in Drupal. Use a patch from the issue: https://www.drupal.org/project/drupal/issues/3188136
  • 4,104
2 votes
Accepted

How can I control node access based on entity reference to multiple users

Yes, it's a bad idea to do this in templates as their output will be cached by default. If it's just for viewing the full node via its canonical URL (/node/123 or /my-node-alias) you can achieve that ...
  • 16.6k
2 votes

Composer not applying patch: exceeded the timeout of 300 seconds

Thanks @cilefen for pointing me in the right direction. For me solution 423 of this thread fixed the problem: https://github.com/cweagans/composer-patches/issues/423#issuecomment-1301026697 The ...
  • 956
2 votes
Accepted

How to programatically publish content after form validation

You're trying to combine what should be two steps, into one. Validation handlers are for validation, so skipping the validation happens in the validation handler. Processing, which in this case ...
  • 15.6k
2 votes

When I add an emoji in full HTML with CKeditor 5, I get a PHP error

The problem is probably that the Drupal site was setup some years ago when they still used UTF-8 with three bytes per character because many versions of MYSQL didn't support more than that. You need ...
  • 91.5k
2 votes
Accepted

How to hide the comment subject field?

If one installs the contributed extension named Manage display the "Subject" field becomes exposed under the "Manage display" tab for a comment. You can then move it to the "...
  • 14.9k
2 votes

How do I use CKEditor 5?

Drupal core will provide an upgrade path of switching from CKEditor 4 to 5 without data loss. You should be able to switch the editor from 4 to 5 in your text format with an action as simple as ...
  • 10.8k
1 vote

How to translate breadcrumbs block via drupal_block() in twig?

I wouldn't try to translate breadcrumbs in Twig. Blocks get the language from the global context and for breadcrumbs it's delegated to the breadcrumb builder which then gets it from the context. For ...
  • 91.5k
1 vote
Accepted

Why is ScrollTopCommand not working?

You need to include the views/views.ajax lib: $form['#attached']['library'][] = 'views/views.ajax';
1 vote

How do I get TypeScript that uses Drupal globals to compile?

Thanks to cilefen and https://stackoverflow.com/questions/13252225/call-a-global-variable-inside-module this works : declare var jQuery: any; declare var Drupal: any; (function ($: any, Drupal: any) {...
  • 353
1 vote

Print total value in footer but unable to modify footer value using hook_views_pre_render()

If that is a copy of your code, you need to replace the hook word in the function name hook_views_pre_render with your module name. EG. Your module is called mymodule hook_views_pre_render(...
  • 112
1 vote
Accepted

How can I use custom HTML/CSS in the login page?

You can write a custom module to use attaching a library to a form As forms are just render arrays, attaching a library works just the same: /** * Implements hook_form_alter(). */ function ...
1 vote
Accepted

Context Definition for Taxonomy Term Not Working

Context depends on the presence of one or more context providers and how they extract that data. In this case of TermRouteContext, it extracts Term information from the route. if ($route_object = $...
  • 1,232
1 vote

How can I check if a module is enabled in settings.php?

For the same reasons mentioned in How can we use \Drupal class inside Settings.php, namely that the Drupal bootstrap process hasn't completed yet, this cannot be done. see @Jaypan's comment.
1 vote
Accepted

How to set widget for a field on a custom form?

The form API is the most basic way to define custom forms in Drupal. It is using form elements to show HTML controls for form fields. (Field) Widgets on the other hand are part of the entity fields ...
1 vote

How to programmatically set a checkbox value of an user account which field is not in /people/accounts/fields

because the module stores the settings information in the userObject and not in fields you can use $userData = \Drupal::service('user.data'); $userData->set('danse', $userID_current, 'content-node-&...
  • 31
1 vote
Accepted

How to get fields of a product type using a database dynamic query

how can I determine the fields of the product type with which I can then create a dynamic database query to get the product and the field values that go along with it? You shouldn't do that. That's ...
  • 164k
1 vote

How to hide the tabs on the user account if it is not his account?

You can add a RouteSubscriber with a custom access check to accomplish this. Something like: class RouteSubscriber extends RouteSubscriberBase { /** * {@inheritdoc} */ protected function ...
  • 27.1k
1 vote
Accepted

Generating forms dynamically from json data

I think this is going to be tough, unfortunately. The Feeds module has good JSON support, so that's a way to get the data in. The problem is: what will you import to? Webform would seem to be an ...
1 vote

CKEditor 4 style to add a class to a paragraph instead of replacing existing classes

I was asking myself the same question. It seems that someone did a plugin for that, see https://stackoverflow.com/questions/43680918/stylescombo-plugins-with-multiple-class-selection. His plugin can ...

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