diff --git a/composer.json b/composer.json index 07360089..7df56882 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,7 @@ "ramsey/uuid": "^3.9", "symfony/framework-bundle": "^5.0", "symfony/twig-bundle": "^5.0", + "symfony/webpack-encore-bundle": "^1.8", "webmozart/assert": "^1.0" }, "require-dev": { @@ -57,6 +58,7 @@ } }, "config": { - "sort-packages": true + "sort-packages": true, + "allow-plugins": false } } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 77f1a78d..211af313 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -860,11 +860,6 @@ parameters: count: 1 path: src/lib/Service/ContentService.php - - - message: "#^Comparison operation \"\\>\" between int\\<1, max\\> and 0 is always true\\.$#" - count: 1 - path: src/lib/Service/ContentService.php - - message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Service\\\\ContentService\\:\\:fetchContent\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -885,21 +880,6 @@ parameters: count: 1 path: src/lib/Service/ContentService.php - - - message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Service\\\\ContentService\\:\\:prepareFields\\(\\) has parameter \\$fields with no value type specified in iterable type array\\.$#" - count: 1 - path: src/lib/Service/ContentService.php - - - - message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Service\\\\ContentService\\:\\:prepareFields\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: src/lib/Service/ContentService.php - - - - message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Service\\\\ContentService\\:\\:prepareFields\\(\\) should return array but returns array\\\\|null\\.$#" - count: 1 - path: src/lib/Service/ContentService.php - - message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Service\\\\ContentService\\:\\:setContent\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 diff --git a/src/bundle/Controller/RecommendationController.php b/src/bundle/Controller/RecommendationController.php index 3fca5e6a..d96be440 100644 --- a/src/bundle/Controller/RecommendationController.php +++ b/src/bundle/Controller/RecommendationController.php @@ -14,6 +14,8 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupCollectionInterface; +use Symfony\WebpackEncoreBundle\Asset\TagRenderer; use Twig\Environment; class RecommendationController @@ -26,16 +28,26 @@ class RecommendationController /** @var \EzSystems\EzRecommendationClient\Config\CredentialsResolverInterface */ private $credentialsResolver; + /** @var \Symfony\WebpackEncoreBundle\Asset\TagRenderer */ + private $encoreTagRenderer; + + /** @var \Symfony\WebpackEncoreBundle\Asset\EntrypointLookupCollectionInterface */ + private $entrypointLookupCollection; + /** @var \Twig\Environment */ private $twig; public function __construct( EventDispatcherInterface $eventDispatcher, CredentialsResolverInterface $credentialsResolver, + TagRenderer $encoreTagRenderer, + EntrypointLookupCollectionInterface $entrypointLookupCollection, Environment $twig ) { $this->eventDispatcher = $eventDispatcher; $this->credentialsResolver = $credentialsResolver; + $this->encoreTagRenderer = $encoreTagRenderer; + $this->entrypointLookupCollection = $entrypointLookupCollection; $this->twig = $twig; } @@ -60,12 +72,20 @@ public function showRecommendationsAction(Request $request): Response $response = new Response(); $response->setPrivate(); - return $response->setContent( + $this->encoreTagRenderer->reset(); + $this->entrypointLookupCollection->getEntrypointLookup('ezplatform')->reset(); + + $response->setContent( $this->twig()->render($template, [ 'recommendations' => $event->getRecommendationItems(), 'templateId' => Uuid::uuid4()->toString(), ]) ); + + $this->encoreTagRenderer->reset(); + $this->entrypointLookupCollection->getEntrypointLookup('ezplatform')->reset(); + + return $response; } protected function twig(): Environment diff --git a/src/bundle/Resources/config/services/controllers.yaml b/src/bundle/Resources/config/services/controllers.yaml index 4f94351e..598eb586 100644 --- a/src/bundle/Resources/config/services/controllers.yaml +++ b/src/bundle/Resources/config/services/controllers.yaml @@ -11,6 +11,8 @@ services: public: true arguments: $credentialsResolver: '@EzSystems\EzRecommendationClient\Config\EzRecommendationClientCredentialsResolver' + $encoreTagRenderer: '@webpack_encore.tag_renderer' + $entrypointLookupCollection: '@webpack_encore.entrypoint_lookup_collection' ez_recommendation: alias: EzSystems\EzRecommendationClientBundle\Controller\RecommendationController diff --git a/src/lib/Service/ContentService.php b/src/lib/Service/ContentService.php index 8b26437d..86aafff0 100644 --- a/src/lib/Service/ContentService.php +++ b/src/lib/Service/ContentService.php @@ -254,10 +254,14 @@ private function getAuthor(APIContent $contentValue, APIContentType $contentType /** * Checks if fields are given, if not - returns all of them. + * + * @param array $fields + * + * @return array */ - private function prepareFields(APIContentType $contentType, ?array $fields = null): array + private function prepareFields(APIContentType $contentType, array $fields): array { - if ($fields && \count($fields) > 0) { + if (empty($fields)) { return $fields; }