diff --git a/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php b/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php index 8b912e0..ae2c560 100644 --- a/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php +++ b/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php @@ -26,7 +26,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface; * id = "inline_entity_form_complex", * label = @Translation("Inline entity form - Complex"), * field_types = { - * "entity_reference" + * "entity_reference", + * "entity_reference_revisions" * }, * multiple_values = true * ) @@ -617,6 +618,7 @@ class InlineEntityFormComplex extends InlineEntityFormBase implements ContainerF foreach ($values as $delta => &$item) { /** @var \Drupal\Core\Entity\EntityInterface $entity */ $entity = $item['entity']; + $is_revisionable = \Drupal::entityManager()->getStorage($entity->getEntityTypeId())->getEntityType()->isRevisionable(); if (!empty($item['needs_save'])) { $entity->save(); } @@ -624,6 +626,19 @@ class InlineEntityFormComplex extends InlineEntityFormBase implements ContainerF $entity->delete(); unset($items[$delta]); } + if (!empty($item['needs_save'])) { + if ($is_revisionable) { + $entity->setNewRevision(); + // If a new revision is created, save the current user as revision author. + $entity->setRevisionCreationTime(REQUEST_TIME); + + if (in_array('Drupal\node\NodeInterface', class_implements($entity))) { + $entity->setRevisionAuthorId(\Drupal::currentUser()->id()); + } + elseif (in_array('Drupal\entity\Revision\EntityRevisionLogInterface', class_implements($entity))) { + $entity->setRevisionUser(\Drupal::currentUser()); + } + } } } @@ -657,7 +672,11 @@ class InlineEntityFormComplex extends InlineEntityFormBase implements ContainerF foreach ($values as $value) { $item = $value; if (isset($item['entity'])) { + $is_revisionable = \Drupal::entityManager()->getStorage($item['entity']->getEntityTypeId())->getEntityType()->isRevisionable(); $item['target_id'] = $item['entity']->id(); + if ($is_revisionable) { + $item['target_revision_id'] = $item['entity']->getRevisionId(); + } $items[] = $item; } else { diff --git a/src/Plugin/Field/FieldWidget/InlineEntityFormSimple.php b/src/Plugin/Field/FieldWidget/InlineEntityFormSimple.php index 102e734..0b93d67 100644 --- a/src/Plugin/Field/FieldWidget/InlineEntityFormSimple.php +++ b/src/Plugin/Field/FieldWidget/InlineEntityFormSimple.php @@ -20,7 +20,8 @@ use Drupal\Core\Form\FormStateInterface; * id = "inline_entity_form_simple", * label = @Translation("Inline entity form - Simple"), * field_types = { - * "entity_reference" + * "entity_reference", + * "entity_reference_revisions" * }, * multiple_values = false * )