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

AccountEvents::SET_USER isn't the event for user registration. Per the docs: This event allows modules to perform an action whenever the current user is set. The event listener receives an \Drupal\Core\Session\AccountSetEvent instance. The event is fired when Drupal initializes the user object for the current request, not when new users are created. ...


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


1

There is no need to write code to get the content type of the viewed node, inside the html.html.twig file: That value is already passed to the template file. logged_in: A flag indicating if user is logged in. root_path: The root path of the current page (e.g., node, admin, user). node_type: The content type for the current node, if the page is a ...


1

There are patches under work and testing but no commits yet https://www.drupal.org/project/drupal/issues/2960353. Patches work on latest D8 to date, but until a patch has been committed, suggest to use Hide Preview Button module https://www.drupal.org/project/hide_preview works well for other form pages, too. In case, this helps those not comfortable with ...


1

You simply can do that without any templating by implementing template_preprocess_html. /** * Implements template_preprocess_html(). */ function MYTHEME_preprocess_html(&$variables) { $node = \Drupal::routeMatch()->getParameter('node'); if ($node instanceof \Drupal\node\NodeInterface) { // Add node type body class. $variables['...


1

This is the way I do it: // Get actual user role. $current_user_roles = \Drupal::currentUser()->getRoles(); // Check if user is not admin. if (!in_array('administrator', $current_user_roles)) { // Check if user is an admin. if (in_array('administrator', $current_user_roles)) {


1

Only in a narrow scope where "empty" for the field means the empty string ('') and it's stored as such in the DB. EntityStorageBase::loadByProperties() uses a helper method, ::buildPropertyQuery(), that chains comparisons using the IN operator. As such, you can't use negation or special comparison cases (e.g. IS NULL if "empty" means NULL in the DB). ...


1

I think the problem in your current code is that you're overwriting the response. You should add the cookie to the default AjaxResponse instead: public function submitUserInfoFormAjax(array $form, FormStateInterface $form_state) { $response = new AjaxResponse(); $response->headers->setCookie(new \Symfony\Component\HttpFoundation\Cookie('john',...


1

Checkbox values are preprocessed so only checked ones you can get in your twig: I think you need to preprocess your field by implementing hook_preprocess_HOOK to add unchecked ones to your variables something like: /** * Implements hook_preprocess_HOOK(). */ function MY_MODULE_preprocess_field(&$variables) { $element = $variables['element']; if ($...


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

Apache can handle this. You can leave the Drupal code where it is. Have a look at the Apache documentation for Mapping URLs to Filesystem Locations. In particular, the differences between DocumentRoot and Alias. In the absence of any other information, Apache looks for files/scripts in the document root. For a Drupal site located at https://www....


1

Maybe start with https://drupal.stackexchange.com/a/232783/15055, just implement the preprocess page title hook (without the code inside for now) in a custom module or a custom theme. Then install the Devel sub-module Kint. And put ksm(\Drupal::routeMatch()->getRouteName()); inside this hook. Note, in the hook name replace MYMODULE with your custom ...


1

Could someone tell me where to go and which static route to change? It's not a static route. Like other entity collection routes, it is built with the aid of the comment annotations above the Vocabulary entity class. VocabularyRouteProvider also comes into play, and it sets a _title_callback into TaxonomyController::vocabularyTitle for good measure. At ...


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