You are here

protected function Node::preprocessElement in Open Social 8.8

Same name in this branch
  1. 8.8 themes/socialblue/src/Plugin/Preprocess/Node.php \Drupal\socialblue\Plugin\Preprocess\Node::preprocessElement()
  2. 8.8 themes/socialbase/src/Plugin/Preprocess/Node.php \Drupal\socialbase\Plugin\Preprocess\Node::preprocessElement()
Same name and namespace in other branches
  1. 8.9 themes/socialblue/src/Plugin/Preprocess/Node.php \Drupal\socialblue\Plugin\Preprocess\Node::preprocessElement()

Preprocess the variables array if an element is present.

Parameters

\Drupal\bootstrap\Utility\Element $element: The Element object.

\Drupal\bootstrap\Utility\Variables $variables: The Variables object.

Overrides Node::preprocessElement

File

themes/socialblue/src/Plugin/Preprocess/Node.php, line 21

Class

Node
Pre-processes variables for the "node" theme hook.

Namespace

Drupal\socialblue\Plugin\Preprocess

Code

protected function preprocessElement(Element $element, Variables $variables) {
  parent::preprocessElement($element, $variables);

  /** @var \Drupal\node\Entity\Node $node */
  $node = $variables['node'];
  $style = theme_get_setting('style');
  $view_modes = [
    'teaser',
    'activity',
    'activity_comment',
    'featured',
    'hero',
  ];

  // Add teaser tag as title prefix to node teasers and hero view modes.
  if ($style === 'sky' && in_array($variables['view_mode'], $view_modes)) {
    if (!empty($variables['topic_type'])) {
      $teaser_tag = $variables['topic_type'];
    }
    elseif (!empty($variables['event_type'])) {
      $teaser_tag = $variables['event_type'];
    }
    else {
      $teaser_tag = $node->type->entity
        ->label();
    }
    $variables['title_prefix']['teaser_tag'] = [
      '#type' => 'inline_template',
      '#template' => '<div class="teaser__tag">{{ teaser_tag }}</div>',
      '#context' => [
        'teaser_tag' => $teaser_tag,
      ],
    ];
  }
}