function Section::getNextHighestWeight

Same name in other branches
  1. 9 core/modules/layout_builder/src/Section.php \Drupal\layout_builder\Section::getNextHighestWeight()
  2. 8.9.x core/modules/layout_builder/src/Section.php \Drupal\layout_builder\Section::getNextHighestWeight()
  3. 11.x 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 251

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;
}

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