You are here

public function LayoutParagraphsFormatter::buildLayoutTree in Layout Paragraphs 1.0.x

Builds the structure for the entire layout.

Parameters

\Drupal\Core\Field\FieldItemListInterface $items: The items to render.

string $langcode: The current language code.

Return value

array A render array.

Throws

\Drupal\Component\Plugin\Exception\PluginException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

\Drupal\Core\TypedData\Exception\MissingDataException

See also

EntityReferenceRevisionsEntityFormatter::viewElements()

1 call to LayoutParagraphsFormatter::buildLayoutTree()
LayoutParagraphsFormatter::viewElements in src/Plugin/Field/FieldFormatter/LayoutParagraphsFormatter.php

File

src/Plugin/Field/FieldFormatter/LayoutParagraphsFormatter.php, line 103

Class

LayoutParagraphsFormatter
Layout Paragraphs field formatter.

Namespace

Drupal\layout_paragraphs\Plugin\Field\FieldFormatter

Code

public function buildLayoutTree(FieldItemListInterface $items, $langcode) {
  $build = [];
  $containerUUID = FALSE;

  /** @var \Drupal\paragraphs\Entity\Paragraph $entity */
  $entities_to_view = $this
    ->getEntitiesToView($items, $langcode);
  while ($entity = array_shift($entities_to_view)) {
    static $depth = 0;
    $depth++;
    if ($depth > 20) {
      $this->loggerFactory
        ->get('entity')
        ->error($this
        ->t('Recursive rendering detected when rendering entity @entity_type @entity_id. Aborting rendering.', [
        '@entity_type' => $entity
          ->getEntityTypeId(),
        '@entity_id' => $entity
          ->id(),
      ]));
      return $build;
    }
    if ($entity
      ->getBehaviorSetting('layout_paragraphs', 'layout', '')) {
      $containerUUID = $entity
        ->uuid();
      $build[$containerUUID] = $this
        ->buildLayoutContainer($entity, $entities_to_view);
    }
    else {
      $build[$entity
        ->uuid()] = $this
        ->buildEntityView($entity);
    }

    // Remove the item if it is disabled.
    if ('_disabled' == $entity
      ->getBehaviorSetting('layout_paragraphs', 'region', '')) {
      unset($build[$entity
        ->uuid()]);
    }
    $depth = 0;
  }
  return $build;
}