You are here

public function ParagraphsSummaryFormatter::viewElements in Paragraphs 8

Builds a renderable array for a field value.

Parameters

\Drupal\Core\Field\FieldItemListInterface $items: The field values to be rendered.

string $langcode: The language that should be used to render the field.

Return value

array A renderable array for $items, as an array of child elements keyed by consecutive numeric indexes starting from 0.

Overrides FormatterInterface::viewElements

1 call to ParagraphsSummaryFormatter::viewElements()
LibraryItemSummaryFormatter::viewElements in modules/paragraphs_library/src/Plugin/Field/FieldFormatter/LibraryItemSummaryFormatter.php
Builds a renderable array for a field value.
1 method overrides ParagraphsSummaryFormatter::viewElements()
LibraryItemSummaryFormatter::viewElements in modules/paragraphs_library/src/Plugin/Field/FieldFormatter/LibraryItemSummaryFormatter.php
Builds a renderable array for a field value.

File

src/Plugin/Field/FieldFormatter/ParagraphsSummaryFormatter.php, line 26

Class

ParagraphsSummaryFormatter
Plugin implementation of the 'paragraph_summary' formatter.

Namespace

Drupal\paragraphs\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
  $elements = [];
  foreach ($this
    ->getEntitiesToView($items, $langcode) as $delta => $entity) {
    if ($entity
      ->id()) {
      $elements[$delta] = [
        '#type' => 'container',
        '#attributes' => [
          'class' => [
            'paragraph-formatter',
          ],
        ],
      ];
      $elements[$delta]['info'] = [
        '#type' => 'container',
        '#attributes' => [
          'class' => [
            'paragraph-info',
          ],
        ],
      ];
      $elements[$delta]['info'] += $entity
        ->getIcons();
      $elements[$delta]['summary'] = [
        '#type' => 'container',
        '#attributes' => [
          'class' => [
            'paragraph-summary',
          ],
        ],
      ];
      $elements[$delta]['summary']['description'] = [
        '#theme' => 'paragraphs_summary',
        '#summary' => $entity
          ->getSummaryItems(),
      ];
    }
  }
  $elements['#attached']['library'][] = 'paragraphs/drupal.paragraphs.formatter';
  return $elements;
}