diff --git a/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php b/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php index ae2c560..f7b4e92 100644 --- a/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php +++ b/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php @@ -10,6 +10,7 @@ namespace Drupal\inline_entity_form\Plugin\Field\FieldWidget; use Drupal\Component\Utility\NestedArray; use Drupal\Component\Utility\SortArray; use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Entity\RevisionableInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldItemListInterface; @@ -54,7 +55,7 @@ class InlineEntityFormComplex extends InlineEntityFormBase implements ContainerF * The widget settings. * @param array $third_party_settings * Any third party settings. - * @param \Drupal\Core\Entity\EntityManager $entity_manager + * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * Entity manager service. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * Module handler service. @@ -178,6 +179,7 @@ class InlineEntityFormComplex extends InlineEntityFormBase implements ContainerF $settings = $this->getSettings(); $target_type = $this->getFieldSetting('target_type'); + // Get the entity type labels for the UI strings. $labels = $this->labels(); @@ -618,7 +620,6 @@ 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(); } @@ -627,7 +628,7 @@ class InlineEntityFormComplex extends InlineEntityFormBase implements ContainerF unset($items[$delta]); } if (!empty($item['needs_save'])) { - if ($is_revisionable) { + if ($entity instanceof RevisionableInterface) { $entity->setNewRevision(); // If a new revision is created, save the current user as revision author. $entity->setRevisionCreationTime(REQUEST_TIME); @@ -639,11 +640,10 @@ class InlineEntityFormComplex extends InlineEntityFormBase implements ContainerF $entity->setRevisionUser(\Drupal::currentUser()); } } + } } } - - // Let the widget massage the submitted values. $values = $this->massageFormValues($values, $form, $form_state); @@ -672,9 +672,8 @@ 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) { + if ($item['entity'] instanceof RevisionableInterface) { $item['target_revision_id'] = $item['entity']->getRevisionId(); } $items[] = $item;