function Section::toRenderArray

Same name and namespace in other branches
  1. 11.x core/modules/layout_builder/src/Section.php \Drupal\layout_builder\Section::toRenderArray()
  2. 10 core/modules/layout_builder/src/Section.php \Drupal\layout_builder\Section::toRenderArray()
  3. 9 core/modules/layout_builder/src/Section.php \Drupal\layout_builder\Section::toRenderArray()
  4. main core/modules/layout_builder/src/Section.php \Drupal\layout_builder\Section::toRenderArray()

Returns the renderable array for this section.

Parameters

\Drupal\Core\Plugin\Context\ContextInterface[] $contexts: An array of available contexts.

bool $in_preview: TRUE if the section is being previewed, FALSE otherwise.

Return value

array A renderable array representing the content of the section.

File

core/modules/layout_builder/src/Section.php, line 83

Class

Section
Provides a domain object for layout sections.

Namespace

Drupal\layout_builder

Code

public function toRenderArray(array $contexts = [], $in_preview = FALSE) {
  $regions = [];
  foreach ($this->getComponents() as $component) {
    if ($output = $component->toRenderArray($contexts, $in_preview)) {
      $regions[$component->getRegion()][$component->getUuid()] = $output;
    }
  }
  return $this->getLayout()
    ->build($regions);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.