Drupal 8, getting paragraph parent

function hook_suggestions_paragraph_alter(array &$suggestions, array $variables, $hook) {
$parent = $variables['elements']['#paragraph']->getParentEntity()->bundle();
if($parent){
$paragraph = $variables['elements']['#paragraph'];
$sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
//$suggestions[] = 'paragraph__' . $sanitized_view_mode; //$suggestions[] = 'paragraph__' . $paragraph->bundle(); //$suggestions[] = 'paragraph__' . $paragraph->bundle() . '__' . $sanitized_view_mode; $suggestions[] = 'paragraph__' . $paragraph->bundle() . '__' . $sanitized_view_mode . '__parent_' . $parent;
}
}

Leave a comment

Your email address will not be published. Required fields are marked *