Skip to content

Commit 0099b02

Browse files
committed
4410: Hacked display of theme categories
1 parent a0e47eb commit 0099b02

4 files changed

Lines changed: 92 additions & 0 deletions

File tree

assets/styles/app.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,20 @@ th.rotate {
288288
}
289289
}
290290
}
291+
292+
/* Help our theme.themeCategories table stuff fall into place visually (cf. template/admin/form.html.twig) */
293+
#form-theme-themeCategories {
294+
td {
295+
vertical-align: top;
296+
}
297+
298+
tr.field-collection-item {
299+
display: table-row;
300+
301+
.field-collection-delete-button {
302+
inset-block-start: initial;
303+
inset-inline-end: initial;
304+
position: initial;
305+
}
306+
}
307+
}

src/Controller/Admin/ThemeCrudController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ public static function getEntityFqcn(): string
1818
return Theme::class;
1919
}
2020

21+
#[\Override]
22+
public function configureCrud(Crud $crud): Crud
23+
{
24+
return $crud
25+
// https://symfony.com/bundles/EasyAdminBundle/current/design.html#form-field-templates
26+
->addFormTheme('admin/form.html.twig');
27+
}
28+
2129
/**
2230
* @throws \Exception
2331
*/

templates/admin/form.html.twig

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{# @see https://symfony.com/bundles/EasyAdminBundle/current/design.html#form-field-templates #}
2+
{% block _Theme_themeCategories_widget %}
3+
{% set id = 'form-theme-themeCategories' %}
4+
<table class="table table-striped" id="{{ id }}">
5+
<thead>
6+
<th>{{ 'theme.form.sort_order'|trans }}</th>
7+
<th>{{ 'theme.form.category'|trans }}</th>
8+
<th></th>
9+
</thead>
10+
<tbody class="ea-form-collection-items field-array">
11+
{{ block('_Theme_themeCategories_collection_widget') }}
12+
</tbody>
13+
</table>
14+
{# Pretend that the collection is an array collection to make "add item" not assume that we have an accordion, cf. vendor/easycorp/easyadmin-bundle/assets/js/field-collection.js #}
15+
<script>
16+
const el = document.getElementById({{ id|json_encode|raw }}).closest('[data-ea-collection-field]');
17+
if (el) {
18+
el.classList.add('field-array')
19+
}
20+
</script>
21+
22+
{% if allow_add|default(false) and not disabled %}
23+
<button type="button" class="btn btn-link field-collection-add-button">
24+
<twig:ea:Icon name="internal:plus" class="pr-1" />
25+
{{ 'theme.form.add_new_item'|trans }}
26+
</button>
27+
{% endif %}
28+
{% endblock %}
29+
30+
{% block _Theme_themeCategories_collection_widget %}
31+
{% set isEmptyCollection = value is null or (value is iterable and value is empty) %}
32+
33+
{% if isEmptyCollection %}
34+
{{ block('_Theme_themeCategories_empty_collection') }}
35+
{% else %}
36+
{{ block('form_widget') }}
37+
{% endif %}
38+
{% endblock %}
39+
40+
{% block _Theme_themeCategories_empty_collection %}
41+
<tr>
42+
<td colspan="3">
43+
{{ 'No theme categories'|trans }}
44+
</td>
45+
</tr>
46+
{% endblock %}
47+
48+
{% block _Theme_themeCategories_entry_row %}
49+
{# See block collection_entry_row in @EasyAdmin:crud/form_theme.html.twig for details on which bits and pieces are used to stitch this together #}
50+
<tr class="field-collection-item">
51+
<td>
52+
{{ form_widget(form.sortOrder) }}
53+
{{ form_errors(form.sortOrder) }}
54+
</td>
55+
<td>
56+
{{ form_widget(form.category) }}
57+
{{ form_errors(form.category) }}
58+
</td>
59+
<td>
60+
<button type="button" class="btn btn-danger field-collection-delete-button">
61+
{{ 'theme.form.delete_item'|trans }}
62+
</button>
63+
</td>
64+
</tr>
65+
{% endblock %}

translations/messages.da.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ theme:
2929
theme_categories: Kategorier
3030
sort_order: Sortering
3131
category: Kategori
32+
delete_item: Fjern
33+
add_new_item: Tilføj
3234

3335
filter:
3436
submit: Søg

0 commit comments

Comments
 (0)