diff --git a/src/Form/EntityInlineForm.php b/src/Form/EntityInlineForm.php index 24765f0..41ca64a 100644 --- a/src/Form/EntityInlineForm.php +++ b/src/Form/EntityInlineForm.php @@ -242,30 +242,6 @@ public function entityFormSubmit(&$entity_form, FormStateInterface $form_state) $entity = $entity_form['#entity']; $this->buildEntity($entity_form, $entity, $form_state); - if ($entity_form['#save_entity']) { - // The entity was already validated in entityFormValidate(). - $entity->setValidationRequired(FALSE); - if (!empty($item['needs_save'])) { - if ($entity instanceof RevisionableInterface) { - $entity->setNewRevision(); - - // If a new revision is created, save the current user as revision author. - if (in_array('Drupal\node\NodeInterface', class_implements($entity))) { - $entity->setRevisionAuthorId(\Drupal::currentUser()->id()); - $entity->setRevisionCreationTime(REQUEST_TIME); - } - elseif (in_array('Drupal\entity\Revision\EntityRevisionLogInterface', class_implements($entity))) { - $entity->setRevisionUserId(\Drupal::currentUser()->id()); - $entity->setRevisionCreationTime(REQUEST_TIME); - } - elseif (in_array('\Drupal\Core\Entity\RevisionLogInterface', class_implements($entity))) { - $entity->setRevisionUserId(\Drupal::currentUser()->id()); - $entity->setRevisionCreationTime(REQUEST_TIME); - } - } - } - $entity->save(); - } // TODO - this is field-only part of the code. Figure out how to refactor. if ($form_state->has(['inline_entity_form', $entity_form['#ief_id']])) { $form_state->set(['inline_entity_form', $entity_form['#ief_id'], 'entity'], $entity); @@ -300,6 +276,25 @@ protected function buildEntity(array $entity_form, ContentEntityInterface $entit call_user_func_array($function, [$entity->getEntityTypeId(), $entity, &$entity_form, &$form_state]); } } + + $entity->setValidationRequired(FALSE); + if ($entity instanceof RevisionableInterface) { + $entity->setNewRevision(); + + // If a new revision is created, save the current user as revision author. + if (in_array('Drupal\node\NodeInterface', class_implements($entity))) { + $entity->setRevisionAuthorId(\Drupal::currentUser()->id()); + $entity->setRevisionCreationTime(REQUEST_TIME); + } + elseif (in_array('Drupal\entity\Revision\EntityRevisionLogInterface', class_implements($entity))) { + $entity->setRevisionUserId(\Drupal::currentUser()->id()); + $entity->setRevisionCreationTime(REQUEST_TIME); + } + elseif (in_array('\Drupal\Core\Entity\RevisionLogInterface', class_implements($entity))) { + $entity->setRevisionUserId(\Drupal::currentUser()->id()); + $entity->setRevisionCreationTime(REQUEST_TIME); + } + } } /**