Skip to content
Snippets Groups Projects
Commit 88569f5f authored by Justin Toupin's avatar Justin Toupin
Browse files

Set _referringItem on entities

parent 3dd79b5c
No related branches found
No related tags found
No related merge requests found
......@@ -164,6 +164,11 @@ class LayoutParagraphsLayout implements ThirdPartySettingsInterface {
* @return $this
*/
public function setParagraphsReferenceField(EntityReferenceFieldItemListInterface $paragraphs_reference_field) {
foreach ($paragraphs_reference_field as $key => $field_item) {
if ($field_item->entity) {
$paragraphs_reference_field[$key]->entity->_referringItem = $field_item;
}
}
$this->paragraphsReferenceField = $paragraphs_reference_field;
return $this;
}
......@@ -399,9 +404,11 @@ class LayoutParagraphsLayout implements ThirdPartySettingsInterface {
$new_paragraph = $component->getEntity();
$new_paragraph->setParentEntity($this->getEntity(), $this->getFieldName());
// Splice the new paragraph into the field item list.
$list = $this->paragraphsReferenceField->getValue();
$item_list = $this->getParagraphsReferenceField();
$list = $item_list->getValue();
$list[] = ['entity' => $new_paragraph];
$this->paragraphsReferenceField->setValue($list);
$item_list->setValue($list);
$this->setParagraphsReferenceField($item_list);
}
else {
// @todo Throw exception.
......@@ -470,11 +477,13 @@ class LayoutParagraphsLayout implements ThirdPartySettingsInterface {
$new_paragraph = $new_component->getEntity();
$new_paragraph->setParentEntity($this->getEntity(), $this->getFieldName());
// Splice the new paragraph into the field item list.
$list = $this->paragraphsReferenceField->getValue();
$item_list = $this->getParagraphsReferenceField();
$list = $item_list->getValue();
$delta = $this->getComponentDeltaByUuid($sibling_uuid);
$delta += $delta_offset;
array_splice($list, $delta, 0, ['entity' => $new_paragraph]);
$this->paragraphsReferenceField->setValue($list);
$item_list->setValue($list);
$this->setParagraphsReferenceField($item_list);
}
else {
// @todo Throw exception.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment