Skip to content

Commit

Permalink
IBX-2597: Removing first Pesonalized block from page builder editor r…
Browse files Browse the repository at this point in the history
…emoves both previews (#113)

* IBX-2597: Removing first Pesonalized block from page builder editor removes both previews

* order of uses

* [Composer] Added symfony/webpack-encore-bundle dependency

* [PHPStan] Fixed phpstan errors

* Changed visibilty of  property in Reco controller

* Added calling reset second time

---------

Co-authored-by: Tomasz Kryszan <tomasz.kryszan@ez.no>
  • Loading branch information
GrabowskiM and ciastektk authored May 16, 2023
1 parent 6b0ef31 commit 99498fa
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 24 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -57,6 +58,7 @@
}
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": false
}
}
20 changes: 0 additions & 20 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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\\<int, mixed\\>\\|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
Expand Down
22 changes: 21 additions & 1 deletion src/bundle/Controller/RecommendationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/bundle/Resources/config/services/controllers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/lib/Service/ContentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,14 @@ private function getAuthor(APIContent $contentValue, APIContentType $contentType

/**
* Checks if fields are given, if not - returns all of them.
*
* @param array<string> $fields
*
* @return array<string>
*/
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;
}

Expand Down

0 comments on commit 99498fa

Please sign in to comment.