Hot answers tagged

3

Lists like views will not be passed through hook_node_access(), as this would create too much overhead. Views does a query on the database to get the results. hook_node_access() is run in PHP, so these won't work (easily/well/efficently) together. To deal with lists, you will need to create a grant system, using hook_node_access_records() and ...


2

First of all, User module's user.private_tempstore and user.shared_tempstore services moved to core. So we want to use the tempstore.private. The code below will get your started. you will want to read more about how getSubscribedEvents() works, as here is where you tweak the where and when of your event. Don't forget an .info.yml file! /mymodule/mymodule....


2

As start, the code shown in the question is wrong in many points, in particular because it is using Drupal 7 code that has not been adapted for Drupal 8. Drupal core has modules that alter the user edit form, and that code should be taken as guide for your own code. Since you want to alter the user edit form for when users create an account and when an ...


1

Got it to work with the following code. I needed to output the changed value in the $vars['output']. This would override the url in the nothing_1 field so I then had to create a new link and use that to alter the original value. /** * Implements hook_preprocess_views_view_field(). */ function frontview_general_preprocess_views_view_field(&$vars) { $...


1

Add a boolean field as a condition to hide the end-date is a fine solution. For hiding the field you can either check for the boolean in the template: {% if $node->field_hide_end_date->value %} {{ $node->field_range->value|format_date('my_custom_date_format') }} {% else %} {# Original version of the field #} {{ $content['field_range']...


1

In page-title.html.twig you don't have access to content variable. according to page-title.html.twig comment section: Available variables are: title_attributes title_prefix title title_suffix So you should implement hook_preprocess_HOOK to passe hide_title to your twig like the following: /** * Implements hook_preprocess_HOOK(). */ function ...


1

In Drupal 8 you should use hook_entity_update(). This hook runs once the entity storage has been updated. https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21entity.api.php/function/hook_entity_update/8.3.x


1

In Drupal 8, the core Drupal hook hook_entity_view() is only called when the entity is "being assembled before rendering". See the documentation at https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!entity.api.php/function/hook_entity_view After the entity has been rendered, core Drupal will cache the rendered entity and serve the rendered entity ...


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