From 57bab6068593708e436f6aa48843139ca8284425 Mon Sep 17 00:00:00 2001 From: Mikkel Ricky Date: Thu, 5 Oct 2023 16:27:01 +0200 Subject: [PATCH] DISPLAY-1030: Media provider --- config/api_platform/theme.yaml | 1 + config/services.yaml | 5 +++ .../ThemeProvider.php} | 38 ++++++++++++++----- 3 files changed, 34 insertions(+), 10 deletions(-) rename src/{DataProvider/ThemeItemDataProvider.php => State/ThemeProvider.php} (66%) diff --git a/config/api_platform/theme.yaml b/config/api_platform/theme.yaml index e1747b00..3ed153ab 100644 --- a/config/api_platform/theme.yaml +++ b/config/api_platform/theme.yaml @@ -7,6 +7,7 @@ resources: operations: ApiPlatform\Metadata\Get: + provider: App\State\ThemeProvider openapi_context: description: Retrieves a Theme resource. summary: Retrieve a Theme resource. diff --git a/config/services.yaml b/config/services.yaml index 4db1520b..2fb38087 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -175,6 +175,11 @@ services: arguments: $itemExtensions: !tagged_iterator api_platform.doctrine.orm.query_extension.item + App\State\ThemeProvider: + tags: [ { name: 'api_platform.state_provider', priority: 2 } ] + arguments: + $itemExtensions: !tagged_iterator api_platform.doctrine.orm.query_extension.item + # Enable ULID helper CLI commands. Symfony\Component\Uid\Command\InspectUlidCommand: ~ Symfony\Component\Uid\Command\InspectUuidCommand: ~ diff --git a/src/DataProvider/ThemeItemDataProvider.php b/src/State/ThemeProvider.php similarity index 66% rename from src/DataProvider/ThemeItemDataProvider.php rename to src/State/ThemeProvider.php index 20d2294a..babcb733 100644 --- a/src/DataProvider/ThemeItemDataProvider.php +++ b/src/State/ThemeProvider.php @@ -1,10 +1,12 @@ provideItem(Theme::class, $uriVariables['id'], $operation, $context); + } + + return null; } - public function getItem(string $resourceClass, $id, string $operationName = null, array $context = []): ?Theme + private function provideItem(string $resourceClass, $id, Operation $operation, array $context): ?Theme { $user = $this->security->getUser(); if (is_null($user)) { @@ -53,8 +69,10 @@ public function getItem(string $resourceClass, $id, string $operationName = null // Filter the query-builder with tenant extension. foreach ($this->itemExtensions as $extension) { - $identifiers = ['id' => $id]; - $extension->applyToItem($queryBuilder, $queryNameGenerator, $resourceClass, $identifiers, $operationName, $context); + if ($extension instanceof QueryItemExtensionInterface) { + $identifiers = ['id' => $id]; + $extension->applyToItem($queryBuilder, $queryNameGenerator, $resourceClass, $identifiers, $operation, $context); + } } // Get result. If there is a result this is returned.