diff --git a/src/Plugin/Block/EntityEditFormBlock.php b/src/Plugin/Block/EntityEditFormBlock.php index 9286389..7fbafe5 100644 --- a/src/Plugin/Block/EntityEditFormBlock.php +++ b/src/Plugin/Block/EntityEditFormBlock.php @@ -3,6 +3,7 @@ namespace Drupal\entityform_block\Plugin\Block; use Drupal\Core\Block\BlockBase; +use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityDisplayRepositoryInterface; use Drupal\Core\Entity\EntityFormBuilder; use Drupal\Core\Entity\EntityTypeBundleInfoInterface; @@ -12,7 +13,6 @@ use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\ContextAwarePluginInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountProxyInterface; -use Drupal\user\EntityOwnerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -179,13 +179,9 @@ class EntityEditFormBlock extends BlockBase implements ContextAwarePluginInterfa public function build() { /* @var $entity \Drupal\Core\Entity\EntityInterface */ $entity = $this->getContextValue('entity'); - - if ($entity->isNew() && $this->entityType->hasKey('bundle')) { - $entity->set($this->entityType->getKey('bundle'), $this->configuration['bundle']); - } - - if ($entity->isNew() && $entity instanceof EntityOwnerInterface) { - $entity->setOwnerId($this->currentUser->id()); + if (!$entity instanceof ContentEntityInterface) { + $entity = $this->entityTypeManager->getStorage($this->entityType->id()) + ->create([$this->entityType->getKey('bundle') => $this->configuration['bundle']]); } return $this->entityFormBuilder->getForm($entity, $this->configuration['view_mode']);