Skip to content

Commit

Permalink
Merge pull request #15 from netgen-layouts/fix-mapping-layout-to-spec…
Browse files Browse the repository at this point in the history
…ific-resource

Fix mapping layout to a specific resource
  • Loading branch information
emodric authored Jul 16, 2024
2 parents 7a622f2 + 4bccda3 commit 5609707
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 6 deletions.
3 changes: 3 additions & 0 deletions bundle/EventListener/Shop/ProductIndexListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

/**
* @deprecated since 1.4.6 together with nglayouts_sylius_taxon attribute, use nglayouts_sylius_resource (set by ResourceShowListener) instead
*/
final class ProductIndexListener implements EventSubscriberInterface
{
/**
Expand Down
3 changes: 3 additions & 0 deletions bundle/EventListener/Shop/ProductShowListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

/**
* @deprecated since 1.4.6 together with nglayouts_sylius_product attribute, use nglayouts_sylius_resource (set by ResourceShowListener) instead
*/
final class ProductShowListener implements EventSubscriberInterface
{
public function __construct(private RequestStack $requestStack, private Context $context) {}
Expand Down
2 changes: 1 addition & 1 deletion lib/Layout/Resolver/TargetType/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function getConstraints(): array

public function provideValue(Request $request): ?int
{
$product = $request->attributes->get('nglayouts_sylius_product');
$product = $request->attributes->get('nglayouts_sylius_resource');

return $product instanceof ProductInterface ? $product->getId() : null;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Layout/Resolver/TargetType/Taxon.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function getConstraints(): array
*/
public function provideValue(Request $request): ?array
{
$taxon = $request->attributes->get('nglayouts_sylius_taxon');
$taxon = $request->attributes->get('nglayouts_sylius_resource');
if (!$taxon instanceof TaxonInterface) {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Layout/Resolver/TargetType/TaxonProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function getConstraints(): array
*/
public function provideValue(Request $request): ?array
{
$product = $request->attributes->get('nglayouts_sylius_product');
$product = $request->attributes->get('nglayouts_sylius_resource');
if (!$product instanceof ProductInterface) {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Layout/Resolver/TargetType/ProductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function testValidationInvalid(): void
public function testProvideValue(): void
{
$request = Request::create('/');
$request->attributes->set('nglayouts_sylius_product', new ProductStub(42));
$request->attributes->set('nglayouts_sylius_resource', new ProductStub(42));

self::assertSame(42, $this->targetType->provideValue($request));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Layout/Resolver/TargetType/TaxonProductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function testProvideValue(): void
}

$request = Request::create('/');
$request->attributes->set('nglayouts_sylius_product', $product);
$request->attributes->set('nglayouts_sylius_resource', $product);

self::assertSame([12, 13], $this->targetType->provideValue($request));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Layout/Resolver/TargetType/TaxonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function testProvideValue(): void
$taxon->setParent(new TaxonStub(24));

$request = Request::create('/');
$request->attributes->set('nglayouts_sylius_taxon', $taxon);
$request->attributes->set('nglayouts_sylius_resource', $taxon);

self::assertSame([42, 24], $this->targetType->provideValue($request));
}
Expand Down

0 comments on commit 5609707

Please sign in to comment.