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.
array $variables: An associative array containing:
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();
if (!$paragraph_type) {
\Drupal::logger('paragraphs')
->critical(t('Unable to load paragraph type %type when displaying paragraph %id'), [
'%type' => $variables['elements']['#paragraph']
->bundle(),
'%id' => $variables['elements']['#paragraph']
->id(),
]);
$paragraph_type = ParagraphsType::create([
'id' => $variables['elements']['#paragraph']
->bundle(),
]);
}
foreach ($paragraph_type
->getEnabledBehaviorPlugins() as $plugin_value) {
$plugin_value
->preprocess($variables);
}
}