diff --git a/composer.json b/composer.json index 2f545b2350ceca5d867c4748bcfbfb26a247dcfd..1f3ad6bb58da8ac6930997eb3b05d2ea504b1c09 100644 --- a/composer.json +++ b/composer.json @@ -301,6 +301,9 @@ }, "drupal/linkit": { "2712951": "https://www.drupal.org/files/issues/2019-11-27/linkit_for_link_field-2712951-140.patch" + }, + "drupal/entity_clone": { + "3060223": "https://www.drupal.org/files/issues/2019-10-17/%20entity_clone-corrupted-paragraph-cloning-3060223-5.patch" } } }, diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 9ca848dc7dea5779c81f3fbf949395c44bc08107..7ac7ec2fac4f96eed6b41df65a186e1ef774a4c0 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -4617,6 +4617,9 @@ "status": "not-covered", "message": "Beta releases are not covered by Drupal security advisories." } + }, + "patches_applied": { + "3060223": "https://www.drupal.org/files/issues/2019-10-17/%20entity_clone-corrupted-paragraph-cloning-3060223-5.patch" } }, "installation-source": "dist", diff --git a/web/modules/entity_clone/PATCHES.txt b/web/modules/entity_clone/PATCHES.txt new file mode 100644 index 0000000000000000000000000000000000000000..c6ac62dbfd6451506c3c00425e0bcdfbea88b370 --- /dev/null +++ b/web/modules/entity_clone/PATCHES.txt @@ -0,0 +1,7 @@ +This file was automatically generated by Composer Patches (https://github.com/cweagans/composer-patches) +Patches applied to this directory: + +3060223 +Source: https://www.drupal.org/files/issues/2019-10-17/%20entity_clone-corrupted-paragraph-cloning-3060223-5.patch + + diff --git a/web/modules/entity_clone/src/EntityClone/Content/ContentEntityCloneBase.php b/web/modules/entity_clone/src/EntityClone/Content/ContentEntityCloneBase.php index dea3e7bdf8de2de4c067d1ed4ad0d6ad45b8629f..17bf7b2dcce55aa5f6d234357f00f6e0703364ea 100644 --- a/web/modules/entity_clone/src/EntityClone/Content/ContentEntityCloneBase.php +++ b/web/modules/entity_clone/src/EntityClone/Content/ContentEntityCloneBase.php @@ -11,6 +11,7 @@ use Drupal\Core\Field\FieldConfigInterface; use Drupal\Core\Field\FieldItemListInterface; use Drupal\entity_clone\EntityClone\EntityCloneInterface; +use Drupal\Component\Datetime\TimeInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -25,6 +26,13 @@ class ContentEntityCloneBase implements EntityHandlerInterface, EntityCloneInter */ protected $entityTypeManager; + /** + * The time service. + * + * @var \Drupal\Component\Datetime\TimeInterface + */ + protected $time; + /** * The entity type ID. * @@ -37,12 +45,15 @@ class ContentEntityCloneBase implements EntityHandlerInterface, EntityCloneInter * * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * The entity type manager. + * @param \Drupal\Component\Datetime\TimeInterface $time + * The time service. * @param string $entity_type_id * The entity type ID. */ - public function __construct(EntityTypeManagerInterface $entity_type_manager, $entity_type_id) { + public function __construct(EntityTypeManagerInterface $entity_type_manager, TimeInterface $time, $entity_type_id) { $this->entityTypeManager = $entity_type_manager; $this->entityTypeId = $entity_type_id; + $this->time = $time; } /** @@ -51,6 +62,7 @@ public function __construct(EntityTypeManagerInterface $entity_type_manager, $en public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { return new static( $container->get('entity_type.manager'), + $container->get('datetime.time'), $entity_type->id() ); } @@ -60,7 +72,6 @@ public static function createInstance(ContainerInterface $container, EntityTypeI */ public function cloneEntity(EntityInterface $entity, EntityInterface $cloned_entity, array $properties = [], array &$already_cloned = []) { // Clone referenced entities. - $cloned_entity->save(); $already_cloned[$entity->getEntityTypeId()][$entity->id()] = $cloned_entity; if ($cloned_entity instanceof FieldableEntityInterface && $entity instanceof FieldableEntityInterface) { foreach ($cloned_entity->getFieldDefinitions() as $field_id => $field_definition) { @@ -75,7 +86,10 @@ public function cloneEntity(EntityInterface $entity, EntityInterface $cloned_ent } $this->setClonedEntityLabel($entity, $cloned_entity); + $this->setClonedEntityChangedTime($cloned_entity); + $this->setClonedEntityCreatedTime($cloned_entity); $cloned_entity->save(); + $entity->save(); return $cloned_entity; } @@ -116,6 +130,30 @@ protected function setClonedEntityLabel(EntityInterface $original_entity, Entity } } + /** + * Sets the cloned entity's Changed Time. + * + * @param \Drupal\Core\Entity\EntityInterface $cloned_entity + * The entity cloned from the original. + */ + protected function setClonedEntityChangedTime(EntityInterface $cloned_entity) { + if ($cloned_entity->hasField('changed')) { + $cloned_entity->set('changed', $this->time->getRequestTime()); + } + } + + /** + * Sets the cloned entity's Created Time. + * + * @param \Drupal\Core\Entity\EntityInterface $cloned_entity + * The entity cloned from the original. + */ + protected function setClonedEntityCreatedTime(EntityInterface $cloned_entity) { + if ($cloned_entity->hasField('created')) { + $cloned_entity->set('created', $this->time->getRequestTime()); + } + } + /** * Clone referenced entities. *