Hot answers tagged

3

In addition to @sonfd answer you also need to consider caching. The easiest way would be to add a cache context: $variables['#cache']['contexts'][] = 'user'; But then the database needs to store a cached version for each user. Better for performance would be to postpone replacing the placeholder by attaching a lazy builder to the render array: function ...


2

I was able to use hook_entity_field_access and return an AccessResult $result->addCacheContexts(['session', 'user.roles.anonymous'])


1

Recommend using @4k4's answer instead. There are a few issues here: You're setting your $body variable, but not setting the change in your $variables array. You can fix this by using a reference, update with $body = &$variables['content']['body'][0]['#text']; You're replacing with the user object rather than the user id. You can't insert an object into ...


1

By implementing hook_link_alter in either a custom module or your theme. The code (untested) would be similar to: /** * Implements hook_link_alter(). */ function MODULE/THEME_link_alter(&$variables) { if (isset($variables['options']['attributes']['target']) && $variables['options']['attributes']['target'] == '_blank') { $variables['...


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