function 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:

  • attributes: HTML attributes for the containing element.

File

core/modules/user/src/Hook/UserThemeHooks.php, line 61

Class

UserThemeHooks
Hook implementations for user.

Namespace

Drupal\user\Hook

Code

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.