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): hide empty version / description columns #33

Merged
merged 5 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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 composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
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: ~
2 changes: 1 addition & 1 deletion src/Bricks/Model/Brick.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ final class Brick
public array $pages;

/** @var list<BrickProperty> */
public array $additionalProperties;
public array $additionalProperties = [];
}
3 changes: 0 additions & 3 deletions src/Controller/Admin/AreabrickOverviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]));
}
}
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(...)),
jdreesen marked this conversation as resolved.
Show resolved Hide resolved
];
}

/**
* @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;
}
}
22 changes: 17 additions & 5 deletions templates/bricks/overview.html.twig
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
{% 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>
<thead>
<tr>
<th>{{ 'neusta_pimcore_areabrick_config.areabricks.overview.table.col_headers.name'|trans }}</th>
<th>{{ 'neusta_pimcore_areabrick_config.areabricks.overview.table.col_headers.id'|trans }}</th>
<th>{{ 'neusta_pimcore_areabrick_config.areabricks.overview.table.col_headers.version'|trans }}</th>
<th>{{ 'neusta_pimcore_areabrick_config.areabricks.overview.table.col_headers.description'|trans }}</th>
{% if hasVersions %}
<th>{{ 'neusta_pimcore_areabrick_config.areabricks.overview.table.col_headers.version'|trans }}</th>
{% endif %}
{% if hasDescriptions %}
<th>{{ 'neusta_pimcore_areabrick_config.areabricks.overview.table.col_headers.description'|trans }}</th>
{% endif %}
<th>{{ 'neusta_pimcore_areabrick_config.areabricks.overview.table.col_headers.template'|trans }}</th>
<th>{{ 'neusta_pimcore_areabrick_config.areabricks.overview.table.col_headers.pages'|trans }}</th>
{% if hasAdditionalProperties %}
Expand All @@ -18,8 +26,12 @@
<tr>
<td>{{ brick.name|trans }}</td>
<td>{{ brick.id }}</td>
<td>{{ brick.version }}</td>
<td>{{ brick.description|trans }}</td>
{% if hasVersions %}
<td>{{ brick.version }}</td>
{% endif %}
{% if hasDescriptions %}
<td>{{ brick.description|trans }}</td>
{% endif %}
<td>{{ brick.template }}</td>
<td>
{% embed "@NeustaPimcoreAreabrickConfig/bricks/pages_accordion.html.twig" with {
Expand All @@ -40,7 +52,7 @@
{% if hasAdditionalProperties %}
<td>
<ul class="additional-properties">
{% for additionalProperty in brick.additionalProperties|default([]) %}
{% for additionalProperty in brick.additionalProperties %}
<li class="{% if additionalProperty.name == 'tags' %}tag{% elseif additionalProperty.name == 'groups' %}group{% endif %}">
{{ additionalProperty.name }}: {{ additionalProperty.value }}
</li>
Expand Down
Loading