function Section::insertAfterComponent

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

Inserts a component after a specified existing component.

Parameters

string $preceding_uuid: The UUID of the existing component to insert after.

\Drupal\layout_builder\SectionComponent $component: The component being inserted.

Return value

$this

Throws

\InvalidArgumentException Thrown when the expected UUID does not exist.

File

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

Class

Section
Provides a domain object for layout sections.

Namespace

Drupal\layout_builder

Code

public function insertAfterComponent($preceding_uuid, SectionComponent $component) {
    // Find the delta of the specified UUID.
    $uuids = array_keys($this->getComponentsByRegion($component->getRegion()));
    $delta = array_search($preceding_uuid, $uuids, TRUE);
    if ($delta === FALSE) {
        throw new \InvalidArgumentException(sprintf('Invalid preceding UUID "%s"', $preceding_uuid));
    }
    return $this->insertComponent($delta + 1, $component);
}

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