How to add the paragraph parent field in the theme suggestions alter 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(&amp;$suggestions, $variables) {
    $paragraph = $variables['elements']['#paragraph'];
    $parent = $paragraph-&gt;getParentEntity();

    $suggestions[] = 'paragraph__' . $parent-&gt;bundle() . '__' .  $paragraph-&gt;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-&gt;bundle() . __ . $parent_field_name . '__' .  $paragraph-&gt;bundle();
}


Expected output:

paragraph--nodetype--field-test-paragraph--paragraph-type-name.html.twig
You can get the parent field name directly from the paragraph:

Replace

// get the parent field of the current paragraph
// assuming that the parent field name is field_test_paragraph
$parent_field_name = 'field_test_paragraph';


with

$parent_field_name = $paragraph-&gt;parent_field_name-&gt;value;




As a side note, this is an entity base field like parent_id and parent_type you load the parent entity with in getParentEntity().