From d9f05ce93e3ee70e791aa2c360878211bba177e5 Mon Sep 17 00:00:00 2001 From: Elias Hiller Date: Mon, 6 Nov 2023 13:29:18 +0100 Subject: [PATCH 01/16] Added support to create variants on object creation --- src/Resolver/Location/FindParentStrategy.php | 16 ++++++++++++++++ .../components/resolver/location/findParent.js | 6 ++++++ src/Resources/translations/admin.ca.yml | 1 + src/Resources/translations/admin.cs.yml | 1 + src/Resources/translations/admin.de.yml | 1 + src/Resources/translations/admin.en.yml | 1 + src/Resources/translations/admin.es.yml | 1 + src/Resources/translations/admin.fr.yml | 1 + src/Resources/translations/admin.hu.yml | 1 + src/Resources/translations/admin.it.yml | 1 + src/Resources/translations/admin.nl.yml | 1 + src/Resources/translations/admin.pl.yml | 1 + src/Resources/translations/admin.sk.yml | 1 + src/Resources/translations/admin.sv.yml | 1 + src/Resources/translations/admin.th.yml | 1 + src/Resources/translations/admin.zh_Hans.yml | 1 + 16 files changed, 36 insertions(+) diff --git a/src/Resolver/Location/FindParentStrategy.php b/src/Resolver/Location/FindParentStrategy.php index 4f653b61..c9d8d8c4 100644 --- a/src/Resolver/Location/FindParentStrategy.php +++ b/src/Resolver/Location/FindParentStrategy.php @@ -57,6 +57,8 @@ class FindParentStrategy implements LocationStrategyInterface */ protected $attributeLanguage; + protected bool $saveAsVariant; + public function __construct(protected DataObjectLoader $dataObjectLoader) { } @@ -75,6 +77,8 @@ public function setSettings(array $settings): void throw new InvalidConfigurationException('Empty find strategy.'); } + $this->saveAsVariant = !empty($settings['asVariant']) && $settings['asVariant'] === 'on'; + $this->findStrategy = $settings['findStrategy']; if ($this->findStrategy == self::FIND_BY_ATTRIBUTE) { @@ -129,9 +133,21 @@ public function updateParent(ElementInterface $element, array $inputData): Eleme } if ($newParent) { + if ( + $this->saveAsVariant && + $newParent instanceof DataObject\Concrete && + $newParent::class === $element::class && + $newParent->getClass()->getAllowVariants() + ) { + /** @var DataObject\Concrete $element */ + $element->setType(DataObject::OBJECT_TYPE_VARIANT); + } + return $element->setParent($newParent); } + // Save the element as variant: The parent and element need to be of the same dataobject type. + return $element; } diff --git a/src/Resources/public/js/pimcore/configuration/components/resolver/location/findParent.js b/src/Resources/public/js/pimcore/configuration/components/resolver/location/findParent.js index 17dc33b1..36542c6f 100644 --- a/src/Resources/public/js/pimcore/configuration/components/resolver/location/findParent.js +++ b/src/Resources/public/js/pimcore/configuration/components/resolver/location/findParent.js @@ -154,6 +154,12 @@ pimcore.plugin.pimcoreDataImporterBundle.configuration.components.resolver.locat fieldLabel: t('plugin_pimcore_datahub_data_importer_configpanel_fallback_path'), name: this.dataNamePrefix + 'fallbackPath', value: this.data.fallbackPath + }, + { + xtype: 'checkbox', + fieldLabel: t('plugin_pimcore_datahub_data_importer_configpanel_as_variant'), + name: this.dataNamePrefix + 'asVariant', + value: this.data.asVariant } ] }); diff --git a/src/Resources/translations/admin.ca.yml b/src/Resources/translations/admin.ca.yml index 8b89574b..8fa2df47 100644 --- a/src/Resources/translations/admin.ca.yml +++ b/src/Resources/translations/admin.ca.yml @@ -77,6 +77,7 @@ plugin_pimcore_datahub_data_importer_configpanel_create_location_strategy: Locat Strategy plugin_pimcore_datahub_data_importer_configpanel_fallback_path: Fallback Path plugin_pimcore_datahub_data_importer_configpanel_find_strategy: Find Strategy +plugin_pimcore_datahub_data_importer_configpanel_as_variant: As Variant plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findParent: Find Parent plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findOrCreateFolder: Find diff --git a/src/Resources/translations/admin.cs.yml b/src/Resources/translations/admin.cs.yml index 8b89574b..8fa2df47 100644 --- a/src/Resources/translations/admin.cs.yml +++ b/src/Resources/translations/admin.cs.yml @@ -77,6 +77,7 @@ plugin_pimcore_datahub_data_importer_configpanel_create_location_strategy: Locat Strategy plugin_pimcore_datahub_data_importer_configpanel_fallback_path: Fallback Path plugin_pimcore_datahub_data_importer_configpanel_find_strategy: Find Strategy +plugin_pimcore_datahub_data_importer_configpanel_as_variant: As Variant plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findParent: Find Parent plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findOrCreateFolder: Find diff --git a/src/Resources/translations/admin.de.yml b/src/Resources/translations/admin.de.yml index 8e9a1f2d..9e2f067e 100644 --- a/src/Resources/translations/admin.de.yml +++ b/src/Resources/translations/admin.de.yml @@ -76,6 +76,7 @@ plugin_pimcore_datahub_data_importer_configpanel_element_creation: Element-Erste plugin_pimcore_datahub_data_importer_configpanel_create_location_strategy: Pfad-Strategie plugin_pimcore_datahub_data_importer_configpanel_fallback_path: Fallback-Pfad plugin_pimcore_datahub_data_importer_configpanel_find_strategy: Strategie finden +plugin_pimcore_datahub_data_importer_configpanel_as_variant: Als Variante plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findParent: Elternteil finden plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findOrCreateFolder: Ordner diff --git a/src/Resources/translations/admin.en.yml b/src/Resources/translations/admin.en.yml index 84a5161e..700bf11f 100644 --- a/src/Resources/translations/admin.en.yml +++ b/src/Resources/translations/admin.en.yml @@ -64,6 +64,7 @@ plugin_pimcore_datahub_data_importer_configpanel_element_creation: Element Creat plugin_pimcore_datahub_data_importer_configpanel_create_location_strategy: Location Strategy plugin_pimcore_datahub_data_importer_configpanel_fallback_path: Fallback Path plugin_pimcore_datahub_data_importer_configpanel_find_strategy: Find Strategy +plugin_pimcore_datahub_data_importer_configpanel_as_variant: As Variant plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findParent: Find Parent plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findOrCreateFolder: Find or Create Folder plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_noChange: No Change diff --git a/src/Resources/translations/admin.es.yml b/src/Resources/translations/admin.es.yml index 8b89574b..8fa2df47 100644 --- a/src/Resources/translations/admin.es.yml +++ b/src/Resources/translations/admin.es.yml @@ -77,6 +77,7 @@ plugin_pimcore_datahub_data_importer_configpanel_create_location_strategy: Locat Strategy plugin_pimcore_datahub_data_importer_configpanel_fallback_path: Fallback Path plugin_pimcore_datahub_data_importer_configpanel_find_strategy: Find Strategy +plugin_pimcore_datahub_data_importer_configpanel_as_variant: As Variant plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findParent: Find Parent plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findOrCreateFolder: Find diff --git a/src/Resources/translations/admin.fr.yml b/src/Resources/translations/admin.fr.yml index 04e465d4..ee914db0 100644 --- a/src/Resources/translations/admin.fr.yml +++ b/src/Resources/translations/admin.fr.yml @@ -80,6 +80,7 @@ plugin_pimcore_datahub_data_importer_configpanel_create_location_strategy: "Stra de localisation" plugin_pimcore_datahub_data_importer_configpanel_fallback_path: Fallback Path plugin_pimcore_datahub_data_importer_configpanel_find_strategy: "Trouver une strat\xE9gie" +plugin_pimcore_datahub_data_importer_configpanel_as_variant: As Variant plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findParent: Trouver le parent plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findOrCreateFolder: "Trouver diff --git a/src/Resources/translations/admin.hu.yml b/src/Resources/translations/admin.hu.yml index 8b89574b..8fa2df47 100644 --- a/src/Resources/translations/admin.hu.yml +++ b/src/Resources/translations/admin.hu.yml @@ -77,6 +77,7 @@ plugin_pimcore_datahub_data_importer_configpanel_create_location_strategy: Locat Strategy plugin_pimcore_datahub_data_importer_configpanel_fallback_path: Fallback Path plugin_pimcore_datahub_data_importer_configpanel_find_strategy: Find Strategy +plugin_pimcore_datahub_data_importer_configpanel_as_variant: As Variant plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findParent: Find Parent plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findOrCreateFolder: Find diff --git a/src/Resources/translations/admin.it.yml b/src/Resources/translations/admin.it.yml index 8b89574b..8fa2df47 100644 --- a/src/Resources/translations/admin.it.yml +++ b/src/Resources/translations/admin.it.yml @@ -77,6 +77,7 @@ plugin_pimcore_datahub_data_importer_configpanel_create_location_strategy: Locat Strategy plugin_pimcore_datahub_data_importer_configpanel_fallback_path: Fallback Path plugin_pimcore_datahub_data_importer_configpanel_find_strategy: Find Strategy +plugin_pimcore_datahub_data_importer_configpanel_as_variant: As Variant plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findParent: Find Parent plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findOrCreateFolder: Find diff --git a/src/Resources/translations/admin.nl.yml b/src/Resources/translations/admin.nl.yml index 8b89574b..8fa2df47 100644 --- a/src/Resources/translations/admin.nl.yml +++ b/src/Resources/translations/admin.nl.yml @@ -77,6 +77,7 @@ plugin_pimcore_datahub_data_importer_configpanel_create_location_strategy: Locat Strategy plugin_pimcore_datahub_data_importer_configpanel_fallback_path: Fallback Path plugin_pimcore_datahub_data_importer_configpanel_find_strategy: Find Strategy +plugin_pimcore_datahub_data_importer_configpanel_as_variant: As Variant plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findParent: Find Parent plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findOrCreateFolder: Find diff --git a/src/Resources/translations/admin.pl.yml b/src/Resources/translations/admin.pl.yml index 8b89574b..8fa2df47 100644 --- a/src/Resources/translations/admin.pl.yml +++ b/src/Resources/translations/admin.pl.yml @@ -77,6 +77,7 @@ plugin_pimcore_datahub_data_importer_configpanel_create_location_strategy: Locat Strategy plugin_pimcore_datahub_data_importer_configpanel_fallback_path: Fallback Path plugin_pimcore_datahub_data_importer_configpanel_find_strategy: Find Strategy +plugin_pimcore_datahub_data_importer_configpanel_as_variant: As Variant plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findParent: Find Parent plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findOrCreateFolder: Find diff --git a/src/Resources/translations/admin.sk.yml b/src/Resources/translations/admin.sk.yml index 8b89574b..8fa2df47 100644 --- a/src/Resources/translations/admin.sk.yml +++ b/src/Resources/translations/admin.sk.yml @@ -77,6 +77,7 @@ plugin_pimcore_datahub_data_importer_configpanel_create_location_strategy: Locat Strategy plugin_pimcore_datahub_data_importer_configpanel_fallback_path: Fallback Path plugin_pimcore_datahub_data_importer_configpanel_find_strategy: Find Strategy +plugin_pimcore_datahub_data_importer_configpanel_as_variant: As Variant plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findParent: Find Parent plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findOrCreateFolder: Find diff --git a/src/Resources/translations/admin.sv.yml b/src/Resources/translations/admin.sv.yml index 8b89574b..8fa2df47 100644 --- a/src/Resources/translations/admin.sv.yml +++ b/src/Resources/translations/admin.sv.yml @@ -77,6 +77,7 @@ plugin_pimcore_datahub_data_importer_configpanel_create_location_strategy: Locat Strategy plugin_pimcore_datahub_data_importer_configpanel_fallback_path: Fallback Path plugin_pimcore_datahub_data_importer_configpanel_find_strategy: Find Strategy +plugin_pimcore_datahub_data_importer_configpanel_as_variant: As Variant plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findParent: Find Parent plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findOrCreateFolder: Find diff --git a/src/Resources/translations/admin.th.yml b/src/Resources/translations/admin.th.yml index 8b89574b..8fa2df47 100644 --- a/src/Resources/translations/admin.th.yml +++ b/src/Resources/translations/admin.th.yml @@ -77,6 +77,7 @@ plugin_pimcore_datahub_data_importer_configpanel_create_location_strategy: Locat Strategy plugin_pimcore_datahub_data_importer_configpanel_fallback_path: Fallback Path plugin_pimcore_datahub_data_importer_configpanel_find_strategy: Find Strategy +plugin_pimcore_datahub_data_importer_configpanel_as_variant: As Variant plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findParent: Find Parent plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findOrCreateFolder: Find diff --git a/src/Resources/translations/admin.zh_Hans.yml b/src/Resources/translations/admin.zh_Hans.yml index 8b89574b..8fa2df47 100644 --- a/src/Resources/translations/admin.zh_Hans.yml +++ b/src/Resources/translations/admin.zh_Hans.yml @@ -77,6 +77,7 @@ plugin_pimcore_datahub_data_importer_configpanel_create_location_strategy: Locat Strategy plugin_pimcore_datahub_data_importer_configpanel_fallback_path: Fallback Path plugin_pimcore_datahub_data_importer_configpanel_find_strategy: Find Strategy +plugin_pimcore_datahub_data_importer_configpanel_as_variant: As Variant plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findParent: Find Parent plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findOrCreateFolder: Find From d1853a1d7d206b981ed5b648a8f0e6fc4144828c Mon Sep 17 00:00:00 2001 From: Elias Date: Mon, 6 Nov 2023 15:45:02 +0100 Subject: [PATCH 02/16] Apply suggestions from code review Co-authored-by: Sebastian Blank --- src/Resolver/Location/FindParentStrategy.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Resolver/Location/FindParentStrategy.php b/src/Resolver/Location/FindParentStrategy.php index c9d8d8c4..6b8316c0 100644 --- a/src/Resolver/Location/FindParentStrategy.php +++ b/src/Resolver/Location/FindParentStrategy.php @@ -57,7 +57,7 @@ class FindParentStrategy implements LocationStrategyInterface */ protected $attributeLanguage; - protected bool $saveAsVariant; + protected bool $saveAsVariant = false; public function __construct(protected DataObjectLoader $dataObjectLoader) { @@ -77,7 +77,7 @@ public function setSettings(array $settings): void throw new InvalidConfigurationException('Empty find strategy.'); } - $this->saveAsVariant = !empty($settings['asVariant']) && $settings['asVariant'] === 'on'; + $this->saveAsVariant = isset($settings['asVariant']) && $settings['asVariant'] === 'on'; $this->findStrategy = $settings['findStrategy']; From 1fac68441b9015f31a0c7dc3926e4fff6a4e77b0 Mon Sep 17 00:00:00 2001 From: Elias Hiller Date: Thu, 9 Nov 2023 14:41:54 +0100 Subject: [PATCH 03/16] Added error handling when changing existing variants As the parent can be changed for variants this is now catched, as a variant cannot change its parent anymore. --- src/Resolver/Location/FindParentStrategy.php | 19 +++++++++++++------ src/Resolver/Resolver.php | 10 ++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/Resolver/Location/FindParentStrategy.php b/src/Resolver/Location/FindParentStrategy.php index 6b8316c0..58b78ea2 100644 --- a/src/Resolver/Location/FindParentStrategy.php +++ b/src/Resolver/Location/FindParentStrategy.php @@ -16,6 +16,7 @@ namespace Pimcore\Bundle\DataImporterBundle\Resolver\Location; use Pimcore\Bundle\DataImporterBundle\Exception\InvalidConfigurationException; +use Pimcore\Bundle\DataImporterBundle\Exception\InvalidInputException; use Pimcore\Bundle\DataImporterBundle\Tool\DataObjectLoader; use Pimcore\Model\DataObject; use Pimcore\Model\DataObject\ClassDefinition; @@ -133,11 +134,19 @@ public function updateParent(ElementInterface $element, array $inputData): Eleme } if ($newParent) { + if ($newParent->getType() === DataObject::OBJECT_TYPE_VARIANT) { + throw new InvalidInputException( + 'The elements desired parent is a variant which cannot have any child elements' + ); + } + + // Check if element should be saved as a variant. if ( - $this->saveAsVariant && - $newParent instanceof DataObject\Concrete && - $newParent::class === $element::class && - $newParent->getClass()->getAllowVariants() + $this->saveAsVariant + && $element instanceof DataObject\Concrete + && $element::class === $newParent::class + && $element->getClass()->getAllowVariants() + && !$element->hasChildren() ) { /** @var DataObject\Concrete $element */ $element->setType(DataObject::OBJECT_TYPE_VARIANT); @@ -146,8 +155,6 @@ public function updateParent(ElementInterface $element, array $inputData): Eleme return $element->setParent($newParent); } - // Save the element as variant: The parent and element need to be of the same dataobject type. - return $element; } diff --git a/src/Resolver/Resolver.php b/src/Resolver/Resolver.php index 97af4256..17e9aee8 100644 --- a/src/Resolver/Resolver.php +++ b/src/Resolver/Resolver.php @@ -15,10 +15,12 @@ namespace Pimcore\Bundle\DataImporterBundle\Resolver; +use Pimcore\Bundle\DataImporterBundle\Exception\InvalidInputException; use Pimcore\Bundle\DataImporterBundle\Resolver\Factory\FactoryInterface; use Pimcore\Bundle\DataImporterBundle\Resolver\Load\LoadStrategyInterface; use Pimcore\Bundle\DataImporterBundle\Resolver\Location\LocationStrategyInterface; use Pimcore\Bundle\DataImporterBundle\Resolver\Publish\PublishStrategyInterface; +use Pimcore\Model\DataObject; use Pimcore\Model\Element\ElementInterface; class Resolver @@ -149,7 +151,15 @@ public function loadOrCreateAndPrepareElement(array $inputData, bool $createNew $this->getCreateLocationStrategy()->updateParent($element, $inputData); $justCreated = true; } else { + $oldParentId = $element->getParentId(); $this->getLocationUpdateStrategy()->updateParent($element, $inputData); + + // The parent of a variant cannot be changed anymore. + if ($oldParentId !== $element->getParentId() && $element->getType() === DataObject::OBJECT_TYPE_VARIANT) { + throw new InvalidInputException( + "Element with id `{$element->getId()}` is a variant and cannot change its parent anymore" + ); + } } $this->getPublishingStrategy()->updatePublishState($element, $justCreated, $inputData); From 23419b55d77f1bca9180de9d24264db521b9bc57 Mon Sep 17 00:00:00 2001 From: Elias Hiller Date: Mon, 6 Nov 2023 13:29:18 +0100 Subject: [PATCH 04/16] Added support to create variants on object creation --- src/Resolver/Location/FindParentStrategy.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Resolver/Location/FindParentStrategy.php b/src/Resolver/Location/FindParentStrategy.php index 58b78ea2..3ca8245e 100644 --- a/src/Resolver/Location/FindParentStrategy.php +++ b/src/Resolver/Location/FindParentStrategy.php @@ -155,6 +155,8 @@ public function updateParent(ElementInterface $element, array $inputData): Eleme return $element->setParent($newParent); } + // Save the element as variant: The parent and element need to be of the same dataobject type. + return $element; } From 1e73a45b69436b153c99db6705afddb76b1ea974 Mon Sep 17 00:00:00 2001 From: Elias Hiller Date: Thu, 9 Nov 2023 14:41:54 +0100 Subject: [PATCH 05/16] Added error handling when changing existing variants As the parent can be changed for variants this is now catched, as a variant cannot change its parent anymore. --- src/Resolver/Location/FindParentStrategy.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Resolver/Location/FindParentStrategy.php b/src/Resolver/Location/FindParentStrategy.php index 3ca8245e..58b78ea2 100644 --- a/src/Resolver/Location/FindParentStrategy.php +++ b/src/Resolver/Location/FindParentStrategy.php @@ -155,8 +155,6 @@ public function updateParent(ElementInterface $element, array $inputData): Eleme return $element->setParent($newParent); } - // Save the element as variant: The parent and element need to be of the same dataobject type. - return $element; } From 91db3b3f6ea72e8499ec2b1c3aa7585d4763ec85 Mon Sep 17 00:00:00 2001 From: Elias Hiller Date: Tue, 30 Jan 2024 14:25:20 +0100 Subject: [PATCH 06/16] Removed unecessary translations --- src/Resources/translations/admin.ca.yml | 1 - src/Resources/translations/admin.cs.yml | 1 - src/Resources/translations/admin.de.yml | 1 - src/Resources/translations/admin.es.yml | 1 - src/Resources/translations/admin.fr.yml | 1 - src/Resources/translations/admin.hu.yml | 1 - src/Resources/translations/admin.it.yml | 1 - src/Resources/translations/admin.nl.yml | 1 - src/Resources/translations/admin.pl.yml | 1 - src/Resources/translations/admin.sk.yml | 1 - src/Resources/translations/admin.sv.yml | 1 - src/Resources/translations/admin.th.yml | 1 - src/Resources/translations/admin.zh_Hans.yml | 1 - 13 files changed, 13 deletions(-) diff --git a/src/Resources/translations/admin.ca.yml b/src/Resources/translations/admin.ca.yml index 8fa2df47..8b89574b 100644 --- a/src/Resources/translations/admin.ca.yml +++ b/src/Resources/translations/admin.ca.yml @@ -77,7 +77,6 @@ plugin_pimcore_datahub_data_importer_configpanel_create_location_strategy: Locat Strategy plugin_pimcore_datahub_data_importer_configpanel_fallback_path: Fallback Path plugin_pimcore_datahub_data_importer_configpanel_find_strategy: Find Strategy -plugin_pimcore_datahub_data_importer_configpanel_as_variant: As Variant plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findParent: Find Parent plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findOrCreateFolder: Find diff --git a/src/Resources/translations/admin.cs.yml b/src/Resources/translations/admin.cs.yml index 8fa2df47..8b89574b 100644 --- a/src/Resources/translations/admin.cs.yml +++ b/src/Resources/translations/admin.cs.yml @@ -77,7 +77,6 @@ plugin_pimcore_datahub_data_importer_configpanel_create_location_strategy: Locat Strategy plugin_pimcore_datahub_data_importer_configpanel_fallback_path: Fallback Path plugin_pimcore_datahub_data_importer_configpanel_find_strategy: Find Strategy -plugin_pimcore_datahub_data_importer_configpanel_as_variant: As Variant plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findParent: Find Parent plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findOrCreateFolder: Find diff --git a/src/Resources/translations/admin.de.yml b/src/Resources/translations/admin.de.yml index 9e2f067e..8e9a1f2d 100644 --- a/src/Resources/translations/admin.de.yml +++ b/src/Resources/translations/admin.de.yml @@ -76,7 +76,6 @@ plugin_pimcore_datahub_data_importer_configpanel_element_creation: Element-Erste plugin_pimcore_datahub_data_importer_configpanel_create_location_strategy: Pfad-Strategie plugin_pimcore_datahub_data_importer_configpanel_fallback_path: Fallback-Pfad plugin_pimcore_datahub_data_importer_configpanel_find_strategy: Strategie finden -plugin_pimcore_datahub_data_importer_configpanel_as_variant: Als Variante plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findParent: Elternteil finden plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findOrCreateFolder: Ordner diff --git a/src/Resources/translations/admin.es.yml b/src/Resources/translations/admin.es.yml index 8fa2df47..8b89574b 100644 --- a/src/Resources/translations/admin.es.yml +++ b/src/Resources/translations/admin.es.yml @@ -77,7 +77,6 @@ plugin_pimcore_datahub_data_importer_configpanel_create_location_strategy: Locat Strategy plugin_pimcore_datahub_data_importer_configpanel_fallback_path: Fallback Path plugin_pimcore_datahub_data_importer_configpanel_find_strategy: Find Strategy -plugin_pimcore_datahub_data_importer_configpanel_as_variant: As Variant plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findParent: Find Parent plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findOrCreateFolder: Find diff --git a/src/Resources/translations/admin.fr.yml b/src/Resources/translations/admin.fr.yml index ee914db0..04e465d4 100644 --- a/src/Resources/translations/admin.fr.yml +++ b/src/Resources/translations/admin.fr.yml @@ -80,7 +80,6 @@ plugin_pimcore_datahub_data_importer_configpanel_create_location_strategy: "Stra de localisation" plugin_pimcore_datahub_data_importer_configpanel_fallback_path: Fallback Path plugin_pimcore_datahub_data_importer_configpanel_find_strategy: "Trouver une strat\xE9gie" -plugin_pimcore_datahub_data_importer_configpanel_as_variant: As Variant plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findParent: Trouver le parent plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findOrCreateFolder: "Trouver diff --git a/src/Resources/translations/admin.hu.yml b/src/Resources/translations/admin.hu.yml index 8fa2df47..8b89574b 100644 --- a/src/Resources/translations/admin.hu.yml +++ b/src/Resources/translations/admin.hu.yml @@ -77,7 +77,6 @@ plugin_pimcore_datahub_data_importer_configpanel_create_location_strategy: Locat Strategy plugin_pimcore_datahub_data_importer_configpanel_fallback_path: Fallback Path plugin_pimcore_datahub_data_importer_configpanel_find_strategy: Find Strategy -plugin_pimcore_datahub_data_importer_configpanel_as_variant: As Variant plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findParent: Find Parent plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findOrCreateFolder: Find diff --git a/src/Resources/translations/admin.it.yml b/src/Resources/translations/admin.it.yml index 8fa2df47..8b89574b 100644 --- a/src/Resources/translations/admin.it.yml +++ b/src/Resources/translations/admin.it.yml @@ -77,7 +77,6 @@ plugin_pimcore_datahub_data_importer_configpanel_create_location_strategy: Locat Strategy plugin_pimcore_datahub_data_importer_configpanel_fallback_path: Fallback Path plugin_pimcore_datahub_data_importer_configpanel_find_strategy: Find Strategy -plugin_pimcore_datahub_data_importer_configpanel_as_variant: As Variant plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findParent: Find Parent plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findOrCreateFolder: Find diff --git a/src/Resources/translations/admin.nl.yml b/src/Resources/translations/admin.nl.yml index 8fa2df47..8b89574b 100644 --- a/src/Resources/translations/admin.nl.yml +++ b/src/Resources/translations/admin.nl.yml @@ -77,7 +77,6 @@ plugin_pimcore_datahub_data_importer_configpanel_create_location_strategy: Locat Strategy plugin_pimcore_datahub_data_importer_configpanel_fallback_path: Fallback Path plugin_pimcore_datahub_data_importer_configpanel_find_strategy: Find Strategy -plugin_pimcore_datahub_data_importer_configpanel_as_variant: As Variant plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findParent: Find Parent plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findOrCreateFolder: Find diff --git a/src/Resources/translations/admin.pl.yml b/src/Resources/translations/admin.pl.yml index 8fa2df47..8b89574b 100644 --- a/src/Resources/translations/admin.pl.yml +++ b/src/Resources/translations/admin.pl.yml @@ -77,7 +77,6 @@ plugin_pimcore_datahub_data_importer_configpanel_create_location_strategy: Locat Strategy plugin_pimcore_datahub_data_importer_configpanel_fallback_path: Fallback Path plugin_pimcore_datahub_data_importer_configpanel_find_strategy: Find Strategy -plugin_pimcore_datahub_data_importer_configpanel_as_variant: As Variant plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findParent: Find Parent plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findOrCreateFolder: Find diff --git a/src/Resources/translations/admin.sk.yml b/src/Resources/translations/admin.sk.yml index 8fa2df47..8b89574b 100644 --- a/src/Resources/translations/admin.sk.yml +++ b/src/Resources/translations/admin.sk.yml @@ -77,7 +77,6 @@ plugin_pimcore_datahub_data_importer_configpanel_create_location_strategy: Locat Strategy plugin_pimcore_datahub_data_importer_configpanel_fallback_path: Fallback Path plugin_pimcore_datahub_data_importer_configpanel_find_strategy: Find Strategy -plugin_pimcore_datahub_data_importer_configpanel_as_variant: As Variant plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findParent: Find Parent plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findOrCreateFolder: Find diff --git a/src/Resources/translations/admin.sv.yml b/src/Resources/translations/admin.sv.yml index 8fa2df47..8b89574b 100644 --- a/src/Resources/translations/admin.sv.yml +++ b/src/Resources/translations/admin.sv.yml @@ -77,7 +77,6 @@ plugin_pimcore_datahub_data_importer_configpanel_create_location_strategy: Locat Strategy plugin_pimcore_datahub_data_importer_configpanel_fallback_path: Fallback Path plugin_pimcore_datahub_data_importer_configpanel_find_strategy: Find Strategy -plugin_pimcore_datahub_data_importer_configpanel_as_variant: As Variant plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findParent: Find Parent plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findOrCreateFolder: Find diff --git a/src/Resources/translations/admin.th.yml b/src/Resources/translations/admin.th.yml index 8fa2df47..8b89574b 100644 --- a/src/Resources/translations/admin.th.yml +++ b/src/Resources/translations/admin.th.yml @@ -77,7 +77,6 @@ plugin_pimcore_datahub_data_importer_configpanel_create_location_strategy: Locat Strategy plugin_pimcore_datahub_data_importer_configpanel_fallback_path: Fallback Path plugin_pimcore_datahub_data_importer_configpanel_find_strategy: Find Strategy -plugin_pimcore_datahub_data_importer_configpanel_as_variant: As Variant plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findParent: Find Parent plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findOrCreateFolder: Find diff --git a/src/Resources/translations/admin.zh_Hans.yml b/src/Resources/translations/admin.zh_Hans.yml index 8fa2df47..8b89574b 100644 --- a/src/Resources/translations/admin.zh_Hans.yml +++ b/src/Resources/translations/admin.zh_Hans.yml @@ -77,7 +77,6 @@ plugin_pimcore_datahub_data_importer_configpanel_create_location_strategy: Locat Strategy plugin_pimcore_datahub_data_importer_configpanel_fallback_path: Fallback Path plugin_pimcore_datahub_data_importer_configpanel_find_strategy: Find Strategy -plugin_pimcore_datahub_data_importer_configpanel_as_variant: As Variant plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findParent: Find Parent plugin_pimcore_datahub_data_importer_configpanel_createLocationStrategy.type_findOrCreateFolder: Find From a5836ea7c920feb4ab2845d78c8b668ea38ac8b4 Mon Sep 17 00:00:00 2001 From: Elias Hiller Date: Tue, 30 Jan 2024 14:48:43 +0100 Subject: [PATCH 07/16] Addressed some qodana warnings --- src/Resolver/Location/FindParentStrategy.php | 31 ++++++++++++-------- src/Resolver/Resolver.php | 10 +++++-- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/Resolver/Location/FindParentStrategy.php b/src/Resolver/Location/FindParentStrategy.php index 58b78ea2..76d879b6 100644 --- a/src/Resolver/Location/FindParentStrategy.php +++ b/src/Resolver/Location/FindParentStrategy.php @@ -15,10 +15,12 @@ namespace Pimcore\Bundle\DataImporterBundle\Resolver\Location; +use Exception; use Pimcore\Bundle\DataImporterBundle\Exception\InvalidConfigurationException; use Pimcore\Bundle\DataImporterBundle\Exception\InvalidInputException; use Pimcore\Bundle\DataImporterBundle\Tool\DataObjectLoader; use Pimcore\Model\DataObject; +use Pimcore\Model\DataObject\AbstractObject; use Pimcore\Model\DataObject\ClassDefinition; use Pimcore\Model\Element\ElementInterface; @@ -134,25 +136,28 @@ public function updateParent(ElementInterface $element, array $inputData): Eleme } if ($newParent) { - if ($newParent->getType() === DataObject::OBJECT_TYPE_VARIANT) { + if ($newParent->getType() === AbstractObject::OBJECT_TYPE_VARIANT) { throw new InvalidInputException( 'The elements desired parent is a variant which cannot have any child elements' ); } - // Check if element should be saved as a variant. - if ( - $this->saveAsVariant - && $element instanceof DataObject\Concrete - && $element::class === $newParent::class - && $element->getClass()->getAllowVariants() - && !$element->hasChildren() - ) { - /** @var DataObject\Concrete $element */ - $element->setType(DataObject::OBJECT_TYPE_VARIANT); + try { + // Check if element should be saved as a variant. + if ( + $this->saveAsVariant + && $element instanceof DataObject\Concrete + && $element::class === $newParent::class + && !$element->hasChildren() + && $element->getClass()->getAllowVariants() + ) { + $element->setType(AbstractObject::OBJECT_TYPE_VARIANT); + } + + return $element->setParent($newParent); + } catch (Exception) { + // Exception might be thrown by $element->getClass(). } - - return $element->setParent($newParent); } return $element; diff --git a/src/Resolver/Resolver.php b/src/Resolver/Resolver.php index 17e9aee8..c4da3707 100644 --- a/src/Resolver/Resolver.php +++ b/src/Resolver/Resolver.php @@ -20,7 +20,7 @@ use Pimcore\Bundle\DataImporterBundle\Resolver\Load\LoadStrategyInterface; use Pimcore\Bundle\DataImporterBundle\Resolver\Location\LocationStrategyInterface; use Pimcore\Bundle\DataImporterBundle\Resolver\Publish\PublishStrategyInterface; -use Pimcore\Model\DataObject; +use Pimcore\Model\DataObject\AbstractObject; use Pimcore\Model\Element\ElementInterface; class Resolver @@ -136,6 +136,9 @@ public function loadElementByIdentifier($identifier): ?ElementInterface return $this->getLoadingStrategy()->loadElementByIdentifier($identifier); } + /** + * @throws InvalidInputException + */ public function loadOrCreateAndPrepareElement(array $inputData, bool $createNew = true): ?ElementInterface { $element = $this->loadElement($inputData); @@ -155,7 +158,10 @@ public function loadOrCreateAndPrepareElement(array $inputData, bool $createNew $this->getLocationUpdateStrategy()->updateParent($element, $inputData); // The parent of a variant cannot be changed anymore. - if ($oldParentId !== $element->getParentId() && $element->getType() === DataObject::OBJECT_TYPE_VARIANT) { + if ( + $oldParentId !== $element->getParentId() + && $element->getType() === AbstractObject::OBJECT_TYPE_VARIANT + ) { throw new InvalidInputException( "Element with id `{$element->getId()}` is a variant and cannot change its parent anymore" ); From 19b96299fdc3571263a24b15b8da9011fd734532 Mon Sep 17 00:00:00 2001 From: Elias Hiller Date: Mon, 25 Mar 2024 14:24:51 +0100 Subject: [PATCH 08/16] Allowing variants to be parents of variants of the same class --- src/Resolver/Location/FindParentStrategy.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Resolver/Location/FindParentStrategy.php b/src/Resolver/Location/FindParentStrategy.php index 76d879b6..f9136abc 100644 --- a/src/Resolver/Location/FindParentStrategy.php +++ b/src/Resolver/Location/FindParentStrategy.php @@ -136,9 +136,16 @@ public function updateParent(ElementInterface $element, array $inputData): Eleme } if ($newParent) { - if ($newParent->getType() === AbstractObject::OBJECT_TYPE_VARIANT) { + + if ( + $newParent->getType() === AbstractObject::OBJECT_TYPE_VARIANT && + ( + $element->getType() !== AbstractObject::OBJECT_TYPE_VARIANT || + $element::class !== $newParent::class + ) + ) { throw new InvalidInputException( - 'The elements desired parent is a variant which cannot have any child elements' + "An element can only have a variant as a parent if it's of the same class." ); } From 2dfd425188da84401704e1dcdc17a6f6ae4048ab Mon Sep 17 00:00:00 2001 From: turbo-ele Date: Mon, 25 Mar 2024 13:25:12 +0000 Subject: [PATCH 09/16] Apply php-cs-fixer changes --- src/Resolver/Location/FindParentStrategy.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Resolver/Location/FindParentStrategy.php b/src/Resolver/Location/FindParentStrategy.php index f9136abc..c7ac2300 100644 --- a/src/Resolver/Location/FindParentStrategy.php +++ b/src/Resolver/Location/FindParentStrategy.php @@ -136,7 +136,6 @@ public function updateParent(ElementInterface $element, array $inputData): Eleme } if ($newParent) { - if ( $newParent->getType() === AbstractObject::OBJECT_TYPE_VARIANT && ( From 04e7ce4f74365c0ab7acc07b70ca64cee2187e03 Mon Sep 17 00:00:00 2001 From: Elias Hiller Date: Mon, 25 Mar 2024 14:29:54 +0100 Subject: [PATCH 10/16] fixup! Allowing variants to be parents of variants of the same class --- src/Resolver/Location/FindParentStrategy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resolver/Location/FindParentStrategy.php b/src/Resolver/Location/FindParentStrategy.php index f9136abc..8e90fd56 100644 --- a/src/Resolver/Location/FindParentStrategy.php +++ b/src/Resolver/Location/FindParentStrategy.php @@ -145,7 +145,7 @@ public function updateParent(ElementInterface $element, array $inputData): Eleme ) ) { throw new InvalidInputException( - "An element can only have a variant as a parent if it's of the same class." + "An element can only have a variant as a parent if it's a variant itself and of the same class." ); } From e0a48f47714d74251e47598e5bc987270e9bc794 Mon Sep 17 00:00:00 2001 From: Elias Hiller Date: Tue, 26 Mar 2024 07:23:48 +0100 Subject: [PATCH 11/16] Added check if parent has changed --- src/Resolver/Location/FindParentStrategy.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Resolver/Location/FindParentStrategy.php b/src/Resolver/Location/FindParentStrategy.php index 92aff248..159f8607 100644 --- a/src/Resolver/Location/FindParentStrategy.php +++ b/src/Resolver/Location/FindParentStrategy.php @@ -135,6 +135,11 @@ public function updateParent(ElementInterface $element, array $inputData): Eleme $newParent = DataObject::getByPath($this->fallbackPath); } + // If parent has not changed - no need to update. + if ($element->getParentId() && $element->getParentId() === $newParent?->getId()) { + return $element; + } + if ($newParent) { if ( $newParent->getType() === AbstractObject::OBJECT_TYPE_VARIANT && From c1c629636c54f1ea70cbcf9f1c68346222001a7f Mon Sep 17 00:00:00 2001 From: Elias Hiller Date: Tue, 26 Mar 2024 11:46:34 +0100 Subject: [PATCH 12/16] Added individual exceptions when variant type cannot be set --- src/Resolver/Location/FindParentStrategy.php | 70 ++++++++++++++------ 1 file changed, 49 insertions(+), 21 deletions(-) diff --git a/src/Resolver/Location/FindParentStrategy.php b/src/Resolver/Location/FindParentStrategy.php index 159f8607..9a4ce0ae 100644 --- a/src/Resolver/Location/FindParentStrategy.php +++ b/src/Resolver/Location/FindParentStrategy.php @@ -135,11 +135,6 @@ public function updateParent(ElementInterface $element, array $inputData): Eleme $newParent = DataObject::getByPath($this->fallbackPath); } - // If parent has not changed - no need to update. - if ($element->getParentId() && $element->getParentId() === $newParent?->getId()) { - return $element; - } - if ($newParent) { if ( $newParent->getType() === AbstractObject::OBJECT_TYPE_VARIANT && @@ -153,22 +148,9 @@ public function updateParent(ElementInterface $element, array $inputData): Eleme ); } - try { - // Check if element should be saved as a variant. - if ( - $this->saveAsVariant - && $element instanceof DataObject\Concrete - && $element::class === $newParent::class - && !$element->hasChildren() - && $element->getClass()->getAllowVariants() - ) { - $element->setType(AbstractObject::OBJECT_TYPE_VARIANT); - } - - return $element->setParent($newParent); - } catch (Exception) { - // Exception might be thrown by $element->getClass(). - } + $this->setElementType($element, $newParent); + + return $element->setParent($newParent); } return $element; @@ -177,4 +159,50 @@ public function updateParent(ElementInterface $element, array $inputData): Eleme protected function loadById() { } + + /** + * @throws InvalidInputException + */ + private function setElementType(ElementInterface $element, DataObject|ElementInterface $newParent): void + { + // Check if element should be saved as a variant if not already. + if ( + $this->saveAsVariant && $element->getType() !== AbstractObject::OBJECT_TYPE_VARIANT + ) { + if ( + !$element instanceof DataObject\Concrete + || $element::class !== $newParent::class + ) { + throw new InvalidInputException( + 'Only concrete objects of the same class can be saved as a variant.' + ); + } + + if ($element->hasChildren()) { + throw new InvalidInputException( + 'Only objects without any children can be saved as a variant.' + ); + } + + if (!$this->getElementClassDefinition($element)?->getAllowVariants()) { + throw new InvalidInputException( + sprintf( + 'Class `%s` is not configured to allow the creation of variants.', + $this->getElementClassDefinition($element)?->getName(), + ) + ); + } + + $element->setType(AbstractObject::OBJECT_TYPE_VARIANT); + } + } + + private function getElementClassDefinition(ElementInterface $element): ?ClassDefinition + { + try { + return $element->getClass(); + } catch (Exception) { + return null; + } + } } From 044ee811c33322e5480ff8c8ea04e01317080913 Mon Sep 17 00:00:00 2001 From: turbo-ele Date: Tue, 26 Mar 2024 10:46:52 +0000 Subject: [PATCH 13/16] Apply php-cs-fixer changes --- src/Resolver/Location/FindParentStrategy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resolver/Location/FindParentStrategy.php b/src/Resolver/Location/FindParentStrategy.php index 9a4ce0ae..639adc5b 100644 --- a/src/Resolver/Location/FindParentStrategy.php +++ b/src/Resolver/Location/FindParentStrategy.php @@ -163,7 +163,7 @@ protected function loadById() /** * @throws InvalidInputException */ - private function setElementType(ElementInterface $element, DataObject|ElementInterface $newParent): void + private function setElementType(ElementInterface $element, DataObject | ElementInterface $newParent): void { // Check if element should be saved as a variant if not already. if ( From 536d0eea11c515154d39909c24646c45bb732dd9 Mon Sep 17 00:00:00 2001 From: Elias Hiller Date: Tue, 26 Mar 2024 14:11:17 +0100 Subject: [PATCH 14/16] fixup! Added individual exceptions when variant type cannot be set --- src/Resolver/Location/FindParentStrategy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resolver/Location/FindParentStrategy.php b/src/Resolver/Location/FindParentStrategy.php index 9a4ce0ae..575e75a8 100644 --- a/src/Resolver/Location/FindParentStrategy.php +++ b/src/Resolver/Location/FindParentStrategy.php @@ -197,7 +197,7 @@ private function setElementType(ElementInterface $element, DataObject|ElementInt } } - private function getElementClassDefinition(ElementInterface $element): ?ClassDefinition + private function getElementClassDefinition(DataObject\Concrete $element): ?ClassDefinition { try { return $element->getClass(); From 862977ef3b6a043070886c1553140b1df0d0444b Mon Sep 17 00:00:00 2001 From: Elias Hiller Date: Wed, 10 Apr 2024 15:52:48 +0200 Subject: [PATCH 15/16] Allowing variants to be changed to objects --- src/Resolver/Location/FindParentStrategy.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Resolver/Location/FindParentStrategy.php b/src/Resolver/Location/FindParentStrategy.php index eb7a21e6..5606988e 100644 --- a/src/Resolver/Location/FindParentStrategy.php +++ b/src/Resolver/Location/FindParentStrategy.php @@ -174,26 +174,36 @@ private function setElementType(ElementInterface $element, DataObject | ElementI || $element::class !== $newParent::class ) { throw new InvalidInputException( - 'Only concrete objects of the same class can be saved as a variant.' + 'Changing type not possible: Only concrete objects of the same class can be saved as a variant.' ); } if ($element->hasChildren()) { throw new InvalidInputException( - 'Only objects without any children can be saved as a variant.' + 'Changing type not possible: Only objects without any children can be saved as a variant.' ); } if (!$this->getElementClassDefinition($element)?->getAllowVariants()) { throw new InvalidInputException( sprintf( - 'Class `%s` is not configured to allow the creation of variants.', + 'Changing type not possible: Class `%s` is not configured to allow the creation of variants.', $this->getElementClassDefinition($element)?->getName(), ) ); } $element->setType(AbstractObject::OBJECT_TYPE_VARIANT); + } elseif ( + !$this->saveAsVariant && $element->getType() !== AbstractObject::OBJECT_TYPE_OBJECT + ) { + if ($newParent->getType() === AbstractObject::OBJECT_TYPE_VARIANT) { + throw new InvalidInputException( + 'Changing type not possible: An object cannot be a child of a variant.' + ); + } + + $element->setType(AbstractObject::OBJECT_TYPE_OBJECT); } } From c457958f5fbcbc1b5226826dbaa24b46581fbb5c Mon Sep 17 00:00:00 2001 From: Elias Hiller Date: Mon, 15 Apr 2024 12:33:09 +0200 Subject: [PATCH 16/16] fixup! Allowing variants to be changed to objects --- src/Resolver/Location/FindParentStrategy.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Resolver/Location/FindParentStrategy.php b/src/Resolver/Location/FindParentStrategy.php index 5606988e..4b794ebf 100644 --- a/src/Resolver/Location/FindParentStrategy.php +++ b/src/Resolver/Location/FindParentStrategy.php @@ -195,7 +195,9 @@ private function setElementType(ElementInterface $element, DataObject | ElementI $element->setType(AbstractObject::OBJECT_TYPE_VARIANT); } elseif ( - !$this->saveAsVariant && $element->getType() !== AbstractObject::OBJECT_TYPE_OBJECT + !$this->saveAsVariant + && $element instanceof AbstractObject + && $element->getType() === AbstractObject::OBJECT_TYPE_VARIANT ) { if ($newParent->getType() === AbstractObject::OBJECT_TYPE_VARIANT) { throw new InvalidInputException(