Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(areabrick-overview): display template location for all bricks #34

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/qa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:

permissions:
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:

permissions:
Expand All @@ -23,8 +22,10 @@ jobs:
dependencies: "lowest"
- php-version: "8.1"
dependencies: "highest"
tests: --fail-on-risky
jdreesen marked this conversation as resolved.
Show resolved Hide resolved
- php-version: "8.2"
dependencies: "highest"
tests: --fail-on-risky
jdreesen marked this conversation as resolved.
Show resolved Hide resolved

steps:
- name: Git Checkout
Expand All @@ -40,5 +41,9 @@ jobs:
with:
dependency-versions: ${{ matrix.dependencies }}

- name: Add Pimcore Admin UI
run: composer require --dev pimcore/admin-ui-classic-bundle --no-interaction
if: matrix.dependencies == 'highest'

- name: Execute tests
run: composer tests
run: composer tests -- ${{ matrix.tests }}
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.62",
"jangregor/phpstan-prophecy": "^1.0.2",
"laminas/laminas-zendframework-bridge": "^1.8",
"phpspec/prophecy-phpunit": "^2.2",
"phpstan/phpstan": "^1.11.10",
"phpstan/phpstan-phpunit": "^1.4",
Expand All @@ -52,6 +53,9 @@
}
},
"autoload-dev": {
"classmap": [
"tests/app/TestKernel.php"
],
"psr-4": {
"Neusta\\Pimcore\\AreabrickConfigBundle\\Tests\\": "tests/"
}
Expand Down
2 changes: 1 addition & 1 deletion config/pimcore/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ neusta_converter:
neusta_pimcore_areabrick_config.brick.converter:
target: Neusta\Pimcore\AreabrickConfigBundle\Bricks\Model\Brick
populators:
- Neusta\Pimcore\AreabrickConfigBundle\Bricks\Populator\BrickTemplateLocationPopulator
- Neusta\Pimcore\AreabrickConfigBundle\Bricks\Populator\BrickPagePopulator
properties:
id: ~
name: ~
version: ~
description: ~
template: ~

neusta_pimcore_areabrick_config.page.converter:
target: Neusta\Pimcore\AreabrickConfigBundle\Bricks\Model\Page
Expand Down
2 changes: 1 addition & 1 deletion config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
$brickConverter: '@neusta_pimcore_areabrick_config.brick.converter'
tags: [ 'controller.service_arguments' ]

Neusta\Pimcore\AreabrickConfigBundle\Bricks\Populator\BrickPageEditModeUrlPopulator: ~
Neusta\Pimcore\AreabrickConfigBundle\Bricks\Populator\BrickTemplateLocationPopulator: ~

Neusta\Pimcore\AreabrickConfigBundle\Bricks\Populator\BrickPagePopulator:
arguments:
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
bootstrap="tests/bootstrap.php"
cacheResultFile=".phpunit.cache/test-results"
colors="true"
failOnRisky="true"
failOnWarning="true"
>
<php>
Expand Down
29 changes: 29 additions & 0 deletions src/Bricks/Populator/BrickTemplateLocationPopulator.php
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');
}
}
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 removed tests/app/config/.gitkeep
Empty file.
8 changes: 8 additions & 0 deletions tests/app/config/services.yaml
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 }
24 changes: 24 additions & 0 deletions tests/app/src/Document/Areabrick/CustomTemplate.php
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 tests/app/src/Document/Areabrick/GlobalTemplateLocation.php
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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Global Template Location Areabrick
1 change: 1 addition & 0 deletions tests/app/templates/custom-template-areabrick/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Custom Template Areabrick
Loading