diff --git a/config/assets.yaml b/config/assets.yaml index 28aee31b2..b794b67c8 100644 --- a/config/assets.yaml +++ b/config/assets.yaml @@ -17,4 +17,7 @@ services: # Encoder Pimcore\Bundle\StudioBackendBundle\Asset\Encoder\TextEncoderInterface: - class: Pimcore\Bundle\StudioBackendBundle\Asset\Encoder\TextEncoder \ No newline at end of file + class: Pimcore\Bundle\StudioBackendBundle\Asset\Encoder\TextEncoder + + Pimcore\Bundle\StudioBackendBundle\Asset\Service\AssetServiceInterface: + class: Pimcore\Bundle\StudioBackendBundle\Asset\Service\AssetService \ No newline at end of file diff --git a/src/Asset/Controller/CollectionController.php b/src/Asset/Controller/CollectionController.php index adc6a7a46..2437cd6a4 100644 --- a/src/Asset/Controller/CollectionController.php +++ b/src/Asset/Controller/CollectionController.php @@ -18,6 +18,7 @@ use OpenApi\Attributes\Get; use Pimcore\Bundle\StudioBackendBundle\Asset\Attributes\Response\Property\AnyOfAsset; +use Pimcore\Bundle\StudioBackendBundle\Asset\Service\AssetServiceInterface; use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; use Pimcore\Bundle\StudioBackendBundle\DataIndex\AssetSearchServiceInterface; use Pimcore\Bundle\StudioBackendBundle\DataIndex\OpenSearchFilterInterface; @@ -53,8 +54,7 @@ final class CollectionController extends AbstractApiController public function __construct( SerializerInterface $serializer, - private readonly AssetSearchServiceInterface $assetSearchService, - private readonly FilterServiceProviderInterface $filterServiceProvider + private readonly AssetServiceInterface $assetService, ) { parent::__construct($serializer); } @@ -90,19 +90,12 @@ public function __construct( ])] public function getAssets(#[MapQueryString] ElementParameters $parameters): JsonResponse { - $filterService = $this->filterServiceProvider->create(OpenSearchFilterInterface::SERVICE_TYPE); - - $assetQuery = $filterService->applyFilters( - $parameters, - ElementTypes::TYPE_ASSET - ); - - $result = $this->assetSearchService->searchAssets($assetQuery); + $collection = $this->assetService->getAssets($parameters); return $this->getPaginatedCollection( $this->serializer, - $result->getItems(), - $result->getTotalItems() + $collection->getItems(), + $collection->getTotalItems() ); } } diff --git a/src/Asset/Event/AssetEvent.php b/src/Asset/Event/AssetEvent.php new file mode 100644 index 000000000..051e383e0 --- /dev/null +++ b/src/Asset/Event/AssetEvent.php @@ -0,0 +1,39 @@ +asset; + } +} diff --git a/src/Asset/Schema/Asset.php b/src/Asset/Schema/Asset.php index 91a95ca86..e5e11271a 100644 --- a/src/Asset/Schema/Asset.php +++ b/src/Asset/Schema/Asset.php @@ -21,6 +21,8 @@ use OpenApi\Attributes\Schema; use Pimcore\Bundle\StudioBackendBundle\Asset\Schema\Type\Permissions; use Pimcore\Bundle\StudioBackendBundle\Response\Element; +use Pimcore\Bundle\StudioBackendBundle\Util\Schema\AdditionalAttributesInterface; +use Pimcore\Bundle\StudioBackendBundle\Util\Traits\AdditionalAttributesTrait; /** * @internal @@ -29,8 +31,10 @@ title: 'Asset', type: 'object' )] -class Asset extends Element +class Asset extends Element implements AdditionalAttributesInterface { + use AdditionalAttributesTrait; + public function __construct( #[Property(description: 'IconName', type: 'string', example: 'pimcore_icon_pdf')] private readonly string $iconName, diff --git a/src/Asset/Service/AssetService.php b/src/Asset/Service/AssetService.php new file mode 100644 index 000000000..dfa973824 --- /dev/null +++ b/src/Asset/Service/AssetService.php @@ -0,0 +1,67 @@ +filterServiceProvider->create(OpenSearchFilterInterface::SERVICE_TYPE); + + $assetQuery = $filterService->applyFilters( + $parameters, + ElementTypes::TYPE_ASSET + ); + + $result = $this->assetSearchService->searchAssets($assetQuery); + + $items = $result->getItems(); + + foreach($items as $item) { + $this->eventDispatcher->dispatch( + new AssetEvent($item), + AssetEvent::EVENT_NAME + ); + + } + + return new Collection($result->getTotalItems(), $items); + } +} \ No newline at end of file diff --git a/src/Asset/Service/AssetServiceInterface.php b/src/Asset/Service/AssetServiceInterface.php new file mode 100644 index 000000000..2186afc0d --- /dev/null +++ b/src/Asset/Service/AssetServiceInterface.php @@ -0,0 +1,28 @@ +