public function Paragraph::label

File

paragraphs/src/Entity/Paragraph.php, line 156

Class

Paragraph
Defines the Paragraph entity.

Namespace

Drupal\paragraphs\Entity

Code

public function label() {
  if (($parent = $this
    ->getParentEntity()) && $parent
    ->hasField($this
    ->get('parent_field_name')->value)) {
    $parent_field = $this
      ->get('parent_field_name')->value;
    $field = $parent
      ->get($parent_field);
    $label = $parent
      ->label() . ' > ' . $field
      ->getFieldDefinition()
      ->getLabel();

    // A previous or draft revision or a deleted stale Paragraph.
    $postfix = ' (previous revision)';
    foreach ($field as $value) {
      if ($value->entity && $value->entity
        ->getRevisionId() == $this
        ->getRevisionId()) {
        $postfix = '';
        break;
      }
    }
    if ($postfix) {
      $label .= $postfix;
    }
  }
  else {
    $label = $this
      ->t('Orphaned @type: @summary', [
      '@summary' => Unicode::truncate(strip_tags($this
        ->getSummary()), 50, FALSE, TRUE),
      '@type' => $this
        ->get('type')->entity
        ->label(),
    ]);
  }
  return $label;
}