function UserThemeHooks::preprocessUser
Same name and namespace in other branches
- 11.x core/modules/user/src/Hook/UserThemeHooks.php \Drupal\user\Hook\UserThemeHooks::preprocessUser()
Prepares variables for user templates.
Default template: user.html.twig.
Parameters
array $variables: An associative array containing:
- elements: An associative array containing the user information and any
fields attached to the user. Properties used:
- #user: A \Drupal\user\Entity\User object. The user account of the profile being viewed.
- attributes: HTML attributes for the containing element.
File
-
core/
modules/ user/ src/ Hook/ UserThemeHooks.php, line 65
Class
- UserThemeHooks
- Hook implementations for user.
Namespace
Drupal\user\HookCode
public function preprocessUser(array &$variables) : void {
$variables['user'] = $variables['elements']['#user'];
// Helpful $content variable for templates.
foreach (Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.