diff --git a/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php b/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php index 43aa267..8c41a04 100644 --- a/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php +++ b/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php @@ -20,6 +20,8 @@ use Drupal\paragraphs; use Drupal\paragraphs\ParagraphInterface; use Symfony\Component\Validator\ConstraintViolationInterface; use Drupal\paragraphs\Plugin\EntityReferenceSelection\ParagraphSelection; +use Drupal\quickedit\Form\QuickEditFieldForm; +use Drupal\Core\Entity\EntityFormInterface; /** @@ -1256,6 +1258,16 @@ class InlineParagraphsWidget extends WidgetBase { * {@inheritdoc} */ public function massageFormValues(array $values, array $form, FormStateInterface $form_state) { + $form_object = $form_state->getFormObject(); + // establish whether we're in a normal EntityForm context or an inline QuickeditFieldForm context + // and retrieve the entity from the respectively appropriate place + if ($form_object instanceof EntityFormInterface) { + $entity = $form_object->getEntity(); + } else if ($form_object instanceof QuickEditFieldForm) { + $entity = $form_state->getBuildInfo()['args'][0]; + } else { + //TODO handle this case? + } $field_name = $this->fieldDefinition->getName(); $widget_state = static::getWidgetState($form['#parents'], $field_name, $form_state); $element = NestedArray::getValue($form_state->getCompleteForm(), $widget_state['array_parents']); diff --git a/src/Plugin/Field/FieldWidget/ParagraphsWidget.php b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php index a82ee34..e6ae3a8 100644 --- a/src/Plugin/Field/FieldWidget/ParagraphsWidget.php +++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php @@ -18,6 +18,8 @@ use Drupal\Core\Render\Element; use Drupal\paragraphs; use Drupal\paragraphs\ParagraphInterface; use Drupal\paragraphs\Plugin\EntityReferenceSelection\ParagraphSelection; +use Drupal\quickedit\Form\QuickEditFieldForm; +use Drupal\Core\Entity\EntityFormInterface; /** * Plugin implementation of the 'entity_reference_revisions paragraphs' widget. @@ -1322,6 +1324,16 @@ class ParagraphsWidget extends WidgetBase { * {@inheritdoc} */ public function massageFormValues(array $values, array $form, FormStateInterface $form_state) { + $form_object = $form_state->getFormObject(); + // establish whether we're in a normal EntityForm context or an inline QuickeditFieldForm context + // and retrieve the entity from the respectively appropriate place + if ($form_object instanceof EntityFormInterface) { + $entity = $form_object->getEntity(); + } else if ($form_object instanceof QuickEditFieldForm) { + $entity = $form_state->getBuildInfo()['args'][0]; + } else { + //TODO handle this case? + } $field_name = $this->fieldDefinition->getName(); $widget_state = static::getWidgetState($form['#parents'], $field_name, $form_state); $element = NestedArray::getValue($form_state->getCompleteForm(), $widget_state['array_parents']);