You are here

function template_preprocess_subscription in Mailing List 8

Prepares variables for subscription templates.

Default template: subscription.html.twig.

Parameters

array $variables: An associative array containing:

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

File

./mailing_list.module, line 62
Contains the Mailing list module.

Code

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

  /** @var \Drupal\mailing_list\SubscriptionInterface $subscription */
  $subscription = $variables['subscription'];
  $variables['date'] = drupal_render($variables['elements']['created']);
  unset($variables['elements']['created']);
  $variables['author_name'] = drupal_render($variables['elements']['uid']);
  unset($variables['elements']['uid']);
  $variables['url'] = $subscription
    ->url('canonical', [
    'language' => $subscription
      ->language(),
  ]);
  $variables['label'] = $variables['elements']['title'];
  unset($variables['elements']['title']);
  $variables['email'] = $variables['elements']['email'];
  unset($variables['elements']['email']);

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