public function LayoutParagraphsLayout::setComponent in Layout Paragraphs 2.0.x
Sets a layout component.
If a component is found with a matching paragraph, the matching component's paragraph is overwritten with the incoming paragraph. Otherwise the paragraph is appended to the field item list.
Parameters
\Drupal\paragraphs\Entity\Paragraph $paragraph: The paragraph to set.
Return value
$this
File
- src/
LayoutParagraphsLayout.php, line 296
Class
- LayoutParagraphsLayout
- Provides a domain object for a complete Layout Paragraphs Layout.
Namespace
Drupal\layout_paragraphsCode
public function setComponent(Paragraph $paragraph) {
$delta = $this
->getComponentDeltaByUuid($paragraph
->uuid());
if ($delta > -1) {
$this->paragraphsReferenceField[$delta]->entity = $paragraph;
}
else {
$this->paragraphsReferenceField[] = $paragraph;
}
return $this;
}