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/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/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] + 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 000000000..6d6740c32 --- /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 de004e182..b6f7e3f27 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 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 52% rename from src/Asset/Hydrator/CustomMetadataHydrator.php rename to src/Metadata/Hydrator/MetadataHydrator.php index f6357ace1..91d257da4 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 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/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/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 0c2c30a11..4249f11a1 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 000000000..afc6a852c --- /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 d42fd3598..0f82397c2 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 5e9d6421e..3d56a6301 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 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'; 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