From 9f7eba8616e3dfcdcd24807a28092120ad2663c4 Mon Sep 17 00:00:00 2001 From: Jacob Dreesen Date: Fri, 25 Oct 2024 14:15:38 +0200 Subject: [PATCH 1/5] task: hide version and description columns if they are empty --- src/Bricks/Model/Brick.php | 2 +- .../Admin/AreabrickOverviewController.php | 3 --- templates/bricks/overview.html.twig | 22 ++++++++++++++----- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/Bricks/Model/Brick.php b/src/Bricks/Model/Brick.php index 7504ae9..e240bd1 100644 --- a/src/Bricks/Model/Brick.php +++ b/src/Bricks/Model/Brick.php @@ -14,5 +14,5 @@ final class Brick public array $pages; /** @var list */ - public array $additionalProperties; + public array $additionalProperties = []; } diff --git a/src/Controller/Admin/AreabrickOverviewController.php b/src/Controller/Admin/AreabrickOverviewController.php index 6faa614..d3bd854 100644 --- a/src/Controller/Admin/AreabrickOverviewController.php +++ b/src/Controller/Admin/AreabrickOverviewController.php @@ -36,11 +36,8 @@ public function __invoke(): Response $bricks = array_map($this->brickConverter->convert(...), $this->areabrickManager->getBricks()); usort($bricks, fn ($a, $b) => strcmp($a->name, $b->name)); - $hasAdditionalProperties = array_any($bricks, fn ($brick) => !empty($brick->additionalProperties)); - return new Response($this->twig->render('@NeustaPimcoreAreabrickConfig/bricks/overview.html.twig', [ 'bricks' => $bricks, - 'hasAdditionalProperties' => $hasAdditionalProperties, ])); } } diff --git a/templates/bricks/overview.html.twig b/templates/bricks/overview.html.twig index 907da4f..df955bd 100644 --- a/templates/bricks/overview.html.twig +++ b/templates/bricks/overview.html.twig @@ -1,11 +1,19 @@ +{% set hasVersions = bricks|filter(b => b.version is not empty)|length > 0 %} +{% set hasDescriptions = bricks|filter(b => b.description is not empty)|length > 0 %} +{% set hasAdditionalProperties = bricks|filter(b => b.additionalProperties is not empty)|length > 0 %} +
- - + {% if hasVersions %} + + {% endif %} + {% if hasDescriptions %} + + {% endif %} {% if hasAdditionalProperties %} @@ -18,8 +26,12 @@ - - + {% if hasVersions %} + + {% endif %} + {% if hasDescriptions %} + + {% endif %}
{{ 'neusta_pimcore_areabrick_config.areabricks.overview.table.col_headers.name'|trans }} {{ 'neusta_pimcore_areabrick_config.areabricks.overview.table.col_headers.id'|trans }}{{ 'neusta_pimcore_areabrick_config.areabricks.overview.table.col_headers.version'|trans }}{{ 'neusta_pimcore_areabrick_config.areabricks.overview.table.col_headers.description'|trans }}{{ 'neusta_pimcore_areabrick_config.areabricks.overview.table.col_headers.version'|trans }}{{ 'neusta_pimcore_areabrick_config.areabricks.overview.table.col_headers.description'|trans }}{{ 'neusta_pimcore_areabrick_config.areabricks.overview.table.col_headers.template'|trans }} {{ 'neusta_pimcore_areabrick_config.areabricks.overview.table.col_headers.pages'|trans }}
{{ brick.name|trans }} {{ brick.id }}{{ brick.version }}{{ brick.description|trans }}{{ brick.version }}{{ brick.description|trans }}{{ brick.template }} {% embed "@NeustaPimcoreAreabrickConfig/bricks/pages_accordion.html.twig" with { @@ -40,7 +52,7 @@ {% if hasAdditionalProperties %}
    - {% for additionalProperty in brick.additionalProperties|default([]) %} + {% for additionalProperty in brick.additionalProperties %}
  • {{ additionalProperty.name }}: {{ additionalProperty.value }}
  • From 0b2dd9a4378983a630eb8eda408da9922780fcfe Mon Sep 17 00:00:00 2001 From: Jacob Dreesen Date: Mon, 28 Oct 2024 12:42:48 +0100 Subject: [PATCH 2/5] feat: add "any" twig filter --- config/services.yaml | 2 ++ src/Twig/NeustaExtension.php | 31 +++++++++++++++++++++++++++++ templates/bricks/overview.html.twig | 6 +++--- 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 src/Twig/NeustaExtension.php diff --git a/config/services.yaml b/config/services.yaml index d99dcfa..c69769d 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -18,3 +18,5 @@ services: tags: - { name: kernel.event_listener, event: pimcore.bundle_manager.paths.css, method: addCSSFiles } - { name: kernel.event_listener, event: pimcore.bundle_manager.paths.js, method: addJSFiles } + + Neusta\Pimcore\AreabrickConfigBundle\Twig\NeustaExtension: ~ diff --git a/src/Twig/NeustaExtension.php b/src/Twig/NeustaExtension.php new file mode 100644 index 0000000..f8d95d8 --- /dev/null +++ b/src/Twig/NeustaExtension.php @@ -0,0 +1,31 @@ + $array + */ + private static function any(iterable $array, callable $arrow): bool + { + foreach ($array as $k => $v) { + if ($arrow($v, $k)) { + return true; + } + } + + return false; + } +} diff --git a/templates/bricks/overview.html.twig b/templates/bricks/overview.html.twig index df955bd..f6ce37f 100644 --- a/templates/bricks/overview.html.twig +++ b/templates/bricks/overview.html.twig @@ -1,6 +1,6 @@ -{% set hasVersions = bricks|filter(b => b.version is not empty)|length > 0 %} -{% set hasDescriptions = bricks|filter(b => b.description is not empty)|length > 0 %} -{% set hasAdditionalProperties = bricks|filter(b => b.additionalProperties is not empty)|length > 0 %} +{% set hasVersions = bricks|any(b => b.version is not empty) %} +{% set hasDescriptions = bricks|any(b => b.description is not empty) %} +{% set hasAdditionalProperties = bricks|any(b => b.additionalProperties is not empty) %}
    From ef94ce86362cfc92d047cb3b81c3ee1fdcff093a Mon Sep 17 00:00:00 2001 From: Jacob Dreesen Date: Mon, 28 Oct 2024 12:52:28 +0100 Subject: [PATCH 3/5] task: remove `array_any()` polyfill --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index 4a1405b..6cb5668 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,6 @@ "symfony/dependency-injection": "^5.4 || ^6.4", "symfony/http-foundation": "^5.4 || ^6.4", "symfony/http-kernel": "^5.4 || ^6.4", - "symfony/polyfill-php84": "^1.31", "symfony/routing": "^5.4 || ^6.4", "symfony/translation": "^5.4 || ^6.4", "teamneusta/converter-bundle": "^1.6", From af9f9b008a37b38e6b8ac40cbd09d62b5c2b22c7 Mon Sep 17 00:00:00 2001 From: Jacob Dreesen Date: Tue, 29 Oct 2024 15:28:48 +0100 Subject: [PATCH 4/5] Update src/Twig/NeustaExtension.php --- src/Twig/NeustaExtension.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Twig/NeustaExtension.php b/src/Twig/NeustaExtension.php index f8d95d8..407f170 100644 --- a/src/Twig/NeustaExtension.php +++ b/src/Twig/NeustaExtension.php @@ -11,6 +11,7 @@ final class NeustaExtension extends AbstractExtension public function getFilters(): array { return [ + // Todo: remove in favor of the `any`-test once [#4422](https://github.com/twigphp/Twig/pull/4422) got released new TwigFilter('any', self::any(...)), ]; } From 1dfd5e93b54d72b04b16f77a548217dc2f7cbe2e Mon Sep 17 00:00:00 2001 From: Jacob Dreesen Date: Tue, 29 Oct 2024 15:29:12 +0100 Subject: [PATCH 5/5] Update src/Twig/NeustaExtension.php --- src/Twig/NeustaExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Twig/NeustaExtension.php b/src/Twig/NeustaExtension.php index 407f170..9dfb29f 100644 --- a/src/Twig/NeustaExtension.php +++ b/src/Twig/NeustaExtension.php @@ -11,7 +11,7 @@ final class NeustaExtension extends AbstractExtension public function getFilters(): array { return [ - // Todo: remove in favor of the `any`-test once [#4422](https://github.com/twigphp/Twig/pull/4422) got released + // Todo: remove in favor of the `any`-test once https://github.com/twigphp/Twig/pull/4422 got released new TwigFilter('any', self::any(...)), ]; }