You are here

function template_preprocess_profile in Profile 8

Prepares variables for profile templates.

Default template: profile.html.twig.

Parameters

array $variables: An associative array containing:

  • elements: An associative array containing rendered fields.
  • attributes: HTML attributes for the containing element.

File

./profile.module, line 127
Support for configurable user profiles.

Code

function template_preprocess_profile(array &$variables) {

  /** @var Drupal\profile\Entity\ProfileInterface $profile */
  $profile = $variables['elements']['#profile'];
  $variables['view_mode'] = $variables['elements']['#view_mode'];
  $variables['profile'] = $profile;
  $variables['url'] = $profile
    ->id() ? $profile
    ->toUrl() : FALSE;

  // Helpful $content variable for templates.
  $variables['content'] = [];
  foreach (Element::children($variables['elements']) as $key) {
    $variables['content'][$key] = $variables['elements'][$key];
  }
}