Skip to content

Commit

Permalink
feat: add "any" twig filter
Browse files Browse the repository at this point in the history
  • Loading branch information
jdreesen committed Oct 28, 2024
1 parent 9f7eba8 commit 0b2dd9a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
2 changes: 2 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ~
31 changes: 31 additions & 0 deletions src/Twig/NeustaExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);

namespace Neusta\Pimcore\AreabrickConfigBundle\Twig;

use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;

final class NeustaExtension extends AbstractExtension
{
public function getFilters(): array
{
return [
new TwigFilter('any', self::any(...)),
];
}

/**
* @param iterable<mixed> $array
*/
private static function any(iterable $array, callable $arrow): bool
{
foreach ($array as $k => $v) {
if ($arrow($v, $k)) {
return true;
}
}

return false;
}
}
6 changes: 3 additions & 3 deletions templates/bricks/overview.html.twig
Original file line number Diff line number Diff line change
@@ -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) %}

<div id="neusta_areabrick_config">
<table>
Expand Down

0 comments on commit 0b2dd9a

Please sign in to comment.