Hot answers tagged

5

You could add a listing cache tag for the content type: 'tags' => ['node_list:message'], This cache tag was introduced in Drupal 8.9. See the change record Added an ENTITY_TYPE_list:BUNDLE cache tag.


4

You can create an Entity Reference display in a view and use that to generate the available options. In your view of choice, create a new display of type Entity Reference and configure it so that it only shows the content you want. Navigate back to your field configuration screen (the one in your screenshot) and change Reference Method from "Default&...


3

If you want to run code before the Drupal kernel is started use a middleware. Use the drush code generator drush gen middleware and put your code in handle() of the generated middleware class: MymoduleMiddleware.php <?php namespace Drupal\mymodule; use Drupal\Core\StringTranslation\StringTranslationTrait; use Symfony\Component\HttpFoundation\Request; ...


3

I'm guessing the problem is that in the onFlag event, the flag is still being created, so it can't be unflagged because it hasn't been fully saved yet. But I think the bigger problem is that your code has a logic error-- validation should happen before the action, not after the action. It looks like you are trying to do this: When a user is flagged, check ...


2

In the hook_theme_suggestions_HOOK_alter the $variables contain only informations about the theme of entity in this case theme image: From documentation: array $variables: An array of variables passed to the theme hook. Note that this hook is invoked before any preprocessing. if you look at image_theme you can find all variables passed uri, title ... So to ...


2

I fixed the problem by adding the following code to the class /** * {@inheritdoc} */ public static function getPreconfiguredOptions() { return []; }


2

The comment module provides a permission, "Post comments" (post comments). Before using any code option, you should remove that permission for anonymous users.


2

The closest match to the link you shared is the Entity Browser module. Goal of this module is to provide a generic entity browser/picker/selector. It can be used in any context where one needs to select few entities and do something with them. The module allows you to build your own widgets (similar to the Media Library) to use with entity reference fields ...


1

This is the answer: Url::fromUri($var)->toString(TRUE)->getGeneratedUrl(); Found here: https://www.lullabot.com/articles/early-rendering-a-lesson-in-debugging-drupal-8


1

Commerce License is in alpha. That means it is not generally ready for production use. Further, Commerce Recurring is in beta, but the module page itself notes, as of January 2021: This module is not production ready! Expect pain. Using these modules now will require writing custom code and debugging; there is no out-of-the-box easy solution at this time. ...


1

You are overriding the array each time in getSubscribedEvents instead of adding entries to it. It should look more like this: public static function getSubscribedEvents() { $events = []; $events['commerce_order.place.post_transition'] = ['addSubscription', -100]; $events['commerce_order.place.pre_transition'] = ['removeSubscription', -100]; ...


1

For many real world scenarios, I'd build your example with multiple fields on the node, one for subtasks, and a second for prerequisites, etc. Obviously, you can run into trouble with that if you want a truly flexible field with many types of references across many different content types or types of content. For more robust, "Jira style linking", ...


1

The requirement _csrf_request_header_token: "TRUE" works only if user is connected because CsrfRequestHeaderAccessCheck use session informations. If you look at CsrfRequestHeaderAccessCheck in the access method there is: if ($account ->isAuthenticated() && $this->sessionConfiguration ->hasSession($request)) { To check ...


1

In Drupal 7, this is possible with the Relation module. Relations are entities. So instead of creating entity references to link nodes, when using the Relation module, you create Relation entities, and these Relation entities can contain entity references to two or more entity references to connect them via a "type". In the case of the Relation ...


1

Here's what you can do: First, add then config the contextual filter like this: Then you update the header like this: You can update the header status at this step also. And then here is the result: One more thing need you to handle: The exception when the filter value is not in the url. Can it be your part?


1

There is a issue as you ask the question. The current answer is that Drupal 8 does not yet support this feature besides node content type. I'm also following this issue. more details at: https://www.drupal.org/project/drupal/issues/2915933 https://www.drupal.org/project/drupal/issues/1040786


1

I believe it is too late to halt the Webform with validation errors once it is past the validation phase ie. in postSave(). If you are expecting validation errors on user input however, then you could move the service call to WebformHandlerBase::validateForm() and then save the service response in the $form_state object if you need it. /** * {@...


1

You can enable Twig debugging for your site in sites/default/services.yml parameters: twig.config: debug: true Clear cache Inspect element in the browser and you will see the path to the template Copy the template to your custom theme's templates/ directory and adjust the markup


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