From 9ce4fdc36b96bc8734104cb1a76f779f52eba6b0 Mon Sep 17 00:00:00 2001 From: lukmzig <30526586+lukmzig@users.noreply.github.com> Date: Thu, 28 Nov 2024 11:21:34 +0100 Subject: [PATCH 1/4] [Improvement]: Ignore undefined data object adapters for now (#583) * ignore undefined adapters for now as not field types from all bundles are implemented yet * fix: sonar * fix: sonar * Apply php-cs-fixer changes * fix: rather skip setter than use null value for it * Apply php-cs-fixer changes * fix: remove unused data service --------- Co-authored-by: lukmzig --- src/DataObject/Data/Adapter/BlockAdapter.php | 37 ++++++++++++++++--- .../Adapter/ClassificationStoreAdapter.php | 12 +++++- .../Data/Adapter/EncryptedFieldAdapter.php | 33 +++++++++++++++-- .../Data/Adapter/FieldCollectionsAdapter.php | 14 +++++-- .../Data/Adapter/LocalizedFieldsAdapter.php | 28 +++++++++----- .../Data/Adapter/ObjectBricksAdapter.php | 14 +++++-- src/DataObject/Service/DataAdapterService.php | 13 +++++++ .../Service/DataAdapterServiceInterface.php | 5 +++ src/DataObject/Service/DataService.php | 6 ++- .../Loader/TaggedIteratorDataAdapter.php | 2 +- .../Util/Trait/ValidateFieldTypeTrait.php | 32 ++++++++++++++++ src/Updater/Service/UpdateService.php | 20 ++++++---- 12 files changed, 180 insertions(+), 36 deletions(-) create mode 100644 src/DataObject/Util/Trait/ValidateFieldTypeTrait.php diff --git a/src/DataObject/Data/Adapter/BlockAdapter.php b/src/DataObject/Data/Adapter/BlockAdapter.php index 584eb9a1..c6ed0939 100644 --- a/src/DataObject/Data/Adapter/BlockAdapter.php +++ b/src/DataObject/Data/Adapter/BlockAdapter.php @@ -23,6 +23,7 @@ use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterServiceInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataServiceInterface; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait\ValidateFieldTypeTrait; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidDataTypeException; use Pimcore\Model\DataObject\ClassDefinition\Data; use Pimcore\Model\DataObject\ClassDefinition\Data\Block; @@ -38,6 +39,8 @@ #[AutoconfigureTag(DataAdapterLoaderInterface::ADAPTER_TAG)] final readonly class BlockAdapter implements SetterDataInterface, DataNormalizerInterface { + use ValidateFieldTypeTrait; + public function __construct( private DataAdapterServiceInterface $dataAdapterService, private DataServiceInterface $dataService @@ -148,13 +151,24 @@ private function processBlockElement( $fieldContextData = $this->createFieldContextData($element, $fieldDefinition, $contextData); foreach ($fieldDefinitions as $elementName => $fd) { - $resultElement[$elementName] = $this->createBlockElement( + $adapter = $this->dataAdapterService->tryDataAdapter($fd->getFieldType()); + if (!$adapter) { + continue; + } + + $value = $this->createBlockElement( + $adapter, $element, $fd, $elementName, $blockElement, $fieldContextData ); + if (!$value) { + continue; + } + + $resultElement[$elementName] = $value; } return $resultElement; @@ -164,24 +178,37 @@ private function processBlockElement( * @throws Exception */ private function createBlockElement( + SetterDataInterface $adapter, Concrete $element, Data $fieldDefinition, string $elementName, ?array $blockElement, ?FieldContextData $fieldContextData = null - ): BlockElement { + ): ?BlockElement { $elementType = $fieldDefinition->getFieldtype(); $elementData = $blockElement[$elementName] ?? null; - $adapter = $this->dataAdapterService->getDataAdapter($elementType); - $blockData = $adapter->getDataForSetter( + $data = $adapter->getDataForSetter( $element, $fieldDefinition, $elementName, [$elementName => $elementData], $fieldContextData ); + if (!$this->validateEncryptedField($fieldDefinition, $data)) { + return null; + } - return new BlockElement($elementName, $elementType, $blockData); + return new BlockElement( + $elementName, + $elementType, + $adapter->getDataForSetter( + $element, + $fieldDefinition, + $elementName, + [$elementName => $elementData], + $fieldContextData + ) + ); } } diff --git a/src/DataObject/Data/Adapter/ClassificationStoreAdapter.php b/src/DataObject/Data/Adapter/ClassificationStoreAdapter.php index 5392f4e3..6d37d966 100644 --- a/src/DataObject/Data/Adapter/ClassificationStoreAdapter.php +++ b/src/DataObject/Data/Adapter/ClassificationStoreAdapter.php @@ -28,6 +28,7 @@ use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterServiceInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataServiceInterface; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait\ValidateFieldTypeTrait; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\DatabaseException; use Pimcore\Model\DataObject\ClassDefinition\Data; use Pimcore\Model\DataObject\ClassDefinition\Data\Classificationstore as ClassificationstoreDefinition; @@ -47,6 +48,8 @@ #[AutoconfigureTag(DataAdapterLoaderInterface::ADAPTER_TAG)] final readonly class ClassificationStoreAdapter implements SetterDataInterface, DataNormalizerInterface { + use ValidateFieldTypeTrait; + public function __construct( private DefinitionCacheResolverInterface $definitionCacheResolver, private DataAdapterServiceInterface $dataAdapterService, @@ -182,13 +185,20 @@ private function processGroupKeys( continue; } - $adapter = $this->dataAdapterService->getDataAdapter($fieldDefinition->getFieldType()); + $adapter = $this->dataAdapterService->tryDataAdapter($fieldDefinition->getFieldType()); + if ($adapter === null) { + continue; + } + $setterData = $adapter->getDataForSetter( $element, $fieldDefinition, $fieldDefinition->getName(), [$fieldDefinition->getName() => $value] ); + if (!$this->validateEncryptedField($fieldDefinition, $setterData)) { + continue; + } $container->setLocalizedKeyValue($groupId, $keyId, $setterData, $language); } diff --git a/src/DataObject/Data/Adapter/EncryptedFieldAdapter.php b/src/DataObject/Data/Adapter/EncryptedFieldAdapter.php index 89c7ec62..445772f6 100644 --- a/src/DataObject/Data/Adapter/EncryptedFieldAdapter.php +++ b/src/DataObject/Data/Adapter/EncryptedFieldAdapter.php @@ -21,6 +21,7 @@ use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterServiceInterface; use Pimcore\Model\DataObject\ClassDefinition\Data; +use Pimcore\Model\DataObject\ClassDefinition\Data\EncryptedField as EncryptedFieldDefinition; use Pimcore\Model\DataObject\Concrete; use Pimcore\Model\DataObject\Data\EncryptedField; use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag; @@ -43,7 +44,7 @@ public function getDataForSetter( array $data, ?FieldContextData $contextData = null ): ?EncryptedField { - if (!($fieldDefinition instanceof Data\EncryptedField)) { + if (!$fieldDefinition instanceof EncryptedFieldDefinition) { return null; } @@ -51,9 +52,33 @@ public function getDataForSetter( if (!$delegateFieldDefinition) { return null; } - $adapter = $this->dataAdapterService->getDataAdapter($delegateFieldDefinition->getFieldType()); - $result = $adapter->getDataForSetter($element, $delegateFieldDefinition, $key, $data); - return new EncryptedField($fieldDefinition->getDelegate(), $result); + return $this->handleDelegatedField( + $element, + $delegateFieldDefinition, + $fieldDefinition, + $key, + $data, + $contextData + ); + } + + private function handleDelegatedField( + Concrete $element, + Data $delegateFieldDefinition, + EncryptedFieldDefinition $fieldDefinition, + string $key, + array $data, + ?FieldContextData $contextData = null + ): ?EncryptedField { + $adapter = $this->dataAdapterService->tryDataAdapter($fieldDefinition->getFieldType()); + if ($adapter instanceof SetterDataInterface) { + return new EncryptedField( + $fieldDefinition->getDelegate(), + $adapter->getDataForSetter($element, $delegateFieldDefinition, $key, $data, $contextData) + ); + } + + return null; } } diff --git a/src/DataObject/Data/Adapter/FieldCollectionsAdapter.php b/src/DataObject/Data/Adapter/FieldCollectionsAdapter.php index 6a314767..155b203c 100644 --- a/src/DataObject/Data/Adapter/FieldCollectionsAdapter.php +++ b/src/DataObject/Data/Adapter/FieldCollectionsAdapter.php @@ -24,6 +24,7 @@ use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterServiceInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataServiceInterface; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait\ValidateFieldTypeTrait; use Pimcore\Model\DataObject\ClassDefinition\Data; use Pimcore\Model\DataObject\ClassDefinition\Data\Fieldcollections; use Pimcore\Model\DataObject\Concrete; @@ -38,6 +39,8 @@ #[AutoconfigureTag(DataAdapterLoaderInterface::ADAPTER_TAG)] final readonly class FieldCollectionsAdapter implements SetterDataInterface, DataNormalizerInterface { + use ValidateFieldTypeTrait; + public function __construct( private DataAdapterServiceInterface $dataAdapterService, private DataServiceInterface $dataService, @@ -146,18 +149,23 @@ private function processCollectionRaw( foreach ($collectionDef?->getFieldDefinitions() as $elementName => $fd) { $elementValue = $blockElement[$elementName] ?? null; - if (!$elementValue) { + $adapter = $this->dataAdapterService->tryDataAdapter($fd->getFieldType()); + if (!$elementValue || !$adapter) { continue; } - $adapter = $this->dataAdapterService->getDataAdapter($fd->getFieldType()); - $collectionData[$elementName] = $adapter->getDataForSetter( + $value = $adapter->getDataForSetter( $element, $fd, $elementName, [$elementName => $elementValue], $fieldContextData ); + if (!$this->validateEncryptedField($fieldDefinition, $value)) { + continue; + } + + $collectionData[$elementName] = $value; } return $collectionData; diff --git a/src/DataObject/Data/Adapter/LocalizedFieldsAdapter.php b/src/DataObject/Data/Adapter/LocalizedFieldsAdapter.php index 6891020b..af5c9673 100644 --- a/src/DataObject/Data/Adapter/LocalizedFieldsAdapter.php +++ b/src/DataObject/Data/Adapter/LocalizedFieldsAdapter.php @@ -23,6 +23,7 @@ use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterServiceInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataServiceInterface; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait\ValidateFieldTypeTrait; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\DatabaseException; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException; use Pimcore\Bundle\StudioBackendBundle\Security\Service\SecurityServiceInterface; @@ -43,6 +44,8 @@ #[AutoconfigureTag(DataAdapterLoaderInterface::ADAPTER_TAG)] final readonly class LocalizedFieldsAdapter implements SetterDataInterface, DataNormalizerInterface { + use ValidateFieldTypeTrait; + public function __construct( private DataAdapterServiceInterface $dataAdapterService, private DataServiceInterface $dataService, @@ -75,18 +78,23 @@ public function getDataForSetter( continue; } - $adapter = $this->dataAdapterService->getDataAdapter($childFieldDefinition->getFieldType()); - $localizedField->setLocalizedValue( + $adapter = $this->dataAdapterService->tryDataAdapter($childFieldDefinition->getFieldType()); + if (!$adapter) { + continue; + } + + $value = $adapter->getDataForSetter( + $element, + $childFieldDefinition, $name, - $adapter->getDataForSetter( - $element, - $childFieldDefinition, - $name, - [$name => $fieldData], - new FieldContextData(language: $language) - ), - $language + [$name => $fieldData], + new FieldContextData(language: $language) ); + if (!$this->validateEncryptedField($childFieldDefinition, $value)) { + continue; + } + + $localizedField->setLocalizedValue($name, $value, $language); } } diff --git a/src/DataObject/Data/Adapter/ObjectBricksAdapter.php b/src/DataObject/Data/Adapter/ObjectBricksAdapter.php index a1b15656..c472000f 100644 --- a/src/DataObject/Data/Adapter/ObjectBricksAdapter.php +++ b/src/DataObject/Data/Adapter/ObjectBricksAdapter.php @@ -24,6 +24,7 @@ use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterServiceInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataServiceInterface; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait\ValidateFieldTypeTrait; use Pimcore\Model\DataObject\ClassDefinition\Data; use Pimcore\Model\DataObject\ClassDefinition\Data\Objectbricks; use Pimcore\Model\DataObject\Concrete; @@ -39,6 +40,8 @@ #[AutoconfigureTag(DataAdapterLoaderInterface::ADAPTER_TAG)] final readonly class ObjectBricksAdapter implements SetterDataInterface, DataNormalizerInterface { + use ValidateFieldTypeTrait; + public function __construct( private DataAdapterServiceInterface $dataAdapterService, private DataServiceInterface $dataService, @@ -177,19 +180,24 @@ private function getCollectionData( ): array { $collectionData = []; foreach ($collectionDef->getFieldDefinitions() as $fd) { + $adapter = $this->dataAdapterService->tryDataAdapter($fd->getFieldType()); $fieldName = $fd->getName(); - if (!array_key_exists($fieldName, $rawData)) { + if (!array_key_exists($fieldName, $rawData) || !$adapter) { continue; } - $adapter = $this->dataAdapterService->getDataAdapter($fd->getFieldType()); - $collectionData[$fd->getName()] = $adapter->getDataForSetter( + $value = $adapter->getDataForSetter( $element, $fd, $fieldName, [$fieldName => $rawData[$fieldName]], new FieldContextData($brick) ); + if (!$this->validateEncryptedField($fd, $value)) { + continue; + } + + $collectionData[$fieldName] = $value; } return $collectionData; diff --git a/src/DataObject/Service/DataAdapterService.php b/src/DataObject/Service/DataAdapterService.php index cac29b63..76813f0a 100644 --- a/src/DataObject/Service/DataAdapterService.php +++ b/src/DataObject/Service/DataAdapterService.php @@ -54,10 +54,23 @@ public function getFieldDefinitionAdapterClass(string $fieldDefinitionType): str ); } + /** + * @throws InvalidArgumentException + */ public function getDataAdapter(string $fieldDefinitionType): SetterDataInterface { return $this->dataAdapterLoader->loadAdapter( $this->getFieldDefinitionAdapterClass($fieldDefinitionType) ); } + + // ToDo: Consider removing this method and using getDataAdapter when field types from bundles are implemented + public function tryDataAdapter(string $fieldDefinitionType): ?SetterDataInterface + { + try { + return $this->getDataAdapter($fieldDefinitionType); + } catch (InvalidArgumentException) { + return null; + } + } } diff --git a/src/DataObject/Service/DataAdapterServiceInterface.php b/src/DataObject/Service/DataAdapterServiceInterface.php index 6fdfffed..c3968ab6 100644 --- a/src/DataObject/Service/DataAdapterServiceInterface.php +++ b/src/DataObject/Service/DataAdapterServiceInterface.php @@ -31,5 +31,10 @@ public function getAdaptersMapping(): array; */ public function getFieldDefinitionAdapterClass(string $fieldDefinitionType): string; + /** + * @throws InvalidArgumentException + */ public function getDataAdapter(string $fieldDefinitionType): SetterDataInterface; + + public function tryDataAdapter(string $fieldDefinitionType): ?SetterDataInterface; } diff --git a/src/DataObject/Service/DataService.php b/src/DataObject/Service/DataService.php index 4981daa7..8e5a7e50 100644 --- a/src/DataObject/Service/DataService.php +++ b/src/DataObject/Service/DataService.php @@ -49,10 +49,12 @@ public function getObjectData(Concrete $dataObject): array foreach ($fieldDefinitions as $key => $fieldDefinition) { try { - $data[$key] = $this->getNormalizedValue($dataObject->get($key), $fieldDefinition); + $value = $dataObject->get($key); } catch (Exception) { throw new NotFoundException(type: 'field', id: $key); } + + $data[$key] = $this->getNormalizedValue($value, $fieldDefinition); } return $data; @@ -85,7 +87,7 @@ public function getNormalizedValue( return null; } - $adapter = $this->dataAdapterService->getDataAdapter($fieldDefinition->getFieldType()); + $adapter = $this->dataAdapterService->tryDataAdapter($fieldDefinition->getFieldType()); if ($adapter instanceof DataNormalizerInterface) { return $adapter->normalize($value, $fieldDefinition); } diff --git a/src/DataObject/Service/Loader/TaggedIteratorDataAdapter.php b/src/DataObject/Service/Loader/TaggedIteratorDataAdapter.php index ac7e84b2..3de81935 100644 --- a/src/DataObject/Service/Loader/TaggedIteratorDataAdapter.php +++ b/src/DataObject/Service/Loader/TaggedIteratorDataAdapter.php @@ -16,9 +16,9 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Service\Loader; -use InvalidArgumentException; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; +use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException; use Symfony\Component\DependencyInjection\Attribute\TaggedIterator; use function get_class; use function sprintf; diff --git a/src/DataObject/Util/Trait/ValidateFieldTypeTrait.php b/src/DataObject/Util/Trait/ValidateFieldTypeTrait.php new file mode 100644 index 00000000..a7f6b6bd --- /dev/null +++ b/src/DataObject/Util/Trait/ValidateFieldTypeTrait.php @@ -0,0 +1,32 @@ +getClass(); foreach ($editableData as $key => $value) { $fieldDefinition = $class->getFieldDefinition($key); - if ($fieldDefinition === null) { + if ($fieldDefinition === null || !array_key_exists($key, $editableData)) { continue; } - $data = array_key_exists($key, $editableData) - ? $this->dataAdapterService - ->getDataAdapter($fieldDefinition->getFieldType()) - ->getDataForSetter($element, $fieldDefinition, $key, $editableData) - : null; + $adapter = $this->dataAdapterService->tryDataAdapter($fieldDefinition->getFieldtype()); + if ($adapter === null) { + continue; + } + + $value = $adapter->getDataForSetter($element, $fieldDefinition, $key, $editableData); + if (!$this->validateEncryptedField($fieldDefinition, $value)) { + continue; + } - $element->setValue($key, $data); + $element->setValue($key, $value); } } catch (Exception $e) { From 5464233ac4144ef8e9a88dc7c1cb9ad7ea153e4a Mon Sep 17 00:00:00 2001 From: lukmzig <30526586+lukmzig@users.noreply.github.com> Date: Thu, 28 Nov 2024 13:29:47 +0100 Subject: [PATCH 2/4] [Data Object Editor]: Resolve normalizer issues (#591) * fix: resolve normalizer issues * Apply php-cs-fixer changes * adjust additional adapters * Apply php-cs-fixer changes --------- Co-authored-by: lukmzig --- ...dvancedManyToManyObjectRelationAdapter.php | 2 +- .../AdvancedManyToManyRelationAdapter.php | 2 +- src/DataObject/Data/Adapter/BlockAdapter.php | 4 +- .../Data/Adapter/BooleanAdapter.php | 2 +- .../Data/Adapter/CalculatedValueAdapter.php | 2 +- .../Data/Adapter/CheckboxAdapter.php | 2 +- .../Adapter/ClassificationStoreAdapter.php | 2 +- .../Data/Adapter/ConsentAdapter.php | 21 ++++++++- src/DataObject/Data/Adapter/DateAdapter.php | 2 +- .../Data/Adapter/DateRangeAdapter.php | 2 +- .../Data/Adapter/EncryptedFieldAdapter.php | 2 +- .../Data/Adapter/ExternalImageAdapter.php | 2 +- .../Data/Adapter/FieldCollectionsAdapter.php | 16 ++++--- .../Data/Adapter/GeoBoundsAdapter.php | 2 +- .../Data/Adapter/GeoPointAdapter.php | 2 +- .../Data/Adapter/GeoPointsAdapter.php | 2 +- .../Data/Adapter/HotspotImageAdapter.php | 2 +- src/DataObject/Data/Adapter/ImageAdapter.php | 2 +- .../Data/Adapter/ImageGalleryAdapter.php | 2 +- .../Adapter/InputQuantityValueAdapter.php | 2 +- src/DataObject/Data/Adapter/LinkAdapter.php | 2 +- .../Data/Adapter/LocalizedFieldsAdapter.php | 2 +- .../ManyToManyObjectRelationAdapter.php | 2 +- .../Adapter/ManyToManyRelationAdapter.php | 6 +-- .../Data/Adapter/ManyToOneRelationAdapter.php | 2 +- .../Data/Adapter/MultiSelectAdapter.php | 2 +- .../Data/Adapter/NumericAdapter.php | 2 +- .../Data/Adapter/NumericRangeAdapter.php | 2 +- .../Data/Adapter/ObjectBricksAdapter.php | 2 +- .../Data/Adapter/QuantityValueAdapter.php | 2 +- .../Adapter/QuantityValueRangeAdapter.php | 2 +- .../Adapter/ReverseObjectRelationAdapter.php | 2 +- .../Data/Adapter/RgbaColorAdapter.php | 16 ++++++- src/DataObject/Data/Adapter/SelectAdapter.php | 2 +- src/DataObject/Data/Adapter/SliderAdapter.php | 2 +- src/DataObject/Data/Adapter/StringAdapter.php | 2 +- .../Data/Adapter/StructuredTableAdapter.php | 2 +- src/DataObject/Data/Adapter/TableAdapter.php | 2 +- .../Data/Adapter/UrlSlugAdapter.php | 2 +- src/DataObject/Data/Adapter/VideoAdapter.php | 2 +- src/DataObject/Data/{ => Model}/ClassData.php | 2 +- src/DataObject/Data/Model/ConsentData.php | 45 +++++++++++++++++++ .../Data/{ => Model}/FieldContextData.php | 2 +- .../Data/{ => Model}/RelationData.php | 2 +- src/DataObject/Data/SetterDataInterface.php | 1 + src/DataObject/Service/DataService.php | 2 +- .../Service/DataServiceInterface.php | 2 +- 47 files changed, 133 insertions(+), 56 deletions(-) rename src/DataObject/Data/{ => Model}/ClassData.php (94%) create mode 100644 src/DataObject/Data/Model/ConsentData.php rename src/DataObject/Data/{ => Model}/FieldContextData.php (96%) rename src/DataObject/Data/{ => Model}/RelationData.php (94%) diff --git a/src/DataObject/Data/Adapter/AdvancedManyToManyObjectRelationAdapter.php b/src/DataObject/Data/Adapter/AdvancedManyToManyObjectRelationAdapter.php index 308e30e5..ae5ca460 100644 --- a/src/DataObject/Data/Adapter/AdvancedManyToManyObjectRelationAdapter.php +++ b/src/DataObject/Data/Adapter/AdvancedManyToManyObjectRelationAdapter.php @@ -17,7 +17,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; use Pimcore\Bundle\StaticResolverBundle\Models\DataObject\ConcreteObjectResolverInterface; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Model\DataObject\ClassDefinition\Data; diff --git a/src/DataObject/Data/Adapter/AdvancedManyToManyRelationAdapter.php b/src/DataObject/Data/Adapter/AdvancedManyToManyRelationAdapter.php index baee6397..9764a3b7 100644 --- a/src/DataObject/Data/Adapter/AdvancedManyToManyRelationAdapter.php +++ b/src/DataObject/Data/Adapter/AdvancedManyToManyRelationAdapter.php @@ -18,7 +18,7 @@ use Exception; use Pimcore\Bundle\StaticResolverBundle\Models\Element\ServiceResolverInterface; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Bundle\StudioBackendBundle\Util\Trait\ElementProviderTrait; diff --git a/src/DataObject/Data/Adapter/BlockAdapter.php b/src/DataObject/Data/Adapter/BlockAdapter.php index c6ed0939..0b3599ba 100644 --- a/src/DataObject/Data/Adapter/BlockAdapter.php +++ b/src/DataObject/Data/Adapter/BlockAdapter.php @@ -18,7 +18,7 @@ use Exception; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\DataNormalizerInterface; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterServiceInterface; @@ -85,7 +85,7 @@ public function normalize( /** @var BlockElement $fieldValue */ foreach ($block as $key => $fieldValue) { $blockDefinition = $fieldDefinitions[$key]; - $resultItems[$key] = $this->dataService->getNormalizedValue( + $resultItem[$key] = $this->dataService->getNormalizedValue( $fieldValue->getData(), $blockDefinition, ); diff --git a/src/DataObject/Data/Adapter/BooleanAdapter.php b/src/DataObject/Data/Adapter/BooleanAdapter.php index fe4577e5..6b9ab8b9 100644 --- a/src/DataObject/Data/Adapter/BooleanAdapter.php +++ b/src/DataObject/Data/Adapter/BooleanAdapter.php @@ -16,7 +16,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Model\DataObject\ClassDefinition\Data; diff --git a/src/DataObject/Data/Adapter/CalculatedValueAdapter.php b/src/DataObject/Data/Adapter/CalculatedValueAdapter.php index 116a0070..0e85d514 100644 --- a/src/DataObject/Data/Adapter/CalculatedValueAdapter.php +++ b/src/DataObject/Data/Adapter/CalculatedValueAdapter.php @@ -16,7 +16,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Model\DataObject\ClassDefinition\Data; diff --git a/src/DataObject/Data/Adapter/CheckboxAdapter.php b/src/DataObject/Data/Adapter/CheckboxAdapter.php index b8be6a3e..e2827d28 100644 --- a/src/DataObject/Data/Adapter/CheckboxAdapter.php +++ b/src/DataObject/Data/Adapter/CheckboxAdapter.php @@ -16,7 +16,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait\DefaultSetterValueTrait; diff --git a/src/DataObject/Data/Adapter/ClassificationStoreAdapter.php b/src/DataObject/Data/Adapter/ClassificationStoreAdapter.php index 6d37d966..d13ce368 100644 --- a/src/DataObject/Data/Adapter/ClassificationStoreAdapter.php +++ b/src/DataObject/Data/Adapter/ClassificationStoreAdapter.php @@ -23,7 +23,7 @@ use Pimcore\Bundle\StaticResolverBundle\Models\DataObject\ClassificationStore\GroupConfigResolverInterface; use Pimcore\Bundle\StaticResolverBundle\Models\DataObject\ClassificationStore\ServiceResolverInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\DataNormalizerInterface; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterServiceInterface; diff --git a/src/DataObject/Data/Adapter/ConsentAdapter.php b/src/DataObject/Data/Adapter/ConsentAdapter.php index 75b160aa..6d546b98 100644 --- a/src/DataObject/Data/Adapter/ConsentAdapter.php +++ b/src/DataObject/Data/Adapter/ConsentAdapter.php @@ -17,7 +17,9 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; use Exception; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\DataNormalizerInterface; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\ConsentData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\DataObject\Consent\Service; @@ -30,7 +32,7 @@ * @internal */ #[AutoconfigureTag(DataAdapterLoaderInterface::ADAPTER_TAG)] -final readonly class ConsentAdapter implements SetterDataInterface +final readonly class ConsentAdapter implements SetterDataInterface, DataNormalizerInterface { public function __construct( private Service $service @@ -76,4 +78,19 @@ public function getDataForSetter( return new Consent($value, $noteId); } + + public function normalize( + mixed $value, + Data $fieldDefinition + ): ?ConsentData { + if (!$value instanceof Consent) { + return null; + } + + return new ConsentData( + $value->getConsent(), + $value->getNoteId(), + $value->getSummaryString(), + ); + } } diff --git a/src/DataObject/Data/Adapter/DateAdapter.php b/src/DataObject/Data/Adapter/DateAdapter.php index c251c8ad..57cf688e 100644 --- a/src/DataObject/Data/Adapter/DateAdapter.php +++ b/src/DataObject/Data/Adapter/DateAdapter.php @@ -17,7 +17,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; use Carbon\Carbon; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Model\DataObject\ClassDefinition\Data; diff --git a/src/DataObject/Data/Adapter/DateRangeAdapter.php b/src/DataObject/Data/Adapter/DateRangeAdapter.php index 08bd982b..8cdfbabe 100644 --- a/src/DataObject/Data/Adapter/DateRangeAdapter.php +++ b/src/DataObject/Data/Adapter/DateRangeAdapter.php @@ -18,7 +18,7 @@ use Carbon\Carbon; use Carbon\CarbonPeriod; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Model\DataObject\ClassDefinition\Data; diff --git a/src/DataObject/Data/Adapter/EncryptedFieldAdapter.php b/src/DataObject/Data/Adapter/EncryptedFieldAdapter.php index 445772f6..c150709c 100644 --- a/src/DataObject/Data/Adapter/EncryptedFieldAdapter.php +++ b/src/DataObject/Data/Adapter/EncryptedFieldAdapter.php @@ -16,7 +16,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterServiceInterface; diff --git a/src/DataObject/Data/Adapter/ExternalImageAdapter.php b/src/DataObject/Data/Adapter/ExternalImageAdapter.php index bfc7bc92..7d801bd4 100644 --- a/src/DataObject/Data/Adapter/ExternalImageAdapter.php +++ b/src/DataObject/Data/Adapter/ExternalImageAdapter.php @@ -16,7 +16,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Model\DataObject\ClassDefinition\Data; diff --git a/src/DataObject/Data/Adapter/FieldCollectionsAdapter.php b/src/DataObject/Data/Adapter/FieldCollectionsAdapter.php index 155b203c..434e0276 100644 --- a/src/DataObject/Data/Adapter/FieldCollectionsAdapter.php +++ b/src/DataObject/Data/Adapter/FieldCollectionsAdapter.php @@ -19,7 +19,7 @@ use Exception; use Pimcore\Bundle\StaticResolverBundle\Models\DataObject\FieldCollection\DefinitionResolverInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\DataNormalizerInterface; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterServiceInterface; @@ -41,6 +41,10 @@ { use ValidateFieldTypeTrait; + private const TYPE_KEY = 'type'; + + private const DATA_KEY = 'data'; + public function __construct( private DataAdapterServiceInterface $dataAdapterService, private DataServiceInterface $dataService, @@ -72,7 +76,7 @@ public function getDataForSetter( $collection = $this->createCollection( $element, $fieldDefinition, - $collectionRaw['type'], + $collectionRaw[self::TYPE_KEY], $collectionData, $count ); @@ -100,15 +104,13 @@ public function normalize( if (!$fieldCollectionDefinition) { continue; } - $resultItem = ['type' => $type]; + $resultItem = [self::TYPE_KEY => $type, self::DATA_KEY => []]; foreach ($fieldCollectionDefinition->getFieldDefinitions() as $collectionFieldDefinition) { $getter = 'get' . ucfirst($collectionFieldDefinition->getName()); $value = $item->$getter(); - $resultItem[$collectionFieldDefinition->getName()] = $this->dataService->getNormalizedValue( - $value, - $collectionFieldDefinition, - ); + $resultItem[self::DATA_KEY][$collectionFieldDefinition->getName()] = + $this->dataService->getNormalizedValue($value, $collectionFieldDefinition); } $resultItems[] = $resultItem; diff --git a/src/DataObject/Data/Adapter/GeoBoundsAdapter.php b/src/DataObject/Data/Adapter/GeoBoundsAdapter.php index d9c37566..cb11289d 100644 --- a/src/DataObject/Data/Adapter/GeoBoundsAdapter.php +++ b/src/DataObject/Data/Adapter/GeoBoundsAdapter.php @@ -16,7 +16,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Model\DataObject\ClassDefinition\Data; diff --git a/src/DataObject/Data/Adapter/GeoPointAdapter.php b/src/DataObject/Data/Adapter/GeoPointAdapter.php index 3ac69281..ec493522 100644 --- a/src/DataObject/Data/Adapter/GeoPointAdapter.php +++ b/src/DataObject/Data/Adapter/GeoPointAdapter.php @@ -16,7 +16,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Model\DataObject\ClassDefinition\Data; diff --git a/src/DataObject/Data/Adapter/GeoPointsAdapter.php b/src/DataObject/Data/Adapter/GeoPointsAdapter.php index 829cde79..82fc7b6e 100644 --- a/src/DataObject/Data/Adapter/GeoPointsAdapter.php +++ b/src/DataObject/Data/Adapter/GeoPointsAdapter.php @@ -16,7 +16,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Model\DataObject\ClassDefinition\Data; diff --git a/src/DataObject/Data/Adapter/HotspotImageAdapter.php b/src/DataObject/Data/Adapter/HotspotImageAdapter.php index c2c23a1b..0b9c9a25 100644 --- a/src/DataObject/Data/Adapter/HotspotImageAdapter.php +++ b/src/DataObject/Data/Adapter/HotspotImageAdapter.php @@ -17,7 +17,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; use Pimcore\Bundle\StaticResolverBundle\Models\Element\ServiceResolverInterface; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; diff --git a/src/DataObject/Data/Adapter/ImageAdapter.php b/src/DataObject/Data/Adapter/ImageAdapter.php index 10076b0d..1e4aee60 100644 --- a/src/DataObject/Data/Adapter/ImageAdapter.php +++ b/src/DataObject/Data/Adapter/ImageAdapter.php @@ -17,7 +17,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; use Pimcore\Bundle\StaticResolverBundle\Models\Asset\AssetResolverInterface; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Bundle\StudioBackendBundle\Util\Trait\ElementProviderTrait; diff --git a/src/DataObject/Data/Adapter/ImageGalleryAdapter.php b/src/DataObject/Data/Adapter/ImageGalleryAdapter.php index 56d49e21..afbe06d8 100644 --- a/src/DataObject/Data/Adapter/ImageGalleryAdapter.php +++ b/src/DataObject/Data/Adapter/ImageGalleryAdapter.php @@ -16,7 +16,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Bundle\StudioBackendBundle\Util\Trait\ElementProviderTrait; diff --git a/src/DataObject/Data/Adapter/InputQuantityValueAdapter.php b/src/DataObject/Data/Adapter/InputQuantityValueAdapter.php index 8052080d..08a019a1 100644 --- a/src/DataObject/Data/Adapter/InputQuantityValueAdapter.php +++ b/src/DataObject/Data/Adapter/InputQuantityValueAdapter.php @@ -16,7 +16,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait\DefaultSetterValueTrait; diff --git a/src/DataObject/Data/Adapter/LinkAdapter.php b/src/DataObject/Data/Adapter/LinkAdapter.php index 08dc7180..84377dcf 100644 --- a/src/DataObject/Data/Adapter/LinkAdapter.php +++ b/src/DataObject/Data/Adapter/LinkAdapter.php @@ -17,7 +17,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; use Exception; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Model\DataObject\ClassDefinition\Data; diff --git a/src/DataObject/Data/Adapter/LocalizedFieldsAdapter.php b/src/DataObject/Data/Adapter/LocalizedFieldsAdapter.php index af5c9673..fa2ce28c 100644 --- a/src/DataObject/Data/Adapter/LocalizedFieldsAdapter.php +++ b/src/DataObject/Data/Adapter/LocalizedFieldsAdapter.php @@ -18,7 +18,7 @@ use Exception; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\DataNormalizerInterface; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterServiceInterface; diff --git a/src/DataObject/Data/Adapter/ManyToManyObjectRelationAdapter.php b/src/DataObject/Data/Adapter/ManyToManyObjectRelationAdapter.php index ba88a9b4..d65622a1 100644 --- a/src/DataObject/Data/Adapter/ManyToManyObjectRelationAdapter.php +++ b/src/DataObject/Data/Adapter/ManyToManyObjectRelationAdapter.php @@ -17,7 +17,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; use Pimcore\Bundle\StaticResolverBundle\Models\DataObject\ConcreteObjectResolverInterface; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Model\DataObject\ClassDefinition\Data; diff --git a/src/DataObject/Data/Adapter/ManyToManyRelationAdapter.php b/src/DataObject/Data/Adapter/ManyToManyRelationAdapter.php index 35ab54fe..8c679f8f 100644 --- a/src/DataObject/Data/Adapter/ManyToManyRelationAdapter.php +++ b/src/DataObject/Data/Adapter/ManyToManyRelationAdapter.php @@ -18,8 +18,8 @@ use Pimcore\Bundle\StaticResolverBundle\Models\Element\ServiceResolverInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\DataNormalizerInterface; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\RelationData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\RelationData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; @@ -78,7 +78,7 @@ public function normalize( $relation->getId(), $elementType, $this->getSubType($relation), - $relation->getFullPath(), + $relation->getRealFullPath(), $this->getPublished($relation) ); } diff --git a/src/DataObject/Data/Adapter/ManyToOneRelationAdapter.php b/src/DataObject/Data/Adapter/ManyToOneRelationAdapter.php index 0ce6cd90..5a93423b 100644 --- a/src/DataObject/Data/Adapter/ManyToOneRelationAdapter.php +++ b/src/DataObject/Data/Adapter/ManyToOneRelationAdapter.php @@ -17,7 +17,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; use Pimcore\Bundle\StaticResolverBundle\Models\Element\ServiceResolverInterface; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; diff --git a/src/DataObject/Data/Adapter/MultiSelectAdapter.php b/src/DataObject/Data/Adapter/MultiSelectAdapter.php index ae40c453..b17cd25e 100644 --- a/src/DataObject/Data/Adapter/MultiSelectAdapter.php +++ b/src/DataObject/Data/Adapter/MultiSelectAdapter.php @@ -16,7 +16,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Model\DataObject\ClassDefinition\Data; diff --git a/src/DataObject/Data/Adapter/NumericAdapter.php b/src/DataObject/Data/Adapter/NumericAdapter.php index a09632d2..c39c1e26 100644 --- a/src/DataObject/Data/Adapter/NumericAdapter.php +++ b/src/DataObject/Data/Adapter/NumericAdapter.php @@ -16,7 +16,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait\DefaultSetterValueTrait; diff --git a/src/DataObject/Data/Adapter/NumericRangeAdapter.php b/src/DataObject/Data/Adapter/NumericRangeAdapter.php index ad6469ea..d8fc8844 100644 --- a/src/DataObject/Data/Adapter/NumericRangeAdapter.php +++ b/src/DataObject/Data/Adapter/NumericRangeAdapter.php @@ -16,7 +16,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Model\DataObject\ClassDefinition\Data; diff --git a/src/DataObject/Data/Adapter/ObjectBricksAdapter.php b/src/DataObject/Data/Adapter/ObjectBricksAdapter.php index c472000f..64a04ae7 100644 --- a/src/DataObject/Data/Adapter/ObjectBricksAdapter.php +++ b/src/DataObject/Data/Adapter/ObjectBricksAdapter.php @@ -19,7 +19,7 @@ use Exception; use Pimcore\Bundle\StaticResolverBundle\Models\DataObject\Objectbrick\DefinitionResolverInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\DataNormalizerInterface; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterServiceInterface; diff --git a/src/DataObject/Data/Adapter/QuantityValueAdapter.php b/src/DataObject/Data/Adapter/QuantityValueAdapter.php index 4c510f07..0642013d 100644 --- a/src/DataObject/Data/Adapter/QuantityValueAdapter.php +++ b/src/DataObject/Data/Adapter/QuantityValueAdapter.php @@ -16,7 +16,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait\DefaultSetterValueTrait; diff --git a/src/DataObject/Data/Adapter/QuantityValueRangeAdapter.php b/src/DataObject/Data/Adapter/QuantityValueRangeAdapter.php index da130f3a..502ceb15 100644 --- a/src/DataObject/Data/Adapter/QuantityValueRangeAdapter.php +++ b/src/DataObject/Data/Adapter/QuantityValueRangeAdapter.php @@ -16,7 +16,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait\DefaultSetterValueTrait; diff --git a/src/DataObject/Data/Adapter/ReverseObjectRelationAdapter.php b/src/DataObject/Data/Adapter/ReverseObjectRelationAdapter.php index a0cd40e1..53d9c60d 100644 --- a/src/DataObject/Data/Adapter/ReverseObjectRelationAdapter.php +++ b/src/DataObject/Data/Adapter/ReverseObjectRelationAdapter.php @@ -19,7 +19,7 @@ use Exception; use Pimcore\Bundle\StaticResolverBundle\Models\DataObject\ClassDefinitionResolverInterface; use Pimcore\Bundle\StaticResolverBundle\Models\DataObject\ConcreteObjectResolverInterface; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Bundle\StudioBackendBundle\Security\Service\SecurityServiceInterface; diff --git a/src/DataObject/Data/Adapter/RgbaColorAdapter.php b/src/DataObject/Data/Adapter/RgbaColorAdapter.php index 11e7b6d3..294e15fe 100644 --- a/src/DataObject/Data/Adapter/RgbaColorAdapter.php +++ b/src/DataObject/Data/Adapter/RgbaColorAdapter.php @@ -16,7 +16,8 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\DataNormalizerInterface; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Model\DataObject\ClassDefinition\Data; @@ -28,7 +29,7 @@ * @internal */ #[AutoconfigureTag(DataAdapterLoaderInterface::ADAPTER_TAG)] -final readonly class RgbaColorAdapter implements SetterDataInterface +final readonly class RgbaColorAdapter implements SetterDataInterface, DataNormalizerInterface { public function getDataForSetter( Concrete $element, @@ -43,4 +44,15 @@ public function getDataForSetter( return new RgbaColor($r, $g, $b, $a); } + + public function normalize( + mixed $value, + Data $fieldDefinition + ): ?string { + if (!$value instanceof RgbaColor) { + return null; + } + + return $value->getHex(true); + } } diff --git a/src/DataObject/Data/Adapter/SelectAdapter.php b/src/DataObject/Data/Adapter/SelectAdapter.php index 06f7569b..1c31c2fc 100644 --- a/src/DataObject/Data/Adapter/SelectAdapter.php +++ b/src/DataObject/Data/Adapter/SelectAdapter.php @@ -16,7 +16,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait\DefaultSetterValueTrait; diff --git a/src/DataObject/Data/Adapter/SliderAdapter.php b/src/DataObject/Data/Adapter/SliderAdapter.php index eaa7ddd8..d742ae9b 100644 --- a/src/DataObject/Data/Adapter/SliderAdapter.php +++ b/src/DataObject/Data/Adapter/SliderAdapter.php @@ -16,7 +16,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait\DefaultSetterValueTrait; diff --git a/src/DataObject/Data/Adapter/StringAdapter.php b/src/DataObject/Data/Adapter/StringAdapter.php index d49be583..9ec32ca6 100644 --- a/src/DataObject/Data/Adapter/StringAdapter.php +++ b/src/DataObject/Data/Adapter/StringAdapter.php @@ -16,7 +16,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait\DefaultSetterValueTrait; diff --git a/src/DataObject/Data/Adapter/StructuredTableAdapter.php b/src/DataObject/Data/Adapter/StructuredTableAdapter.php index 7721b4e9..d9ead2bb 100644 --- a/src/DataObject/Data/Adapter/StructuredTableAdapter.php +++ b/src/DataObject/Data/Adapter/StructuredTableAdapter.php @@ -16,7 +16,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Model\DataObject\ClassDefinition\Data; diff --git a/src/DataObject/Data/Adapter/TableAdapter.php b/src/DataObject/Data/Adapter/TableAdapter.php index 5c526378..bfabf655 100644 --- a/src/DataObject/Data/Adapter/TableAdapter.php +++ b/src/DataObject/Data/Adapter/TableAdapter.php @@ -17,7 +17,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; use Exception; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Model\DataObject\ClassDefinition\Data; diff --git a/src/DataObject/Data/Adapter/UrlSlugAdapter.php b/src/DataObject/Data/Adapter/UrlSlugAdapter.php index 996449c1..49a87eac 100644 --- a/src/DataObject/Data/Adapter/UrlSlugAdapter.php +++ b/src/DataObject/Data/Adapter/UrlSlugAdapter.php @@ -17,7 +17,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; use Exception; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Model\DataObject\ClassDefinition\Data; diff --git a/src/DataObject/Data/Adapter/VideoAdapter.php b/src/DataObject/Data/Adapter/VideoAdapter.php index 3f697ed9..fc020d11 100644 --- a/src/DataObject/Data/Adapter/VideoAdapter.php +++ b/src/DataObject/Data/Adapter/VideoAdapter.php @@ -17,7 +17,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; use Pimcore\Bundle\StaticResolverBundle\Models\Asset\AssetResolverInterface; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Bundle\StudioBackendBundle\Util\Constant\ElementTypes; diff --git a/src/DataObject/Data/ClassData.php b/src/DataObject/Data/Model/ClassData.php similarity index 94% rename from src/DataObject/Data/ClassData.php rename to src/DataObject/Data/Model/ClassData.php index 4ca473a7..376bf2c5 100644 --- a/src/DataObject/Data/ClassData.php +++ b/src/DataObject/Data/Model/ClassData.php @@ -14,7 +14,7 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data; +namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model; /** * @internal diff --git a/src/DataObject/Data/Model/ConsentData.php b/src/DataObject/Data/Model/ConsentData.php new file mode 100644 index 00000000..4aaa66b9 --- /dev/null +++ b/src/DataObject/Data/Model/ConsentData.php @@ -0,0 +1,45 @@ +consent; + } + + public function getNoteId(): ?int + { + return $this->noteId; + } + + public function getNoteContent(): string + { + return $this->noteContent; + } +} diff --git a/src/DataObject/Data/FieldContextData.php b/src/DataObject/Data/Model/FieldContextData.php similarity index 96% rename from src/DataObject/Data/FieldContextData.php rename to src/DataObject/Data/Model/FieldContextData.php index cb1b2d18..519431d0 100644 --- a/src/DataObject/Data/FieldContextData.php +++ b/src/DataObject/Data/Model/FieldContextData.php @@ -14,7 +14,7 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data; +namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model; use Pimcore\Model\DataObject\Data\BlockElement; use Pimcore\Model\DataObject\Fieldcollection; diff --git a/src/DataObject/Data/RelationData.php b/src/DataObject/Data/Model/RelationData.php similarity index 94% rename from src/DataObject/Data/RelationData.php rename to src/DataObject/Data/Model/RelationData.php index 97e3297f..58a0097e 100644 --- a/src/DataObject/Data/RelationData.php +++ b/src/DataObject/Data/Model/RelationData.php @@ -14,7 +14,7 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data; +namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model; /** * @internal diff --git a/src/DataObject/Data/SetterDataInterface.php b/src/DataObject/Data/SetterDataInterface.php index 8183a531..2def3854 100644 --- a/src/DataObject/Data/SetterDataInterface.php +++ b/src/DataObject/Data/SetterDataInterface.php @@ -16,6 +16,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Model\DataObject\ClassDefinition\Data; use Pimcore\Model\DataObject\Concrete; diff --git a/src/DataObject/Service/DataService.php b/src/DataObject/Service/DataService.php index 8e5a7e50..fee605de 100644 --- a/src/DataObject/Service/DataService.php +++ b/src/DataObject/Service/DataService.php @@ -17,8 +17,8 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Service; use Exception; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\ClassData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\DataNormalizerInterface; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\ClassData; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; use Pimcore\Model\DataObject\ClassDefinition\Data; use Pimcore\Model\DataObject\Concrete; diff --git a/src/DataObject/Service/DataServiceInterface.php b/src/DataObject/Service/DataServiceInterface.php index 8ebc53b6..61949666 100644 --- a/src/DataObject/Service/DataServiceInterface.php +++ b/src/DataObject/Service/DataServiceInterface.php @@ -16,7 +16,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Service; -use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\ClassData; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\ClassData; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; use Pimcore\Model\DataObject\ClassDefinition\Data; use Pimcore\Model\DataObject\Concrete; From b2b826f1eb6e4ebf7f67592bd6e6285b5a7b63d0 Mon Sep 17 00:00:00 2001 From: lukmzig <30526586+lukmzig@users.noreply.github.com> Date: Fri, 29 Nov 2024 09:00:52 +0100 Subject: [PATCH 3/4] [Documents] Get Available Sites endpoint (#595) * feat: add endpoint to list available sites * Apply php-cs-fixer changes * fix: sonar * apply review feedback * Apply php-cs-fixer changes * fix: renaming issue --------- Co-authored-by: lukmzig --- config/documents.yaml | 33 +++++++- .../Video/ImageThumbnailStreamController.php | 2 +- .../Attribute/Response/AvailableSitesJson.php | 43 +++++++++++ .../Controller/AvailableSitesController.php | 74 ++++++++++++++++++ src/Document/Event/PreResponse/SiteEvent.php | 39 ++++++++++ src/Document/Hydrator/SiteHydrator.php | 37 +++++++++ .../Hydrator/SiteHydratorInterface.php | 28 +++++++ .../ExcludeMainSiteParameter.php | 33 ++++++++ .../Query/ExcludeMainSiteParameter.php | 35 +++++++++ src/Document/Repository/SiteRepository.php | 34 ++++++++ .../Repository/SiteRepositoryInterface.php | 30 ++++++++ src/Document/Schema/Site.php | 77 +++++++++++++++++++ src/Document/Service/SiteService.php | 66 ++++++++++++++++ src/Document/Service/SiteServiceInterface.php | 31 ++++++++ src/OpenApi/Config/Tags.php | 5 ++ translations/studio_api_docs.en.yaml | 5 ++ 16 files changed, 569 insertions(+), 3 deletions(-) create mode 100644 src/Document/Attribute/Response/AvailableSitesJson.php create mode 100644 src/Document/Controller/AvailableSitesController.php create mode 100644 src/Document/Event/PreResponse/SiteEvent.php create mode 100644 src/Document/Hydrator/SiteHydrator.php create mode 100644 src/Document/Hydrator/SiteHydratorInterface.php create mode 100644 src/Document/MappedParameter/ExcludeMainSiteParameter.php create mode 100644 src/Document/OpenApi/Attribute/Parameter/Query/ExcludeMainSiteParameter.php create mode 100644 src/Document/Repository/SiteRepository.php create mode 100644 src/Document/Repository/SiteRepositoryInterface.php create mode 100644 src/Document/Schema/Site.php create mode 100644 src/Document/Service/SiteService.php create mode 100644 src/Document/Service/SiteServiceInterface.php diff --git a/config/documents.yaml b/config/documents.yaml index 1bce398c..f198214c 100644 --- a/config/documents.yaml +++ b/config/documents.yaml @@ -4,6 +4,35 @@ services: autoconfigure: true public: false - # Secvices + # controllers are imported separately to make sure they're public + # and have a tag that allows actions to type-hint services + Pimcore\Bundle\StudioBackendBundle\Document\Controller\: + resource: '../src/Document/Controller' + public: true + tags: [ 'controller.service_arguments' ] + + # + # Services + # + Pimcore\Bundle\StudioBackendBundle\Document\Service\DocumentServiceInterface: - class: Pimcore\Bundle\StudioBackendBundle\Document\Service\DocumentService \ No newline at end of file + class: Pimcore\Bundle\StudioBackendBundle\Document\Service\DocumentService + + Pimcore\Bundle\StudioBackendBundle\Document\Service\SiteServiceInterface: + class: Pimcore\Bundle\StudioBackendBundle\Document\Service\SiteService + + + # + # Repositories + # + + Pimcore\Bundle\StudioBackendBundle\Document\Repository\SiteRepositoryInterface: + class: Pimcore\Bundle\StudioBackendBundle\Document\Repository\SiteRepository + + + # + # Hydrators + # + + Pimcore\Bundle\StudioBackendBundle\Document\Hydrator\SiteHydratorInterface: + class: Pimcore\Bundle\StudioBackendBundle\Document\Hydrator\SiteHydrator \ No newline at end of file diff --git a/src/Asset/Controller/Video/ImageThumbnailStreamController.php b/src/Asset/Controller/Video/ImageThumbnailStreamController.php index 200af814..828c77ea 100644 --- a/src/Asset/Controller/Video/ImageThumbnailStreamController.php +++ b/src/Asset/Controller/Video/ImageThumbnailStreamController.php @@ -81,7 +81,7 @@ public function __construct( operationId: 'asset_video_image_thumbnail_stream', description: 'asset_video_image_thumbnail_stream_description', summary: 'asset_video_image_thumbnail_stream_summary', - tags: [Tags::Assets->name] + tags: [Tags::Assets->value] )] #[IdParameter(type: 'video')] #[WidthParameter('Width of the video image thumbnail', 265)] diff --git a/src/Document/Attribute/Response/AvailableSitesJson.php b/src/Document/Attribute/Response/AvailableSitesJson.php new file mode 100644 index 00000000..99a62603 --- /dev/null +++ b/src/Document/Attribute/Response/AvailableSitesJson.php @@ -0,0 +1,43 @@ +value)] + #[Get( + path: self::PREFIX . '/documents/sites/list-available', + operationId: 'documents_list_available_sites', + description: 'documents_list_available_sites_description', + summary: 'documents_list_available_sites_summary', + tags: [Tags::Documents->value] + )] + #[ExcludeMainSiteParameter] + #[SuccessResponse( + description: 'documents_list_available_sites_success_response', + content: new AvailableSitesJson() + )] + #[DefaultResponses([ + HttpResponseCodes::UNAUTHORIZED, + ])] + public function getAvailableSites( + #[MapQueryString] MappedParameter $parameter + ): JsonResponse { + return $this->jsonResponse(['items' => $this->siteService->getAvailableSites($parameter)]); + } +} diff --git a/src/Document/Event/PreResponse/SiteEvent.php b/src/Document/Event/PreResponse/SiteEvent.php new file mode 100644 index 00000000..d6300e3a --- /dev/null +++ b/src/Document/Event/PreResponse/SiteEvent.php @@ -0,0 +1,39 @@ +site; + } +} diff --git a/src/Document/Hydrator/SiteHydrator.php b/src/Document/Hydrator/SiteHydrator.php new file mode 100644 index 00000000..577d1337 --- /dev/null +++ b/src/Document/Hydrator/SiteHydrator.php @@ -0,0 +1,37 @@ +getId(), + $siteModel->getDomains(), + $siteModel->getMainDomain(), + $siteModel->getRootId(), + $siteModel->getRootPath(), + ); + } +} diff --git a/src/Document/Hydrator/SiteHydratorInterface.php b/src/Document/Hydrator/SiteHydratorInterface.php new file mode 100644 index 00000000..5c456805 --- /dev/null +++ b/src/Document/Hydrator/SiteHydratorInterface.php @@ -0,0 +1,28 @@ +excludeMainSite === 'true'; // TODO: symfony 7.1 will support bool type + } +} diff --git a/src/Document/OpenApi/Attribute/Parameter/Query/ExcludeMainSiteParameter.php b/src/Document/OpenApi/Attribute/Parameter/Query/ExcludeMainSiteParameter.php new file mode 100644 index 00000000..68a8cf55 --- /dev/null +++ b/src/Document/OpenApi/Attribute/Parameter/Query/ExcludeMainSiteParameter.php @@ -0,0 +1,35 @@ +load(); + } +} diff --git a/src/Document/Repository/SiteRepositoryInterface.php b/src/Document/Repository/SiteRepositoryInterface.php new file mode 100644 index 00000000..9a6b4ce9 --- /dev/null +++ b/src/Document/Repository/SiteRepositoryInterface.php @@ -0,0 +1,30 @@ +id; + } + + public function getRootId(): ?int + { + return $this->rootId; + } + + public function getRootPath(): ?string + { + return $this->rootPath; + } + + public function getDomains(): array + { + return $this->domains; + } + + public function getDomain(): string + { + return $this->domain; + } +} diff --git a/src/Document/Service/SiteService.php b/src/Document/Service/SiteService.php new file mode 100644 index 00000000..a1e8349f --- /dev/null +++ b/src/Document/Service/SiteService.php @@ -0,0 +1,66 @@ +getExcludeMainSite() === false) { + $sites[] = $this->getMainSite(); + } + + $siteList = $this->siteRepository->listSites(); + foreach ($siteList as $siteEntry) { + $site = $this->siteHydrator->hydrate($siteEntry); + + $this->eventDispatcher->dispatch(new SiteEvent($site), SiteEvent::EVENT_NAME); + $sites[] = $site; + } + + return $sites; + } + + private function getMainSite(): Site + { + return new Site(0, [], 'main_site', 1, '/'); + } +} diff --git a/src/Document/Service/SiteServiceInterface.php b/src/Document/Service/SiteServiceInterface.php new file mode 100644 index 00000000..f5ff2af8 --- /dev/null +++ b/src/Document/Service/SiteServiceInterface.php @@ -0,0 +1,31 @@ +value, description: 'tag_dependencies_description' )] +#[Tag( + name: Tags::Documents->value, + description: 'tag_documents_description' +)] #[Tag( name: Tags::Elements->value, description: 'tag_elements_description' @@ -127,6 +131,7 @@ enum Tags: string case DataObjects = 'Data Objects'; case DataObjectsGrid = 'Data Object Grid'; case Dependencies = 'Dependencies'; + case Documents = 'Documents'; case Elements = 'Elements'; case ExecutionEngine = 'Execution Engine'; case Emails = 'E-Mails'; diff --git a/translations/studio_api_docs.en.yaml b/translations/studio_api_docs.en.yaml index 193ba08c..b3179401 100644 --- a/translations/studio_api_docs.en.yaml +++ b/translations/studio_api_docs.en.yaml @@ -201,6 +201,10 @@ data_object_update_by_id_description: | Update needs to have the complete data present.
You can create/update/delete list entries like properties.
If you want to update only a single field, use the PATCH method. data_object_update_by_id_success_response: Successfully updated data object data_object_update_by_id_summary: Update a data object by ID +documents_list_available_sites_description: | + List all available sites +documents_list_available_sites_success_response: List of available sites +documents_list_available_sites_summary: List all available sites element_delete_created_response: Successfully created jobRun for deleting element and its children element_delete_description: | @@ -434,6 +438,7 @@ tag_delete_by_id_description: | tag_delete_by_id_success_response: ID of successfully deleted tag tag_delete_by_id_summary: Delete a specific tag tag_dependencies_description: Get dependencies for a single element +tag_documents_description: Document operations to get/update/create/delete documents tag_elements_description: Get element properties for a single element based on its type and provided parameters tag_emails_description: E-mail operations to get/update/create/delete/test emails and From 1071effdef37d6b7c7b48d89ac1e43f07f290027 Mon Sep 17 00:00:00 2001 From: Matthias Schuhmayer <38959016+mattamon@users.noreply.github.com> Date: Fri, 29 Nov 2024 16:24:49 +0100 Subject: [PATCH 4/4] Restructure metadata and add collection endpoint (#596) * Restructure metadata and add collection endpoint * Apply php-cs-fixer changes * Move Controller * Rename controller * Import correct class * Add filter and extend resolver * Apply php-cs-fixer changes * Change data to type mixed in schema --------- Co-authored-by: mattamon --- config/assets.yaml | 15 +-- config/metadata.yaml | 27 +++- .../Collector/Asset/MetadataCollector.php | 4 +- .../Attribute/Request/FilterRequestBody.php | 47 +++++++ .../Controller/Asset/GetController.php} | 14 +- .../Controller/CollectionController.php | 71 +++++++++++ .../Event/PreResponse/CustomMetadataEvent.php | 4 +- .../PreResponse/PredefinedMetadataEvent.php | 39 ++++++ .../Event/PreSet/CustomMetadataEvent.php | 2 +- .../Hydrator/MetadataHydrator.php} | 42 +++++- .../Hydrator/MetadataHydratorInterface.php | 31 +++++ .../MappedParameter/MetadataParameters.php} | 17 ++- .../Adapter/CustomMetadataAdapter.php} | 8 +- .../Repository/MetadataRepository.php | 20 +++ .../MetadataRepositoryInterface.php | 3 + .../Schema/CustomMetadata.php | 4 +- src/Metadata/Schema/PredefinedMetadata.php | 120 ++++++++++++++++++ .../Service/MetadataService.php} | 37 +++++- .../Service/MetadataServiceInterface.php} | 14 +- .../Updater/Adapter/CustomMetadataAdapter.php | 4 +- src/OpenApi/Config/Tags.php | 5 + src/Resolver/Element/ReferenceResolver.php | 15 +++ .../Element/ReferenceResolverInterface.php | 2 + translations/studio_api_docs.en.yaml | 4 + 24 files changed, 493 insertions(+), 56 deletions(-) create mode 100644 src/Metadata/Attribute/Request/FilterRequestBody.php rename src/{Asset/Controller/Data/CustomMetadataController.php => Metadata/Controller/Asset/GetController.php} (83%) create mode 100644 src/Metadata/Controller/CollectionController.php rename src/{Asset => Metadata}/Event/PreResponse/CustomMetadataEvent.php (87%) create mode 100644 src/Metadata/Event/PreResponse/PredefinedMetadataEvent.php rename src/{Asset => Metadata}/Event/PreSet/CustomMetadataEvent.php (93%) rename src/{Asset/Hydrator/CustomMetadataHydrator.php => Metadata/Hydrator/MetadataHydrator.php} (52%) create mode 100644 src/Metadata/Hydrator/MetadataHydratorInterface.php rename src/{Asset/Hydrator/CustomMetadataHydratorInterface.php => Metadata/MappedParameter/MetadataParameters.php} (63%) rename src/{Asset/Patcher/Adapter/MetadataAdapter.php => Metadata/Patcher/Adapter/CustomMetadataAdapter.php} (93%) rename src/{Asset => Metadata}/Schema/CustomMetadata.php (92%) create mode 100644 src/Metadata/Schema/PredefinedMetadata.php rename src/{Asset/Service/Data/CustomMetadataService.php => Metadata/Service/MetadataService.php} (63%) rename src/{Asset/Service/Data/CustomMetadataServiceInterface.php => Metadata/Service/MetadataServiceInterface.php} (62%) rename src/{Asset => Metadata}/Updater/Adapter/CustomMetadataAdapter.php (92%) diff --git a/config/assets.yaml b/config/assets.yaml index 5a984165..f156a954 100644 --- a/config/assets.yaml +++ b/config/assets.yaml @@ -15,9 +15,6 @@ services: Pimcore\Bundle\StudioBackendBundle\Asset\Hydrator\CustomSettingsHydratorInterface: class: Pimcore\Bundle\StudioBackendBundle\Asset\Hydrator\CustomSettingsHydrator - Pimcore\Bundle\StudioBackendBundle\Asset\Hydrator\CustomMetadataHydratorInterface: - class: Pimcore\Bundle\StudioBackendBundle\Asset\Hydrator\CustomMetadataHydrator - # Encoder Pimcore\Bundle\StudioBackendBundle\Asset\Encoder\TextEncoderInterface: class: Pimcore\Bundle\StudioBackendBundle\Asset\Encoder\TextEncoder @@ -29,8 +26,7 @@ services: Pimcore\Bundle\StudioBackendBundle\Asset\Service\Data\CustomSettingsServiceInterface: class: Pimcore\Bundle\StudioBackendBundle\Asset\Service\Data\CustomSettingsService - Pimcore\Bundle\StudioBackendBundle\Asset\Service\Data\CustomMetadataServiceInterface: - class: Pimcore\Bundle\StudioBackendBundle\Asset\Service\Data\CustomMetadataService + Pimcore\Bundle\StudioBackendBundle\Asset\Service\Data\TextServiceInterface: class: Pimcore\Bundle\StudioBackendBundle\Asset\Service\Data\TextService @@ -73,21 +69,12 @@ services: Pimcore\Bundle\StudioBackendBundle\Asset\Updater\Adapter\ImageAdapter: tags: [ 'pimcore.studio_backend.update_adapter' ] - Pimcore\Bundle\StudioBackendBundle\Asset\Updater\Adapter\CustomMetadataAdapter: - tags: [ 'pimcore.studio_backend.update_adapter' ] - Pimcore\Bundle\StudioBackendBundle\Asset\Updater\Adapter\CustomSettingsAdapter: tags: [ 'pimcore.studio_backend.update_adapter' ] Pimcore\Bundle\StudioBackendBundle\Asset\Updater\Adapter\DataAdapter: tags: [ 'pimcore.studio_backend.update_adapter' ] - # - # Patcher - # - - Pimcore\Bundle\StudioBackendBundle\Asset\Patcher\Adapter\MetadataAdapter: - tags: [ 'pimcore.studio_backend.patch_adapter' ] # # Handler diff --git a/config/metadata.yaml b/config/metadata.yaml index 45e44853..107d767c 100644 --- a/config/metadata.yaml +++ b/config/metadata.yaml @@ -4,9 +4,30 @@ services: autoconfigure: true public: false - # - # Repository - # + # controllers are imported separately to make sure they're public + # and have a tag that allows actions to type-hint services + Pimcore\Bundle\StudioBackendBundle\Metadata\Controller\: + resource: '../src/Metadata/Controller' + public: true + tags: [ 'controller.service_arguments' ] + + # Service + Pimcore\Bundle\StudioBackendBundle\Metadata\Service\MetadataServiceInterface: + class: Pimcore\Bundle\StudioBackendBundle\Metadata\Service\MetadataService + + + # Hydrator + Pimcore\Bundle\StudioBackendBundle\Metadata\Hydrator\MetadataHydratorInterface: + class: Pimcore\Bundle\StudioBackendBundle\Metadata\Hydrator\MetadataHydrator + + # Repository Pimcore\Bundle\StudioBackendBundle\Metadata\Repository\MetadataRepositoryInterface: class: Pimcore\Bundle\StudioBackendBundle\Metadata\Repository\MetadataRepository + + Pimcore\Bundle\StudioBackendBundle\Metadata\Updater\Adapter\CustomMetadataAdapter: + tags: [ 'pimcore.studio_backend.update_adapter' ] + + # Patcher + Pimcore\Bundle\StudioBackendBundle\Metadata\Patcher\Adapter\CustomMetadataAdapter: + tags: [ 'pimcore.studio_backend.patch_adapter' ] diff --git a/src/Grid/Column/Collector/Asset/MetadataCollector.php b/src/Grid/Column/Collector/Asset/MetadataCollector.php index 6514eb4a..7d8d98b1 100644 --- a/src/Grid/Column/Collector/Asset/MetadataCollector.php +++ b/src/Grid/Column/Collector/Asset/MetadataCollector.php @@ -16,12 +16,12 @@ namespace Pimcore\Bundle\StudioBackendBundle\Grid\Column\Collector\Asset; -use Pimcore\Bundle\StudioBackendBundle\Asset\Service\Data\CustomMetadataServiceInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnCollectorInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnDefinitionInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Column\FrontendType; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\ColumnConfiguration; use Pimcore\Bundle\StudioBackendBundle\Metadata\Repository\MetadataRepositoryInterface; +use Pimcore\Bundle\StudioBackendBundle\Metadata\Service\MetadataServiceInterface; use Pimcore\Bundle\StudioBackendBundle\Util\Constant\ElementTypes; use function array_key_exists; @@ -59,7 +59,7 @@ public function getColumnConfigurations(array $availableColumnDefinitions): arra */ private function getDefaultMetadata(): array { - $defaultMetadata = CustomMetadataServiceInterface::DEFAULT_METADATA; + $defaultMetadata = MetadataServiceInterface::DEFAULT_METADATA; $columns = []; foreach ($defaultMetadata as $metadata) { $columns[] = new ColumnConfiguration( diff --git a/src/Metadata/Attribute/Request/FilterRequestBody.php b/src/Metadata/Attribute/Request/FilterRequestBody.php new file mode 100644 index 00000000..689b7bac --- /dev/null +++ b/src/Metadata/Attribute/Request/FilterRequestBody.php @@ -0,0 +1,47 @@ +name] + tags: [Tags::Metadata->name] )] #[IdParameter(type: ElementTypes::TYPE_ASSET)] #[SuccessResponse( @@ -72,6 +72,6 @@ public function __construct( ])] public function getAssetCustomMetadataById(int $id): JsonResponse { - return $this->jsonResponse(['items' => $this->customMetadataService->getCustomMetadata($id)]); + return $this->jsonResponse(['items' => $this->metadataService->getCustomMetadata($id)]); } } diff --git a/src/Metadata/Controller/CollectionController.php b/src/Metadata/Controller/CollectionController.php new file mode 100644 index 00000000..6d6740c3 --- /dev/null +++ b/src/Metadata/Controller/CollectionController.php @@ -0,0 +1,71 @@ +name] + )] + #[FilterRequestBody] + #[SuccessResponse( + description: 'metadata_get_collection_success_response', + content: new ItemsJson(PredefinedMetadata::class) + )] + #[DefaultResponses([ + HttpResponseCodes::UNAUTHORIZED, + ])] + public function getMetadata( + #[MapRequestPayload] MetadataParameters $parameters = new MetadataParameters() + ): JsonResponse { + return $this->jsonResponse(['items' => $this->metadataService->getPredefinedMetadata($parameters)]); + } +} diff --git a/src/Asset/Event/PreResponse/CustomMetadataEvent.php b/src/Metadata/Event/PreResponse/CustomMetadataEvent.php similarity index 87% rename from src/Asset/Event/PreResponse/CustomMetadataEvent.php rename to src/Metadata/Event/PreResponse/CustomMetadataEvent.php index de004e18..b6f7e3f2 100644 --- a/src/Asset/Event/PreResponse/CustomMetadataEvent.php +++ b/src/Metadata/Event/PreResponse/CustomMetadataEvent.php @@ -14,10 +14,10 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioBackendBundle\Asset\Event\PreResponse; +namespace Pimcore\Bundle\StudioBackendBundle\Metadata\Event\PreResponse; -use Pimcore\Bundle\StudioBackendBundle\Asset\Schema\CustomMetadata; use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent; +use Pimcore\Bundle\StudioBackendBundle\Metadata\Schema\CustomMetadata; final class CustomMetadataEvent extends AbstractPreResponseEvent { diff --git a/src/Metadata/Event/PreResponse/PredefinedMetadataEvent.php b/src/Metadata/Event/PreResponse/PredefinedMetadataEvent.php new file mode 100644 index 00000000..a694fb30 --- /dev/null +++ b/src/Metadata/Event/PreResponse/PredefinedMetadataEvent.php @@ -0,0 +1,39 @@ +predefinedMetadata; + } +} diff --git a/src/Asset/Event/PreSet/CustomMetadataEvent.php b/src/Metadata/Event/PreSet/CustomMetadataEvent.php similarity index 93% rename from src/Asset/Event/PreSet/CustomMetadataEvent.php rename to src/Metadata/Event/PreSet/CustomMetadataEvent.php index ab111c96..6ccef73b 100644 --- a/src/Asset/Event/PreSet/CustomMetadataEvent.php +++ b/src/Metadata/Event/PreSet/CustomMetadataEvent.php @@ -14,7 +14,7 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioBackendBundle\Asset\Event\PreSet; +namespace Pimcore\Bundle\StudioBackendBundle\Metadata\Event\PreSet; use Symfony\Contracts\EventDispatcher\Event; diff --git a/src/Asset/Hydrator/CustomMetadataHydrator.php b/src/Metadata/Hydrator/MetadataHydrator.php similarity index 52% rename from src/Asset/Hydrator/CustomMetadataHydrator.php rename to src/Metadata/Hydrator/MetadataHydrator.php index f6357ace..91d257da 100644 --- a/src/Asset/Hydrator/CustomMetadataHydrator.php +++ b/src/Metadata/Hydrator/MetadataHydrator.php @@ -14,16 +14,18 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioBackendBundle\Asset\Hydrator; +namespace Pimcore\Bundle\StudioBackendBundle\Metadata\Hydrator; -use Pimcore\Bundle\StudioBackendBundle\Asset\Schema\CustomMetadata; +use Pimcore\Bundle\StudioBackendBundle\Metadata\Schema\CustomMetadata; +use Pimcore\Bundle\StudioBackendBundle\Metadata\Schema\PredefinedMetadata; use Pimcore\Bundle\StudioBackendBundle\Resolver\Element\ReferenceResolverInterface; use Pimcore\Model\Element\ElementInterface; +use Pimcore\Model\Metadata\Predefined; /** * @internal */ -final readonly class CustomMetadataHydrator implements CustomMetadataHydratorInterface +final readonly class MetadataHydrator implements MetadataHydratorInterface { public function __construct(private ReferenceResolverInterface $referenceResolver) { @@ -42,6 +44,27 @@ public function hydrate(array $customMetadata): CustomMetadata ); } + public function hydratePredefined(Predefined $predefined): PredefinedMetadata + { + return new PredefinedMetadata( + $predefined->getId(), + $predefined->getName(), + $predefined->getDescription(), + $predefined->getType(), + $predefined->getTargetSubType(), + $this->resolveDefinitionData( + $predefined->getData(), + $predefined->getType(), + ), + $predefined->getConfig(), + $predefined->getLanguage(), + $predefined->getGroup(), + $predefined->getCreationDate(), + $predefined->getModificationDate(), + $predefined->isWriteable() + ); + } + private function resolveData(mixed $data, string $type): mixed { return match (true) { @@ -54,4 +77,17 @@ private function resolveData(mixed $data, string $type): mixed default => $data, }; } + + private function resolveDefinitionData(mixed $data, string $type): mixed + { + if (!$data) { + return $data; + } + + return match ($type) { + 'asset', 'document', 'object' => $this->referenceResolver->resolveData($type, (int)$data), + 'checkbox' => (bool)$data, + default => $data + }; + } } diff --git a/src/Metadata/Hydrator/MetadataHydratorInterface.php b/src/Metadata/Hydrator/MetadataHydratorInterface.php new file mode 100644 index 00000000..5170f659 --- /dev/null +++ b/src/Metadata/Hydrator/MetadataHydratorInterface.php @@ -0,0 +1,31 @@ +filter; + } } diff --git a/src/Asset/Patcher/Adapter/MetadataAdapter.php b/src/Metadata/Patcher/Adapter/CustomMetadataAdapter.php similarity index 93% rename from src/Asset/Patcher/Adapter/MetadataAdapter.php rename to src/Metadata/Patcher/Adapter/CustomMetadataAdapter.php index 154f01db..bcc62a25 100644 --- a/src/Asset/Patcher/Adapter/MetadataAdapter.php +++ b/src/Metadata/Patcher/Adapter/CustomMetadataAdapter.php @@ -14,11 +14,11 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioBackendBundle\Asset\Patcher\Adapter; +namespace Pimcore\Bundle\StudioBackendBundle\Metadata\Patcher\Adapter; -use Pimcore\Bundle\StudioBackendBundle\Asset\Service\Data\CustomMetadataServiceInterface; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException; use Pimcore\Bundle\StudioBackendBundle\Metadata\Repository\MetadataRepositoryInterface; +use Pimcore\Bundle\StudioBackendBundle\Metadata\Service\MetadataServiceInterface; use Pimcore\Bundle\StudioBackendBundle\Patcher\Service\Loader\PatchAdapterInterface; use Pimcore\Bundle\StudioBackendBundle\Patcher\Service\Loader\TaggedIteratorAdapter; use Pimcore\Bundle\StudioBackendBundle\Util\Constant\ElementTypes; @@ -32,7 +32,7 @@ * @internal */ #[AutoconfigureTag(TaggedIteratorAdapter::ADAPTER_TAG)] -final class MetadataAdapter implements PatchAdapterInterface +final class CustomMetadataAdapter implements PatchAdapterInterface { private const INDEX_KEY = 'metadata'; @@ -111,7 +111,7 @@ private function processNewMetadataEntry(array $metadata): array throw new InvalidArgumentException('Metadata name is required'); } - if (in_array($metadata['name'], CustomMetadataServiceInterface::DEFAULT_METADATA, true)) { + if (in_array($metadata['name'], MetadataServiceInterface::DEFAULT_METADATA, true)) { return $this->addDefaultMetadata($metadata); } diff --git a/src/Metadata/Repository/MetadataRepository.php b/src/Metadata/Repository/MetadataRepository.php index e7b45e84..9999c953 100644 --- a/src/Metadata/Repository/MetadataRepository.php +++ b/src/Metadata/Repository/MetadataRepository.php @@ -17,6 +17,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\Metadata\Repository; use Pimcore\Bundle\StaticResolverBundle\Models\Metadata\Predefined\PredefinedResolverInterface; +use Pimcore\Bundle\StudioBackendBundle\Metadata\MappedParameter\MetadataParameters; use Pimcore\Model\Metadata\Predefined; use Pimcore\Model\Metadata\Predefined\Listing; @@ -37,6 +38,25 @@ public function getAllPredefinedMetadata(): array return (new Listing())->load(); } + public function getAllPredefinedMetadataDefinitions(MetadataParameters $metadataParameters): array + { + $listing = new Listing(); + $filter = $metadataParameters->getFilter(); + if ($filter !== null) { + $listing->setFilter(function (Predefined $predefined) use ($filter) { + foreach ($predefined->getObjectVars() as $value) { + if (stripos((string)$value, $filter) !== false) { + return true; + } + } + + return false; + }); + } + + return $listing->getDefinitions(); + } + public function getPredefinedMetadataByName(string $name): ?Predefined { return $this->predefinedResolver->getByName($name); diff --git a/src/Metadata/Repository/MetadataRepositoryInterface.php b/src/Metadata/Repository/MetadataRepositoryInterface.php index 9cb5b8d0..9dde5146 100644 --- a/src/Metadata/Repository/MetadataRepositoryInterface.php +++ b/src/Metadata/Repository/MetadataRepositoryInterface.php @@ -16,6 +16,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\Metadata\Repository; +use Pimcore\Bundle\StudioBackendBundle\Metadata\MappedParameter\MetadataParameters; use Pimcore\Model\Metadata\Predefined; /** @@ -28,5 +29,7 @@ interface MetadataRepositoryInterface */ public function getAllPredefinedMetadata(): array; + public function getAllPredefinedMetadataDefinitions(MetadataParameters $metadataParameters): array; + public function getPredefinedMetadataByName(string $name): ?Predefined; } diff --git a/src/Asset/Schema/CustomMetadata.php b/src/Metadata/Schema/CustomMetadata.php similarity index 92% rename from src/Asset/Schema/CustomMetadata.php rename to src/Metadata/Schema/CustomMetadata.php index 0c2c30a1..4249f11a 100644 --- a/src/Asset/Schema/CustomMetadata.php +++ b/src/Metadata/Schema/CustomMetadata.php @@ -14,7 +14,7 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioBackendBundle\Asset\Schema; +namespace Pimcore\Bundle\StudioBackendBundle\Metadata\Schema; use OpenApi\Attributes\Property; use OpenApi\Attributes\Schema; @@ -37,7 +37,7 @@ public function __construct( private readonly string $language, #[Property(description: 'Type', type: 'string', example: 'input')] private readonly string $type, - #[Property(description: 'Data', type: 'string', example: 'data')] + #[Property(description: 'Data', type: 'mixed', example: 'data')] private readonly mixed $data ) { } diff --git a/src/Metadata/Schema/PredefinedMetadata.php b/src/Metadata/Schema/PredefinedMetadata.php new file mode 100644 index 00000000..afc6a852 --- /dev/null +++ b/src/Metadata/Schema/PredefinedMetadata.php @@ -0,0 +1,120 @@ +id; + } + + public function getName(): string + { + return $this->name; + } + + public function getDescription(): ?string + { + return $this->description; + } + + public function getType(): string + { + return $this->type; + } + + public function getTargetSubType(): ?string + { + return $this->targetSubType; + } + + public function getData(): mixed + { + return $this->data; + } + + public function getConfig(): ?string + { + return $this->config; + } + + public function getLanguage(): ?string + { + return $this->language; + } + + public function getGroup(): ?string + { + return $this->group; + } + + public function getCreationDate(): int + { + return $this->creationDate; + } + + public function getModificationDate(): int + { + return $this->modificationDate; + } + + public function isWriteable(): bool + { + return $this->isWriteable; + } +} diff --git a/src/Asset/Service/Data/CustomMetadataService.php b/src/Metadata/Service/MetadataService.php similarity index 63% rename from src/Asset/Service/Data/CustomMetadataService.php rename to src/Metadata/Service/MetadataService.php index d42fd359..0f82397c 100644 --- a/src/Asset/Service/Data/CustomMetadataService.php +++ b/src/Metadata/Service/MetadataService.php @@ -14,13 +14,16 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioBackendBundle\Asset\Service\Data; +namespace Pimcore\Bundle\StudioBackendBundle\Metadata\Service; use Pimcore\Bundle\StaticResolverBundle\Models\Element\ServiceResolverInterface; -use Pimcore\Bundle\StudioBackendBundle\Asset\Event\PreResponse\CustomMetadataEvent; -use Pimcore\Bundle\StudioBackendBundle\Asset\Hydrator\CustomMetadataHydratorInterface; -use Pimcore\Bundle\StudioBackendBundle\Asset\Schema\CustomMetadata; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\AccessDeniedException; +use Pimcore\Bundle\StudioBackendBundle\Metadata\Event\PreResponse\CustomMetadataEvent; +use Pimcore\Bundle\StudioBackendBundle\Metadata\Event\PreResponse\PredefinedMetadataEvent; +use Pimcore\Bundle\StudioBackendBundle\Metadata\Hydrator\MetadataHydratorInterface; +use Pimcore\Bundle\StudioBackendBundle\Metadata\MappedParameter\MetadataParameters; +use Pimcore\Bundle\StudioBackendBundle\Metadata\Repository\MetadataRepositoryInterface; +use Pimcore\Bundle\StudioBackendBundle\Metadata\Schema\CustomMetadata; use Pimcore\Bundle\StudioBackendBundle\Security\Service\SecurityServiceInterface; use Pimcore\Bundle\StudioBackendBundle\Util\Constant\ElementPermissions; use Pimcore\Bundle\StudioBackendBundle\Util\Constant\ElementTypes; @@ -31,15 +34,16 @@ /** * @internal */ -final readonly class CustomMetadataService implements CustomMetadataServiceInterface +final readonly class MetadataService implements MetadataServiceInterface { use ElementProviderTrait; public function __construct( - private CustomMetadataHydratorInterface $hydrator, + private MetadataRepositoryInterface $metadataRepository, private SecurityServiceInterface $securityService, private ServiceResolverInterface $serviceResolver, - private EventDispatcherInterface $eventDispatcher + private EventDispatcherInterface $eventDispatcher, + private MetadataHydratorInterface $hydrator ) { } @@ -88,4 +92,23 @@ public function getCustomMetadata(int $id): array return $customMetadata; } + + public function getPredefinedMetadata(MetadataParameters $parameters): array + { + $originalPredefinedMetadata = $this->metadataRepository->getAllPredefinedMetadataDefinitions($parameters); + + $predefinedMetadata = []; + + foreach ($originalPredefinedMetadata as $predefined) { + $metadata = $this->hydrator->hydratePredefined($predefined); + + $this->eventDispatcher->dispatch( + new PredefinedMetadataEvent($metadata), + PredefinedMetadataEvent::EVENT_NAME + ); + $predefinedMetadata[] = $metadata; + } + + return $predefinedMetadata; + } } diff --git a/src/Asset/Service/Data/CustomMetadataServiceInterface.php b/src/Metadata/Service/MetadataServiceInterface.php similarity index 62% rename from src/Asset/Service/Data/CustomMetadataServiceInterface.php rename to src/Metadata/Service/MetadataServiceInterface.php index 5e9d6421..3d56a630 100644 --- a/src/Asset/Service/Data/CustomMetadataServiceInterface.php +++ b/src/Metadata/Service/MetadataServiceInterface.php @@ -14,15 +14,17 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioBackendBundle\Asset\Service\Data; +namespace Pimcore\Bundle\StudioBackendBundle\Metadata\Service; -use Pimcore\Bundle\StudioBackendBundle\Asset\Schema\CustomMetadata; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\AccessDeniedException; +use Pimcore\Bundle\StudioBackendBundle\Metadata\MappedParameter\MetadataParameters; +use Pimcore\Bundle\StudioBackendBundle\Metadata\Schema\CustomMetadata; +use Pimcore\Bundle\StudioBackendBundle\Metadata\Schema\PredefinedMetadata; /** * @internal */ -interface CustomMetadataServiceInterface +interface MetadataServiceInterface { public const DEFAULT_METADATA = ['title', 'alt', 'copyright']; @@ -30,7 +32,11 @@ interface CustomMetadataServiceInterface * @return array * * @throws AccessDeniedException - * */ public function getCustomMetadata(int $id): array; + + /** + * @return array + */ + public function getPredefinedMetadata(MetadataParameters $parameters): array; } diff --git a/src/Asset/Updater/Adapter/CustomMetadataAdapter.php b/src/Metadata/Updater/Adapter/CustomMetadataAdapter.php similarity index 92% rename from src/Asset/Updater/Adapter/CustomMetadataAdapter.php rename to src/Metadata/Updater/Adapter/CustomMetadataAdapter.php index 3fd43b1c..90ae74b2 100644 --- a/src/Asset/Updater/Adapter/CustomMetadataAdapter.php +++ b/src/Metadata/Updater/Adapter/CustomMetadataAdapter.php @@ -14,9 +14,9 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioBackendBundle\Asset\Updater\Adapter; +namespace Pimcore\Bundle\StudioBackendBundle\Metadata\Updater\Adapter; -use Pimcore\Bundle\StudioBackendBundle\Asset\Event\PreSet\CustomMetadataEvent; +use Pimcore\Bundle\StudioBackendBundle\Metadata\Event\PreSet\CustomMetadataEvent; use Pimcore\Bundle\StudioBackendBundle\Updater\Adapter\UpdateAdapterInterface; use Pimcore\Bundle\StudioBackendBundle\Util\Constant\ElementTypes; use Pimcore\Model\Asset; diff --git a/src/OpenApi/Config/Tags.php b/src/OpenApi/Config/Tags.php index 502f2bab..80c36f4a 100644 --- a/src/OpenApi/Config/Tags.php +++ b/src/OpenApi/Config/Tags.php @@ -73,6 +73,10 @@ name: Tags::Mercure->value, description: 'tag_mercure_description' )] +#[Tag( + name: Tags::Metadata->value, + description: 'tag_metadata_description' +)] #[Tag( name: Tags::Notes->value, description: 'tag_notes_description' @@ -136,6 +140,7 @@ enum Tags: string case ExecutionEngine = 'Execution Engine'; case Emails = 'E-Mails'; case Mercure = 'Mercure'; + case Metadata = 'Metadata'; case Notes = 'Notes'; case Notifications = 'Notifications'; case Properties = 'Properties'; diff --git a/src/Resolver/Element/ReferenceResolver.php b/src/Resolver/Element/ReferenceResolver.php index 5c0adac5..8077f44b 100644 --- a/src/Resolver/Element/ReferenceResolver.php +++ b/src/Resolver/Element/ReferenceResolver.php @@ -15,11 +15,15 @@ namespace Pimcore\Bundle\StudioBackendBundle\Resolver\Element; +use Pimcore\Bundle\StaticResolverBundle\Models\Element\ServiceResolverInterface; +use Pimcore\Bundle\StudioBackendBundle\Util\Trait\ElementProviderTrait; use Pimcore\Model\Element\AbstractElement; use Pimcore\Model\Element\ElementInterface; final class ReferenceResolver implements ReferenceResolverInterface { + use ElementProviderTrait; + private const ALLOWED_MODEL_PROPERTIES = [ 'key', 'filename', @@ -33,6 +37,10 @@ final class ReferenceResolver implements ReferenceResolverInterface */ private array $cache = []; + public function __construct(private ServiceResolverInterface $serviceResolver) + { + } + public function resolve(ElementInterface $element): array { if (isset($this->cache[$element->getId()])) { @@ -53,4 +61,11 @@ public function resolve(ElementInterface $element): array return $data; } + + public function resolveData(string $type, int $id): mixed + { + $element = $this->getElement($this->serviceResolver, $type, $id); + + return $this->resolve($element); + } } diff --git a/src/Resolver/Element/ReferenceResolverInterface.php b/src/Resolver/Element/ReferenceResolverInterface.php index 81301ffc..e2450538 100644 --- a/src/Resolver/Element/ReferenceResolverInterface.php +++ b/src/Resolver/Element/ReferenceResolverInterface.php @@ -20,4 +20,6 @@ interface ReferenceResolverInterface { public function resolve(ElementInterface $element): array; + + public function resolveData(string $type, int $id): mixed; } diff --git a/translations/studio_api_docs.en.yaml b/translations/studio_api_docs.en.yaml index b3179401..c763ce93 100644 --- a/translations/studio_api_docs.en.yaml +++ b/translations/studio_api_docs.en.yaml @@ -285,6 +285,9 @@ logout_summary: Logout and invalidate current session for active user. mercure_create_cookie_description: Retrieve JWT token for Mercure hub as cookie mercure_create_cookie_success_response: Retrieve JWT token for Mercure hub as cookie mercure_create_cookie_summary: Retrieve JWT token for Mercure hub as cookie +metadata_get_collection_description: Get predefined metadata collection with basic filter options +metadata_get_collection_success_response: Predefined metadata collection +metadata_get_collection_summary: Get predefined metadata collection note_delete_by_id_description: | Delete the note with the given {id} note_delete_by_id_success_response: Successfully deleted note @@ -458,6 +461,7 @@ tag_get_collection_for_element_by_type_and_id_summary: Get tags for an element tag_get_collection_success_response: All tags for a parent filtered based on type and query parameters tag_get_collection_summary: Get all tags for a parent tag_mercure_description: Retrieve JWT token for Mercure hub as cookie +tag_metadata_description: Metadata operations to get/update/create/delete metadata tag_notes_description: Note operations to list/delete notes tag_notifications_description: Notification operations to get/delete/send notifications tag_properties_description: Property operations to get/update/create/delete properties