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

Issue #3438379: Set _referringItem in LayoutParagraphsLayout

parent 6c589733
No related branches found
No related tags found
1 merge request!158Resolve #3438379 "Set referringitem in"
Pipeline #138960 passed with warnings
...@@ -97,4 +97,17 @@ interface ComponentFormInterface extends FormInterface { ...@@ -97,4 +97,17 @@ interface ComponentFormInterface extends FormInterface {
*/ */
public function successfulAjaxSubmit(array $form, FormStateInterface $form_state); public function successfulAjaxSubmit(array $form, FormStateInterface $form_state);
/**
* Get the form mode.
*/
public function getFormMode();
/**
* Set the form view mode.
*
* @param string $view_mode
* The view mode.
*/
public function setFormMode($view_mode);
} }
...@@ -83,6 +83,13 @@ abstract class ComponentFormBase extends FormBase implements ComponentFormInterf ...@@ -83,6 +83,13 @@ abstract class ComponentFormBase extends FormBase implements ComponentFormInterf
*/ */
protected $entityRepository; protected $entityRepository;
/**
* The form mode to use for rendering the form.
*
* @var string
*/
protected $formMode = 'default';
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
...@@ -157,7 +164,7 @@ abstract class ComponentFormBase extends FormBase implements ComponentFormInterf ...@@ -157,7 +164,7 @@ abstract class ComponentFormBase extends FormBase implements ComponentFormInterf
FormStateInterface $form_state) { FormStateInterface $form_state) {
$this->initFormLangcodes($form_state); $this->initFormLangcodes($form_state);
$display = EntityFormDisplay::collectRenderDisplay($this->paragraph, 'default'); $display = EntityFormDisplay::collectRenderDisplay($this->paragraph, $this->getFormMode());
$display->buildForm($this->paragraph, $form, $form_state); $display->buildForm($this->paragraph, $form, $form_state);
$this->paragraphType = $this->paragraph->getParagraphType(); $this->paragraphType = $this->paragraph->getParagraphType();
$lp_config = $this->config('layout_paragraphs.settings'); $lp_config = $this->config('layout_paragraphs.settings');
...@@ -607,4 +614,18 @@ abstract class ComponentFormBase extends FormBase implements ComponentFormInterf ...@@ -607,4 +614,18 @@ abstract class ComponentFormBase extends FormBase implements ComponentFormInterf
return []; return [];
} }
/**
* {@inheritDoc}
*/
public function getFormMode() {
return $this->formMode;
}
/**
* {@inheritDoc}
*/
public function setFormMode($view_mode) {
$this->formMode = $view_mode;
}
} }
...@@ -164,6 +164,11 @@ class LayoutParagraphsLayout implements ThirdPartySettingsInterface { ...@@ -164,6 +164,11 @@ class LayoutParagraphsLayout implements ThirdPartySettingsInterface {
* @return $this * @return $this
*/ */
public function setParagraphsReferenceField(EntityReferenceFieldItemListInterface $paragraphs_reference_field) { 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; $this->paragraphsReferenceField = $paragraphs_reference_field;
return $this; return $this;
} }
...@@ -399,9 +404,11 @@ class LayoutParagraphsLayout implements ThirdPartySettingsInterface { ...@@ -399,9 +404,11 @@ class LayoutParagraphsLayout implements ThirdPartySettingsInterface {
$new_paragraph = $component->getEntity(); $new_paragraph = $component->getEntity();
$new_paragraph->setParentEntity($this->getEntity(), $this->getFieldName()); $new_paragraph->setParentEntity($this->getEntity(), $this->getFieldName());
// Splice the new paragraph into the field item list. // 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]; $list[] = ['entity' => $new_paragraph];
$this->paragraphsReferenceField->setValue($list); $item_list->setValue($list);
$this->setParagraphsReferenceField($item_list);
} }
else { else {
// @todo Throw exception. // @todo Throw exception.
...@@ -470,11 +477,13 @@ class LayoutParagraphsLayout implements ThirdPartySettingsInterface { ...@@ -470,11 +477,13 @@ class LayoutParagraphsLayout implements ThirdPartySettingsInterface {
$new_paragraph = $new_component->getEntity(); $new_paragraph = $new_component->getEntity();
$new_paragraph->setParentEntity($this->getEntity(), $this->getFieldName()); $new_paragraph->setParentEntity($this->getEntity(), $this->getFieldName());
// Splice the new paragraph into the field item list. // 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 = $this->getComponentDeltaByUuid($sibling_uuid);
$delta += $delta_offset; $delta += $delta_offset;
array_splice($list, $delta, 0, ['entity' => $new_paragraph]); array_splice($list, $delta, 0, ['entity' => $new_paragraph]);
$this->paragraphsReferenceField->setValue($list); $item_list->setValue($list);
$this->setParagraphsReferenceField($item_list);
} }
else { else {
// @todo Throw exception. // @todo Throw exception.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment