Skip to content

Commit

Permalink
task: hide version and description columns if they are empty
Browse files Browse the repository at this point in the history
  • Loading branch information
jdreesen committed Oct 25, 2024
1 parent a9a9633 commit 3499335
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
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,
]));
}
}
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|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 %}

<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 }}</td>
<td>{{ brick.id }}</td>
<td>{{ brick.version }}</td>
<td>{{ brick.description }}</td>
{% if hasVersions %}
<td>{{ brick.version }}</td>
{% endif %}
{% if hasDescriptions %}
<td>{{ brick.description }}</td>
{% endif %}
<td>{{ brick.template }}</td>
<td>
{% set published_pages = brick.pages|filter(page => page.published) %}
Expand Down Expand Up @@ -59,7 +71,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

0 comments on commit 3499335

Please sign in to comment.