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';