From fe02194e7740914b2c48a04eff9dc77319f48b91 Mon Sep 17 00:00:00 2001 From: mattamon Date: Thu, 28 Nov 2024 17:41:38 +0100 Subject: [PATCH 1/8] Restructure metadata and add collection endpoint --- config/assets.yaml | 15 +-- config/metadata.yaml | 27 ++++- .../Data/CustomMetadataController.php | 5 +- .../Controller/CollectionController.php | 72 ++++++++++++++ .../Event/PreResponse/CustomMetadataEvent.php | 4 +- .../PreResponse/PredefinedMetadataEvent.php | 39 ++++++++ .../Event/PreSet/CustomMetadataEvent.php | 2 +- .../Hydrator/MetadataHydrator.php} | 26 ++++- .../Hydrator/MetadataHydratorInterface.php | 31 ++++++ .../MappedParameter/MetadataParameters.php} | 17 +++- .../Adapter/CustomMetadataAdapter.php} | 8 +- .../Schema/CustomMetadata.php | 2 +- src/Metadata/Schema/PredefinedMetadata.php | 99 +++++++++++++++++++ .../Service/MetadataService.php} | 30 +++++- .../Service/MetadataServiceInterface.php} | 7 +- .../Updater/Adapter/CustomMetadataAdapter.php | 4 +- src/OpenApi/Config/Tags.php | 5 + 17 files changed, 350 insertions(+), 43 deletions(-) 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} (63%) 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 (96%) create mode 100644 src/Metadata/Schema/PredefinedMetadata.php rename src/{Asset/Service/Data/CustomMetadataService.php => Metadata/Service/MetadataService.php} (69%) rename src/{Asset/Service/Data/CustomMetadataServiceInterface.php => Metadata/Service/MetadataServiceInterface.php} (76%) rename src/{Asset => Metadata}/Updater/Adapter/CustomMetadataAdapter.php (92%) diff --git a/config/assets.yaml b/config/assets.yaml index 5a984165b..f156a954b 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 45e448531..107d767c5 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/Asset/Controller/Data/CustomMetadataController.php b/src/Asset/Controller/Data/CustomMetadataController.php index d9224908b..00a946b1a 100644 --- a/src/Asset/Controller/Data/CustomMetadataController.php +++ b/src/Asset/Controller/Data/CustomMetadataController.php @@ -21,6 +21,7 @@ use Pimcore\Bundle\StudioBackendBundle\Asset\Service\Data\CustomMetadataServiceInterface; use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\AccessDeniedException; +use Pimcore\Bundle\StudioBackendBundle\Metadata\Service\MetadataServiceInterface; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Content\ItemsJson; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\IdParameter; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses; @@ -44,7 +45,7 @@ final class CustomMetadataController extends AbstractApiController public function __construct( SerializerInterface $serializer, - private readonly CustomMetadataServiceInterface $customMetadataService + private readonly MetadataServiceInterface $metadataService ) { parent::__construct($serializer); } @@ -72,6 +73,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 000000000..53edca3cb --- /dev/null +++ b/src/Metadata/Controller/CollectionController.php @@ -0,0 +1,72 @@ +name] + )] + #[FilterParameter] + #[SuccessResponse( + description: 'metadata_get_collection_success_response', + content: new ItemsJson(PredefinedMetadata::class) + )] + #[DefaultResponses([ + HttpResponseCodes::UNAUTHORIZED, + ])] + public function getMetadata( + #[MapQueryString] 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 de004e182..f2c835f64 100644 --- a/src/Asset/Event/PreResponse/CustomMetadataEvent.php +++ b/src/Metadata/Event/PreResponse/CustomMetadataEvent.php @@ -14,9 +14,9 @@ * @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\Metadata\Schema\CustomMetadata; use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent; 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 000000000..a694fb309 --- /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 ab111c96e..6ccef73b3 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 63% rename from src/Asset/Hydrator/CustomMetadataHydrator.php rename to src/Metadata/Hydrator/MetadataHydrator.php index f6357ace1..b3df8020b 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,24 @@ 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->resolveData( + $predefined->getData(), + $predefined->getType(), + ), + $predefined->getConfig(), + $predefined->getLanguage(), + $predefined->getGroup() + ); + } + private function resolveData(mixed $data, string $type): mixed { return match (true) { diff --git a/src/Metadata/Hydrator/MetadataHydratorInterface.php b/src/Metadata/Hydrator/MetadataHydratorInterface.php new file mode 100644 index 000000000..5170f6598 --- /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 154f01db9..bcc62a250 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/Asset/Schema/CustomMetadata.php b/src/Metadata/Schema/CustomMetadata.php similarity index 96% rename from src/Asset/Schema/CustomMetadata.php rename to src/Metadata/Schema/CustomMetadata.php index 0c2c30a11..4ed118c84 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; diff --git a/src/Metadata/Schema/PredefinedMetadata.php b/src/Metadata/Schema/PredefinedMetadata.php new file mode 100644 index 000000000..6f11950ea --- /dev/null +++ b/src/Metadata/Schema/PredefinedMetadata.php @@ -0,0 +1,99 @@ +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; + } +} diff --git a/src/Asset/Service/Data/CustomMetadataService.php b/src/Metadata/Service/MetadataService.php similarity index 69% rename from src/Asset/Service/Data/CustomMetadataService.php rename to src/Metadata/Service/MetadataService.php index d42fd3598..feb484f5e 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\Metadata\Event\PreResponse\PredefinedMetadataEvent; +use Pimcore\Bundle\StudioBackendBundle\Metadata\Hydrator\MetadataHydratorInterface; 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\Repository\MetadataRepositoryInterface; use Pimcore\Bundle\StudioBackendBundle\Security\Service\SecurityServiceInterface; use Pimcore\Bundle\StudioBackendBundle\Util\Constant\ElementPermissions; use Pimcore\Bundle\StudioBackendBundle\Util\Constant\ElementTypes; @@ -31,12 +34,13 @@ /** * @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 MetadataHydratorInterface $hydrator, private SecurityServiceInterface $securityService, private ServiceResolverInterface $serviceResolver, private EventDispatcherInterface $eventDispatcher @@ -88,4 +92,22 @@ public function getCustomMetadata(int $id): array return $customMetadata; } + + public function getPredefinedMetadata(MetadataParameters $parameters): array + { + $originalPredefinedMetadata = $this->metadataRepository->getAllPredefinedMetadata(); + + $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 76% rename from src/Asset/Service/Data/CustomMetadataServiceInterface.php rename to src/Metadata/Service/MetadataServiceInterface.php index 5e9d6421e..132af2730 100644 --- a/src/Asset/Service/Data/CustomMetadataServiceInterface.php +++ b/src/Metadata/Service/MetadataServiceInterface.php @@ -14,15 +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\StudioBackendBundle\Asset\Schema\CustomMetadata; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\AccessDeniedException; +use Pimcore\Bundle\StudioBackendBundle\Metadata\MappedParameter\MetadataParameters; /** * @internal */ -interface CustomMetadataServiceInterface +interface MetadataServiceInterface { public const DEFAULT_METADATA = ['title', 'alt', 'copyright']; @@ -33,4 +34,6 @@ interface CustomMetadataServiceInterface * */ public function getCustomMetadata(int $id): 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 3fd43b1c9..90ae74b29 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 be9dfaea4..80f2f16d7 100644 --- a/src/OpenApi/Config/Tags.php +++ b/src/OpenApi/Config/Tags.php @@ -69,6 +69,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' @@ -131,6 +135,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'; From fd44640d1e4c8104794b9a35af7408c3120262fd Mon Sep 17 00:00:00 2001 From: mattamon Date: Thu, 28 Nov 2024 16:43:02 +0000 Subject: [PATCH 2/8] Apply php-cs-fixer changes --- .../Data/CustomMetadataController.php | 1 - .../Controller/CollectionController.php | 1 - .../Event/PreResponse/CustomMetadataEvent.php | 2 +- src/Metadata/Schema/PredefinedMetadata.php | 36 +++++++++---------- src/Metadata/Service/MetadataService.php | 6 ++-- 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/Asset/Controller/Data/CustomMetadataController.php b/src/Asset/Controller/Data/CustomMetadataController.php index 00a946b1a..0a9751fb1 100644 --- a/src/Asset/Controller/Data/CustomMetadataController.php +++ b/src/Asset/Controller/Data/CustomMetadataController.php @@ -18,7 +18,6 @@ use OpenApi\Attributes\Get; use Pimcore\Bundle\StudioBackendBundle\Asset\Schema\CustomMetadata; -use Pimcore\Bundle\StudioBackendBundle\Asset\Service\Data\CustomMetadataServiceInterface; use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\AccessDeniedException; use Pimcore\Bundle\StudioBackendBundle\Metadata\Service\MetadataServiceInterface; diff --git a/src/Metadata/Controller/CollectionController.php b/src/Metadata/Controller/CollectionController.php index 53edca3cb..1c7d4241c 100644 --- a/src/Metadata/Controller/CollectionController.php +++ b/src/Metadata/Controller/CollectionController.php @@ -16,7 +16,6 @@ namespace Pimcore\Bundle\StudioBackendBundle\Metadata\Controller; - use OpenApi\Attributes\Get; use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; use Pimcore\Bundle\StudioBackendBundle\Metadata\MappedParameter\MetadataParameters; diff --git a/src/Metadata/Event/PreResponse/CustomMetadataEvent.php b/src/Metadata/Event/PreResponse/CustomMetadataEvent.php index f2c835f64..b6f7e3f27 100644 --- a/src/Metadata/Event/PreResponse/CustomMetadataEvent.php +++ b/src/Metadata/Event/PreResponse/CustomMetadataEvent.php @@ -16,8 +16,8 @@ namespace Pimcore\Bundle\StudioBackendBundle\Metadata\Event\PreResponse; -use Pimcore\Bundle\StudioBackendBundle\Metadata\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/Schema/PredefinedMetadata.php b/src/Metadata/Schema/PredefinedMetadata.php index 6f11950ea..118234297 100644 --- a/src/Metadata/Schema/PredefinedMetadata.php +++ b/src/Metadata/Schema/PredefinedMetadata.php @@ -31,24 +31,24 @@ final class PredefinedMetadata implements AdditionalAttributesInterface use AdditionalAttributesTrait; public function __construct( - #[Property(description: 'Id', type: 'string', example: '1')] - private string $id, - #[Property(description: 'Name', type: 'string', example: 'custom_metadata')] - private string $name, - #[Property(description: 'Description', type: 'string', example: 'A predefined metadata')] - private ?string $description, - #[Property(description: 'Type', type: 'string', example: 'input')] - private string $type, - #[Property(description: 'Target sub type', type: 'string', example: 'input')] - private ?string $targetSubType, - #[Property(description: 'Data', type: 'string', example: 'data')] - private mixed $data, - #[Property(description: 'Config', type: 'string', example: 'config')] - private ?string $config, - #[Property(description: 'Language', type: 'string', example: 'en')] - private ?string $language, - #[Property(description: 'Group', type: 'string', example: 'group')] - private ?string $group, + #[Property(description: 'Id', type: 'string', example: '1')] + private string $id, + #[Property(description: 'Name', type: 'string', example: 'custom_metadata')] + private string $name, + #[Property(description: 'Description', type: 'string', example: 'A predefined metadata')] + private ?string $description, + #[Property(description: 'Type', type: 'string', example: 'input')] + private string $type, + #[Property(description: 'Target sub type', type: 'string', example: 'input')] + private ?string $targetSubType, + #[Property(description: 'Data', type: 'string', example: 'data')] + private mixed $data, + #[Property(description: 'Config', type: 'string', example: 'config')] + private ?string $config, + #[Property(description: 'Language', type: 'string', example: 'en')] + private ?string $language, + #[Property(description: 'Group', type: 'string', example: 'group')] + private ?string $group, ) { } diff --git a/src/Metadata/Service/MetadataService.php b/src/Metadata/Service/MetadataService.php index feb484f5e..96daa03ca 100644 --- a/src/Metadata/Service/MetadataService.php +++ b/src/Metadata/Service/MetadataService.php @@ -18,10 +18,10 @@ use Pimcore\Bundle\StaticResolverBundle\Models\Element\ServiceResolverInterface; use Pimcore\Bundle\StudioBackendBundle\Asset\Event\PreResponse\CustomMetadataEvent; -use Pimcore\Bundle\StudioBackendBundle\Metadata\Event\PreResponse\PredefinedMetadataEvent; -use Pimcore\Bundle\StudioBackendBundle\Metadata\Hydrator\MetadataHydratorInterface; use Pimcore\Bundle\StudioBackendBundle\Asset\Schema\CustomMetadata; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\AccessDeniedException; +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\Security\Service\SecurityServiceInterface; @@ -98,7 +98,7 @@ public function getPredefinedMetadata(MetadataParameters $parameters): array $originalPredefinedMetadata = $this->metadataRepository->getAllPredefinedMetadata(); $predefinedMetadata = []; - foreach($originalPredefinedMetadata as $predefined) { + foreach ($originalPredefinedMetadata as $predefined) { $metadata = $this->hydrator->hydratePredefined($predefined); $this->eventDispatcher->dispatch( From 638ab96eeb2f68869e3d2fe8c50cf06b23368b0d Mon Sep 17 00:00:00 2001 From: mattamon Date: Fri, 29 Nov 2024 07:31:42 +0100 Subject: [PATCH 3/8] Move Controller --- src/Grid/Column/Collector/Asset/MetadataCollector.php | 4 ++-- .../Controller/Asset}/CustomMetadataController.php | 4 ++-- src/Metadata/Service/MetadataService.php | 7 +++---- src/Metadata/Service/MetadataServiceInterface.php | 7 +++++-- 4 files changed, 12 insertions(+), 10 deletions(-) rename src/{Asset/Controller/Data => Metadata/Controller/Asset}/CustomMetadataController.php (96%) diff --git a/src/Grid/Column/Collector/Asset/MetadataCollector.php b/src/Grid/Column/Collector/Asset/MetadataCollector.php index 6514eb4af..7d8d98b18 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/Asset/Controller/Data/CustomMetadataController.php b/src/Metadata/Controller/Asset/CustomMetadataController.php similarity index 96% rename from src/Asset/Controller/Data/CustomMetadataController.php rename to src/Metadata/Controller/Asset/CustomMetadataController.php index 0a9751fb1..f4fca2eba 100644 --- a/src/Asset/Controller/Data/CustomMetadataController.php +++ b/src/Metadata/Controller/Asset/CustomMetadataController.php @@ -17,9 +17,9 @@ namespace Pimcore\Bundle\StudioBackendBundle\Asset\Controller\Data; use OpenApi\Attributes\Get; -use Pimcore\Bundle\StudioBackendBundle\Asset\Schema\CustomMetadata; use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\AccessDeniedException; +use Pimcore\Bundle\StudioBackendBundle\Metadata\Schema\CustomMetadata; use Pimcore\Bundle\StudioBackendBundle\Metadata\Service\MetadataServiceInterface; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Content\ItemsJson; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\IdParameter; @@ -59,7 +59,7 @@ public function __construct( operationId: 'asset_custom_metadata_get_by_id', description: 'asset_custom_metadata_get_by_id_description', summary: 'asset_custom_metadata_get_by_id_summary', - tags: [Tags::Assets->name] + tags: [Tags::Metadata->name] )] #[IdParameter(type: ElementTypes::TYPE_ASSET)] #[SuccessResponse( diff --git a/src/Metadata/Service/MetadataService.php b/src/Metadata/Service/MetadataService.php index 96daa03ca..421b84db5 100644 --- a/src/Metadata/Service/MetadataService.php +++ b/src/Metadata/Service/MetadataService.php @@ -17,9 +17,8 @@ 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\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; @@ -40,10 +39,10 @@ public function __construct( private MetadataRepositoryInterface $metadataRepository, - private MetadataHydratorInterface $hydrator, private SecurityServiceInterface $securityService, private ServiceResolverInterface $serviceResolver, - private EventDispatcherInterface $eventDispatcher + private EventDispatcherInterface $eventDispatcher, + private MetadataHydratorInterface $hydrator ) { } diff --git a/src/Metadata/Service/MetadataServiceInterface.php b/src/Metadata/Service/MetadataServiceInterface.php index 132af2730..3d56a6301 100644 --- a/src/Metadata/Service/MetadataServiceInterface.php +++ b/src/Metadata/Service/MetadataServiceInterface.php @@ -16,9 +16,10 @@ 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 @@ -31,9 +32,11 @@ interface MetadataServiceInterface * @return array * * @throws AccessDeniedException - * */ public function getCustomMetadata(int $id): array; + /** + * @return array + */ public function getPredefinedMetadata(MetadataParameters $parameters): array; } From 12e974415a7f106c88fd0659bb3111f3553f3e15 Mon Sep 17 00:00:00 2001 From: mattamon Date: Fri, 29 Nov 2024 07:33:10 +0100 Subject: [PATCH 4/8] Rename controller --- .../Asset/{CustomMetadataController.php => GetController.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/Metadata/Controller/Asset/{CustomMetadataController.php => GetController.php} (97%) diff --git a/src/Metadata/Controller/Asset/CustomMetadataController.php b/src/Metadata/Controller/Asset/GetController.php similarity index 97% rename from src/Metadata/Controller/Asset/CustomMetadataController.php rename to src/Metadata/Controller/Asset/GetController.php index f4fca2eba..e87d80447 100644 --- a/src/Metadata/Controller/Asset/CustomMetadataController.php +++ b/src/Metadata/Controller/Asset/GetController.php @@ -38,7 +38,7 @@ /** * @internal */ -final class CustomMetadataController extends AbstractApiController +final class GetController extends AbstractApiController { use ElementProviderTrait; From 8624da864372a7e7641d83ebd0d4a8483cf75466 Mon Sep 17 00:00:00 2001 From: mattamon Date: Fri, 29 Nov 2024 07:37:45 +0100 Subject: [PATCH 5/8] Import correct class --- src/Metadata/Service/MetadataService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Metadata/Service/MetadataService.php b/src/Metadata/Service/MetadataService.php index 421b84db5..88a9125b8 100644 --- a/src/Metadata/Service/MetadataService.php +++ b/src/Metadata/Service/MetadataService.php @@ -23,6 +23,7 @@ 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; From debc081ae21b4944125dd7de9a53e6780fe0b643 Mon Sep 17 00:00:00 2001 From: mattamon Date: Fri, 29 Nov 2024 08:45:13 +0100 Subject: [PATCH 6/8] Add filter and extend resolver --- .../Attribute/Request/FilterRequestBody.php | 47 +++++++++++++++++++ .../Controller/Asset/GetController.php | 2 +- .../Controller/CollectionController.php | 14 +++--- src/Metadata/Hydrator/MetadataHydrator.php | 21 ++++++++- .../Repository/MetadataRepository.php | 20 ++++++++ .../MetadataRepositoryInterface.php | 3 ++ src/Metadata/Schema/PredefinedMetadata.php | 21 +++++++++ src/Metadata/Service/MetadataService.php | 3 +- src/Resolver/Element/ReferenceResolver.php | 15 ++++++ .../Element/ReferenceResolverInterface.php | 2 + translations/studio_api_docs.en.yaml | 4 ++ 11 files changed, 141 insertions(+), 11 deletions(-) create mode 100644 src/Metadata/Attribute/Request/FilterRequestBody.php diff --git a/src/Metadata/Attribute/Request/FilterRequestBody.php b/src/Metadata/Attribute/Request/FilterRequestBody.php new file mode 100644 index 000000000..689b7bac0 --- /dev/null +++ b/src/Metadata/Attribute/Request/FilterRequestBody.php @@ -0,0 +1,47 @@ +name] )] - #[FilterParameter] + #[FilterRequestBody] #[SuccessResponse( description: 'metadata_get_collection_success_response', content: new ItemsJson(PredefinedMetadata::class) @@ -64,7 +64,7 @@ public function __construct( HttpResponseCodes::UNAUTHORIZED, ])] public function getMetadata( - #[MapQueryString] MetadataParameters $parameters = new MetadataParameters() + #[MapRequestPayload] MetadataParameters $parameters = new MetadataParameters() ): JsonResponse { return $this->jsonResponse(['items' => $this->metadataService->getPredefinedMetadata($parameters)]); } diff --git a/src/Metadata/Hydrator/MetadataHydrator.php b/src/Metadata/Hydrator/MetadataHydrator.php index b3df8020b..e3f1cbd04 100644 --- a/src/Metadata/Hydrator/MetadataHydrator.php +++ b/src/Metadata/Hydrator/MetadataHydrator.php @@ -52,13 +52,16 @@ public function hydratePredefined(Predefined $predefined): PredefinedMetadata $predefined->getDescription(), $predefined->getType(), $predefined->getTargetSubType(), - $this->resolveData( + $this->resolveDefinitionData( $predefined->getData(), $predefined->getType(), ), $predefined->getConfig(), $predefined->getLanguage(), - $predefined->getGroup() + $predefined->getGroup(), + $predefined->getCreationDate(), + $predefined->getModificationDate(), + $predefined->isWriteable() ); } @@ -74,4 +77,18 @@ 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/Repository/MetadataRepository.php b/src/Metadata/Repository/MetadataRepository.php index e7b45e841..9999c9537 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 9cb5b8d0d..9dde51462 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/Metadata/Schema/PredefinedMetadata.php b/src/Metadata/Schema/PredefinedMetadata.php index 118234297..29926a45c 100644 --- a/src/Metadata/Schema/PredefinedMetadata.php +++ b/src/Metadata/Schema/PredefinedMetadata.php @@ -49,6 +49,12 @@ public function __construct( private ?string $language, #[Property(description: 'Group', type: 'string', example: 'group')] private ?string $group, + #[Property(description: 'Creation Date', type: 'integer', example: 1634025600)] + private int $creationDate, + #[Property(description: 'Modfication Date', type: 'integer', example: 1634025600)] + private int $modificationDate, + #[Property(description: 'Writable', type: 'bool', example: false)] + private bool $isWriteable = false, ) { } @@ -96,4 +102,19 @@ 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/Metadata/Service/MetadataService.php b/src/Metadata/Service/MetadataService.php index 88a9125b8..0f82397c2 100644 --- a/src/Metadata/Service/MetadataService.php +++ b/src/Metadata/Service/MetadataService.php @@ -95,9 +95,10 @@ public function getCustomMetadata(int $id): array public function getPredefinedMetadata(MetadataParameters $parameters): array { - $originalPredefinedMetadata = $this->metadataRepository->getAllPredefinedMetadata(); + $originalPredefinedMetadata = $this->metadataRepository->getAllPredefinedMetadataDefinitions($parameters); $predefinedMetadata = []; + foreach ($originalPredefinedMetadata as $predefined) { $metadata = $this->hydrator->hydratePredefined($predefined); diff --git a/src/Resolver/Element/ReferenceResolver.php b/src/Resolver/Element/ReferenceResolver.php index 5c0adac56..8077f44bb 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 81301ffca..e24505380 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 193ba08ca..fadf2b339 100644 --- a/translations/studio_api_docs.en.yaml +++ b/translations/studio_api_docs.en.yaml @@ -281,6 +281,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 @@ -453,6 +456,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 From 3f50d03bd45dfa1d95569be957b15fdab357c0ac Mon Sep 17 00:00:00 2001 From: mattamon Date: Fri, 29 Nov 2024 07:45:55 +0000 Subject: [PATCH 7/8] Apply php-cs-fixer changes --- src/Metadata/Controller/CollectionController.php | 2 +- src/Metadata/Hydrator/MetadataHydrator.php | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Metadata/Controller/CollectionController.php b/src/Metadata/Controller/CollectionController.php index 0b3840996..6d6740c32 100644 --- a/src/Metadata/Controller/CollectionController.php +++ b/src/Metadata/Controller/CollectionController.php @@ -18,10 +18,10 @@ use OpenApi\Attributes\Post; use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; +use Pimcore\Bundle\StudioBackendBundle\Metadata\Attribute\Request\FilterRequestBody; use Pimcore\Bundle\StudioBackendBundle\Metadata\MappedParameter\MetadataParameters; use Pimcore\Bundle\StudioBackendBundle\Metadata\Schema\PredefinedMetadata; use Pimcore\Bundle\StudioBackendBundle\Metadata\Service\MetadataServiceInterface; -use Pimcore\Bundle\StudioBackendBundle\Metadata\Attribute\Request\FilterRequestBody; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Content\ItemsJson; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse; diff --git a/src/Metadata/Hydrator/MetadataHydrator.php b/src/Metadata/Hydrator/MetadataHydrator.php index e3f1cbd04..91d257da4 100644 --- a/src/Metadata/Hydrator/MetadataHydrator.php +++ b/src/Metadata/Hydrator/MetadataHydrator.php @@ -80,7 +80,7 @@ private function resolveData(mixed $data, string $type): mixed private function resolveDefinitionData(mixed $data, string $type): mixed { - if(!$data) { + if (!$data) { return $data; } @@ -90,5 +90,4 @@ private function resolveDefinitionData(mixed $data, string $type): mixed default => $data }; } - } From 66f2fc81ba78f058c165407a1607123b0df7b7cd Mon Sep 17 00:00:00 2001 From: mattamon Date: Fri, 29 Nov 2024 08:56:19 +0100 Subject: [PATCH 8/8] Change data to type mixed in schema --- src/Metadata/Schema/CustomMetadata.php | 2 +- src/Metadata/Schema/PredefinedMetadata.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Metadata/Schema/CustomMetadata.php b/src/Metadata/Schema/CustomMetadata.php index 4ed118c84..4249f11a1 100644 --- a/src/Metadata/Schema/CustomMetadata.php +++ b/src/Metadata/Schema/CustomMetadata.php @@ -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 index 29926a45c..afc6a852c 100644 --- a/src/Metadata/Schema/PredefinedMetadata.php +++ b/src/Metadata/Schema/PredefinedMetadata.php @@ -23,7 +23,7 @@ #[Schema( title: 'PredefinedMetadata', - required: ['name', 'type'], + required: ['id', 'name', 'type', 'creationDate', 'modificationDate', 'isWriteable'], type: 'object' )] final class PredefinedMetadata implements AdditionalAttributesInterface @@ -41,7 +41,7 @@ public function __construct( private string $type, #[Property(description: 'Target sub type', type: 'string', example: 'input')] private ?string $targetSubType, - #[Property(description: 'Data', type: 'string', example: 'data')] + #[Property(description: 'Data', type: 'mixed', example: 'data')] private mixed $data, #[Property(description: 'Config', type: 'string', example: 'config')] private ?string $config,