How to add the paragraph parent field in the theme suggestions alter
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().