public function Paragraph::label in Paragraphs 8
Gets the label of the entity.
Return value
string|null The label of the entity, or NULL if there is no label defined.
Overrides ContentEntityBase::label
File
- src/
Entity/ Paragraph.php, line 151
Class
- Paragraph
- Defines the Paragraph entity.
Namespace
Drupal\paragraphs\EntityCode
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;
}