You are here

public function ParagraphLineageInspector::getLineageString in Paragraphs Edit 8.2

Builds a string representation of a paragraph's lineage.

Parameters

\Drupal\paragraphs\ParagraphInterface $paragraph: The paragraph whose lineage to return as a string.

Return value

string A string representation of the paragraph's lineage.

File

src/ParagraphLineageInspector.php, line 104

Class

ParagraphLineageInspector
ParagraphLineageInspector class.

Namespace

Drupal\paragraphs_edit

Code

public function getLineageString(ParagraphInterface $paragraph) {
  $string = '';
  do {
    $parent = $paragraph
      ->getParentEntity();
    if (!$parent) {
      break;
    }
    $parent_field = $this
      ->getParentField($paragraph);
    $parent_field_label = $parent_field
      ->getFieldDefinition()
      ->getLabel();
    $parent_field_item = $this
      ->getParentFieldItem($paragraph, $parent_field);
    $parent_field_delta = $parent_field_item
      ->getName() + 1;
    $string = ' > ' . $parent_field_label . ' #' . $parent_field_delta . $string;
    $paragraph = $parent;
  } while ($parent instanceof ParagraphInterface);
  if ($parent) {
    return $parent
      ->label() . $string;
  }
  return (string) t('Orphan paragraph');
}