You are here

function template_preprocess_paragraph in Paragraphs 8

Prepares variables for paragraph templates.

Default template: paragraph.html.twig.

Most themes use their own copy of paragraph.html.twig. The default is located inside "templates/paragraph.html.twig". Look in there for the full list of variables.

Parameters

array $variables: An associative array containing:

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

File

./paragraphs.module, line 280
Contains paragraphs.module

Code

function template_preprocess_paragraph(&$variables) {
  $variables['view_mode'] = $variables['elements']['#view_mode'];
  $variables['paragraph'] = $variables['elements']['#paragraph'];

  // Helpful $content variable for templates.
  $variables += array(
    'content' => array(),
  );
  foreach (Element::children($variables['elements']) as $key) {
    $variables['content'][$key] = $variables['elements'][$key];
  }
  $paragraph_type = $variables['elements']['#paragraph']
    ->getParagraphType();
  foreach ($paragraph_type
    ->getEnabledBehaviorPlugins() as $plugin_value) {
    $plugin_value
      ->preprocess($variables);
  }
}