You are here

public function Section::insertAfterComponent in Drupal 8

Same name and namespace 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()

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