You are here

function template_preprocess_simplenews_newsletter_body in Simplenews 8

Same name and namespace in other branches
  1. 8.2 simplenews.module \template_preprocess_simplenews_newsletter_body()
  2. 6.2 simplenews.module \template_preprocess_simplenews_newsletter_body()
  3. 6 simplenews.module \template_preprocess_simplenews_newsletter_body()
  4. 7.2 simplenews.module \template_preprocess_simplenews_newsletter_body()
  5. 7 simplenews.module \template_preprocess_simplenews_newsletter_body()
  6. 3.x simplenews.module \template_preprocess_simplenews_newsletter_body()

Process variables to format the simplenews newsletter body.

See also

simplenews-newsletter-body.html.twig

File

./simplenews.module, line 958
Simplenews node handling, sent email, newsletter block and general hooks

Code

function template_preprocess_simplenews_newsletter_body(&$variables) {
  $elements =& $variables['elements'];
  $entity_type = $elements['#entity_type'];

  /** @var \Drupal\Core\Entity\FieldableEntityInterface $entity */
  $entity = !empty($elements['#' . $entity_type]) ? $elements['#' . $entity_type] : $elements['#entity'];
  if ($elements['#language'] && $entity
    ->hasTranslation($elements['#language'])) {
    $entity = $entity
      ->getTranslation($elements['#language']);
  }
  $variables[$entity_type] = $entity;

  // Provide some common variables.
  $variables['title'] = $entity
    ->label();
  $variables['view_mode'] = $elements['#view_mode'];
  $variables['language'] = $elements['#language'];
  $variables['format'] = $elements['#format'];
  $variables['key'] = $elements['#key'];
  $variables['newsletter'] = $elements['#newsletter'];
  $variables['simplenews_subscriber'] = $elements['#simplenews_subscriber'];
  $variables['build'] = [];
  foreach (Element::children($elements) as $key) {

    // In case of nodes, skip the hardcoded formatters for created, title and
    // uid.
    if ($entity_type == 'node' && in_array($key, [
      'uid',
      'created',
      'title',
    ])) {
      continue;
    }
    $variables['build'][$key] = $elements[$key];
  }
  $variables['unsubscribe_text'] = t('Unsubscribe from this newsletter', array(), array(
    'langcode' => $variables['language'],
  ));
  $variables['test_message'] = t('This is a test version of the newsletter.', array(), array(
    'langcode' => $variables['language'],
  ));

  // Do not display the unsubscribe link by default for hidden categories.
  $variables['opt_out_hidden'] = $variables['newsletter']->opt_inout == 'hidden';
}