You are here

protected function Section::getNextHighestWeight in Drupal 10

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

Returns the next highest weight of the component in a region.

Parameters

string $region: The region name.

Return value

int A number higher than the highest weight of the component in the region.

1 call to Section::getNextHighestWeight()
Section::appendComponent in core/modules/layout_builder/src/Section.php
Appends a component to the end of a region.

File

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

Class

Section
Provides a domain object for layout sections.

Namespace

Drupal\layout_builder

Code

protected function getNextHighestWeight($region) {
  $components = $this
    ->getComponentsByRegion($region);
  $weights = array_map(function (SectionComponent $component) {
    return $component
      ->getWeight();
  }, $components);
  return $weights ? max($weights) + 1 : 0;
}