I've been spending a couple of hours from debugging the paragraph properties using kint
and var_dumper
however, the page is freezing and I'm unable to see what are the properties and methods available. Has anyone tried to add a hook theme suggestion to paragraph
based on its parent field name?
I have added a paragraph type as well as added the fields, then I created a node and paragraph reference.
Here's a sample code:-
function THEMENAME_theme_suggestions_paragraph_alter(&$suggestions, $variables) {
$paragraph = $variables['elements']['#paragraph'];
$parent = $paragraph->getParentEntity();
$suggestions[] = 'paragraph__' . $parent->bundle() . '__' . $paragraph->bundle();
// get the parent field of the current paragraph
// assuming that the parent field name is field_test_paragraph
$parent_field_name = 'field_test_paragraph';
// field_test_paragraph should be added to theme suggestions
$suggestions[] = 'paragraph__' . $parent->bundle() . __ . $parent_field_name . '__' . $paragraph->bundle();
}
Expected output:
paragraph--nodetype--field-test-paragraph--paragraph-type-name.html.twig
$parent->bundle() . __ . $parent_field_name
must become$parent->bundle() . '__' . $parent_field_name