You are here

function template_preprocess_private_message in Private Message 8.2

Same name and namespace in other branches
  1. 8 private_message.module \template_preprocess_private_message()

Prepares variables for private_message templates.

Default template: private-message.html.twig.

Parameters

array $variables: An associative array containing:

  • elements: An array of elements to display in view mode.
  • private_message: The private message object.
  • view_mode: View mode; e.g., 'full', 'teaser', etc.

File

./private_message.module, line 434
Contains hooks for the private message module.

Code

function template_preprocess_private_message(array &$variables) {
  $variables['view_mode'] = $variables['elements']['#view_mode'];

  // Provide a distinct $teaser boolean.
  $variables['private_message'] = $variables['elements']['#private_message'];

  /** @var \Drupal\private_message\Entity\PrivateMessageInterface $private_message */
  $private_message = $variables['private_message'];
  $variables['url'] = $private_message
    ->toUrl('canonical', [
    'language' => $private_message
      ->language(),
  ]);

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