You are here

public function Section::getComponentsByRegion in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/layout_builder/src/Section.php \Drupal\layout_builder\Section::getComponentsByRegion()
  2. 9 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 262

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();
  });
  return $components;
}