Returns the summary items of the Paragraph.
array $options: (optional) Array of additional options, with the following elements:
array A list of summary items, grouped into the keys 'content' and 'behaviors'.
Overrides ParagraphInterface::getSummaryItems
public function getSummaryItems(array $options = []) {
$summary = [
'content' => [],
'behaviors' => [],
];
$show_behavior_summary = isset($options['show_behavior_summary']) ? $options['show_behavior_summary'] : TRUE;
$depth_limit = isset($options['depth_limit']) ? $options['depth_limit'] : 1;
// Add content summary items.
$this->summaryCount = 0;
$components = \Drupal::service('entity_display.repository')
->getFormDisplay('paragraph', $this
->getType())
->getComponents();
uasort($components, 'Drupal\\Component\\Utility\\SortArray::sortByWeightElement');
foreach (array_keys($components) as $field_name) {
// Components can be extra fields, check if the field really exists.
if (!$this
->hasField($field_name)) {
continue;
}
$field_definition = $this
->getFieldDefinition($field_name);
// We do not add content to the summary from base fields, skip them
// keeps performance while building the paragraph summary.
if (!$field_definition instanceof FieldConfigInterface || !$this
->get($field_name)
->access('view')) {
continue;
}
if ($field_definition
->getType() == 'image' || $field_definition
->getType() == 'file') {
$file_summary = $this
->getFileSummary($field_name);
if ($file_summary != '') {
$summary['content'][] = $file_summary;
}
}
$text_summary = $this
->getTextSummary($field_name, $field_definition);
if ($text_summary != '') {
$summary['content'][] = $text_summary;
}
if ($field_definition
->getType() == 'entity_reference_revisions') {
// Decrease the depth, since we are entering a nested paragraph.
$nested_summary = $this
->getNestedSummary($field_name, [
'show_behavior_summary' => FALSE,
'depth_limit' => $depth_limit - 1,
]);
$summary['content'] = array_merge($summary['content'], $nested_summary);
}
if ($field_definition
->getType() === 'entity_reference') {
$referenced_entities = $this
->get($field_name)
->referencedEntities();
/** @var \Drupal\Core\Entity\EntityInterface[] $referenced_entities */
foreach ($referenced_entities as $referenced_entity) {
if ($referenced_entity
->access('view label')) {
// Switch to the entity translation in the current context.
$entity = \Drupal::service('entity.repository')
->getTranslationFromContext($referenced_entity, $this
->language()
->getId());
$summary['content'][] = $entity
->label();
}
}
}
// Add the Block admin label referenced by block_field.
if ($field_definition
->getType() == 'block_field') {
if (!empty($this
->get($field_name)
->first())) {
if ($block = $block_admin_label = $this
->get($field_name)
->first()
->getBlock()) {
$block_admin_label = $block
->getPluginDefinition()['admin_label'];
}
$summary['content'][] = $block_admin_label;
}
}
if ($field_definition
->getType() == 'link') {
if (!empty($this
->get($field_name)
->first())) {
// If title is not set, fallback to the uri.
if ($title = $this
->get($field_name)->title) {
$summary['content'][] = $title;
}
else {
$summary['content'][] = $this
->get($field_name)->uri;
}
}
}
}
// Add behaviors summary items.
if ($show_behavior_summary) {
$paragraphs_type = $this
->getParagraphType();
foreach ($paragraphs_type
->getEnabledBehaviorPlugins() as $plugin) {
if ($plugin_summary = $plugin
->settingsSummary($this)) {
foreach ($plugin_summary as $plugin_summary_element) {
if (!is_array($plugin_summary_element)) {
$plugin_summary_element = [
'value' => $plugin_summary_element,
];
}
$summary['behaviors'][] = $plugin_summary_element;
}
}
}
}
return $summary;
}