You are here

public function LayoutParagraphsLayout::deleteComponent in Layout Paragraphs 2.0.x

Delete a component.

Parameters

string $uuid: The uuid of the component to delete.

bool $recursive: Recursively delete child components.

Return value

$this

File

src/LayoutParagraphsLayout.php, line 465

Class

LayoutParagraphsLayout
Provides a domain object for a complete Layout Paragraphs Layout.

Namespace

Drupal\layout_paragraphs

Code

public function deleteComponent(string $uuid, $recursive = FALSE) {
  if ($recursive) {
    $component = $this
      ->getComponentByUuid($uuid);
    if ($component
      ->isLayout()) {

      /** @var \Drupal\layout_paragraphs\LayoutParagraphsSection $section */
      $section = $this
        ->getLayoutSection($component
        ->getEntity());
      foreach ($section
        ->getComponents() as $component) {
        $this
          ->deleteComponent($component
          ->getEntity()
          ->uuid(), TRUE);
      }
    }
  }
  $delta = $this
    ->getComponentDeltaByUuid($uuid);
  if (isset($this->paragraphsReferenceField[$delta])) {
    unset($this->paragraphsReferenceField[$delta]);
  }
  return $this;
}