You are here

public function Section::getComponentsByRegion in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/layout_builder/src/Section.php \Drupal\layout_builder\Section::getComponentsByRegion()

Gets the components for a specific region.

Parameters

string $region: The region name.

Return value

\Drupal\layout_builder\SectionComponent[] An array of components in the specified region, sorted by weight.

3 calls to Section::getComponentsByRegion()
Section::getNextHighestWeight in core/modules/layout_builder/src/Section.php
Returns the next highest weight of the component in a region.
Section::insertAfterComponent in core/modules/layout_builder/src/Section.php
Inserts a component after a specified existing component.
Section::insertComponent in core/modules/layout_builder/src/Section.php
Inserts a component at a specified delta.

File

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

Class

Section
Provides a domain object for layout sections.

Namespace

Drupal\layout_builder

Code

public function getComponentsByRegion($region) {
  $components = array_filter($this
    ->getComponents(), function (SectionComponent $component) use ($region) {
    return $component
      ->getRegion() === $region;
  });
  uasort($components, function (SectionComponent $a, SectionComponent $b) {
    return $a
      ->getWeight() > $b
      ->getWeight() ? 1 : -1;
  });
  return $components;
}