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 58a10ab
Show file tree
Hide file tree
Showing 3 changed files with 33 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: ~
28 changes: 28 additions & 0 deletions src/Twig/NeustaExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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(...)),
];
}

private static function any(iterable $array, callable $arrow): bool

Check failure on line 18 in src/Twig/NeustaExtension.php

View workflow job for this annotation

GitHub Actions / Quality Checks

Method Neusta\Pimcore\AreabrickConfigBundle\Twig\NeustaExtension::any() has parameter $array with no value type specified in iterable type iterable.
{
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 58a10ab

Please sign in to comment.