-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(areabrick-overview): display template location for all bricks (#34)
- Loading branch information
Showing
14 changed files
with
142 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ on: | |
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
workflow_dispatch: | ||
|
||
permissions: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neusta\Pimcore\AreabrickConfigBundle\Bricks\Populator; | ||
|
||
use Neusta\ConverterBundle\Converter\Context\GenericContext; | ||
use Neusta\ConverterBundle\Populator; | ||
use Neusta\Pimcore\AreabrickConfigBundle\Bricks\Model\Brick; | ||
use Pimcore\Document\Editable\EditableHandler; | ||
use Pimcore\Extension\Document\Areabrick\AbstractAreabrick; | ||
|
||
/** | ||
* @implements Populator<AbstractAreabrick, Brick, GenericContext> | ||
*/ | ||
final class BrickTemplateLocationPopulator implements Populator | ||
{ | ||
private readonly \Closure $resolveTemplate; | ||
|
||
public function __construct(EditableHandler $editableHandler) | ||
{ | ||
$this->resolveTemplate = (new \ReflectionMethod($editableHandler, 'resolveBrickTemplate'))->getClosure($editableHandler); | ||
} | ||
|
||
public function populate(object $target, object $source, ?object $ctx = null): void | ||
{ | ||
// Todo: remove the second parameter when Pimcore 10 support is dropped | ||
$target->template = ($this->resolveTemplate)($source, 'view'); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
tests/Integration/Bricks/Populator/BrickTemplateLocationPopulatorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neusta\Pimcore\AreabrickConfigBundle\Tests\Integration\Bricks\Populator; | ||
|
||
use Neusta\Pimcore\AreabrickConfigBundle\Bricks\Model\Brick; | ||
use Neusta\Pimcore\AreabrickConfigBundle\Bricks\Populator\BrickTemplateLocationPopulator; | ||
use Pimcore\Extension\Document\Areabrick\AreabrickManagerInterface; | ||
use Pimcore\Test\KernelTestCase; | ||
|
||
final class BrickTemplateLocationPopulatorTest extends KernelTestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function itPopulatesCustomTemplates(): void | ||
{ | ||
$container = self::getContainer(); | ||
$populator = $container->get(BrickTemplateLocationPopulator::class); | ||
$source = $container->get(AreabrickManagerInterface::class)->getBrick('custom-template'); | ||
$target = new Brick(); | ||
|
||
$populator->populate($target, $source); | ||
|
||
self::assertSame('custom-template-areabrick/index.html.twig', $target->template); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function itPopulatesDefaultTemplateLocations(): void | ||
{ | ||
$container = self::getContainer(); | ||
$populator = $container->get(BrickTemplateLocationPopulator::class); | ||
$source = $container->get(AreabrickManagerInterface::class)->getBrick('global-template-location'); | ||
$target = new Brick(); | ||
|
||
$populator->populate($target, $source); | ||
|
||
self::assertSame('areas/global-template-location/view.html.twig', $target->template); | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
services: | ||
Neusta\Pimcore\AreabrickConfigBundle\Tests\app\src\Document\Areabrick\CustomTemplate: | ||
tags: | ||
- { name: pimcore.area.brick, id: custom-template } | ||
|
||
Neusta\Pimcore\AreabrickConfigBundle\Tests\app\src\Document\Areabrick\GlobalTemplateLocation: | ||
tags: | ||
- { name: pimcore.area.brick, id: global-template-location } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neusta\Pimcore\AreabrickConfigBundle\Tests\app\src\Document\Areabrick; | ||
|
||
use Pimcore\Extension\Document\Areabrick\AbstractAreabrick; | ||
|
||
final class CustomTemplate extends AbstractAreabrick | ||
{ | ||
public function getTemplate(): ?string | ||
{ | ||
return 'custom-template-areabrick/index.html.twig'; | ||
} | ||
|
||
public function getTemplateLocation(): string | ||
{ | ||
return ''; | ||
} | ||
|
||
public function getTemplateSuffix(): string | ||
{ | ||
return ''; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
tests/app/src/Document/Areabrick/GlobalTemplateLocation.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neusta\Pimcore\AreabrickConfigBundle\Tests\app\src\Document\Areabrick; | ||
|
||
use Pimcore\Extension\Document\Areabrick\AbstractAreabrick; | ||
|
||
final class GlobalTemplateLocation extends AbstractAreabrick | ||
{ | ||
public function getTemplate(): ?string | ||
{ | ||
return null; | ||
} | ||
|
||
public function getTemplateLocation(): string | ||
{ | ||
return self::TEMPLATE_LOCATION_GLOBAL; | ||
} | ||
|
||
public function getTemplateSuffix(): string | ||
{ | ||
return self::TEMPLATE_SUFFIX_TWIG; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
tests/app/templates/areas/global-template-location/view.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Global Template Location Areabrick |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Custom Template Areabrick |