Refactor to make ChillDateTimeType field rendering re-usable

- added html rendering to fields.html.twig and block_prefix to ChillDateTimeType.php
This commit is contained in:
2025-11-26 14:09:41 +01:00
parent 23d067fffe
commit a15c2aedd4
4 changed files with 36 additions and 38 deletions

View File

@@ -14,25 +14,7 @@
{{ form_errors(edit_form) }}
{{ form_row(edit_form.circle) }}
{{ form_row(edit_form.name) }}
<div class="mb-3 row">
<label for="{{ edit_form.date.date.vars.id }}" class="col-form-label col-sm-4 required">
{{ 'Date'|trans }}
</label>
<div class="col-sm-8 d-flex align-items-start gap-2">
{{ form_widget(edit_form.date.date, {
attr: {
class: 'form-control',
style: 'flex: 1 1 auto;'
}
}) }}
{{ form_widget(edit_form.date.time, {
attr: {
class: 'form-control',
style: 'flex: 0 0 200px; max-width: 200px; white-space: nowrap; padding: 0;'
}
}) }}
</div>
</div>
{{ form_row(edit_form.date) }}
{{ form_row(edit_form.type, { label: "Event type" }) }}
{{ form_row(edit_form.themes) }}
{{ form_row(edit_form.moderator) }}

View File

@@ -16,25 +16,7 @@
{{ form_errors(form) }}
{{ form_row(form.name) }}
{{ form_row(form.circle) }}
<div class="mb-3 row">
<label for="{{ form.date.date.vars.id }}" class="col-form-label col-sm-4 required">
{{ 'Date'|trans }}
</label>
<div class="col-sm-8 d-flex align-items-start gap-2">
{{ form_widget(form.date.date, {
attr: {
class: 'form-control',
style: 'flex: 1 1 auto;'
}
}) }}
{{ form_widget(form.date.time, {
attr: {
class: 'form-control',
style: 'flex: 0 0 200px; max-width: 200px; white-space: nowrap; padding: 0;'
}
}) }}
</div>
</div>
{{ form_row(form.date) }}
{{ form_row(form.type, { label: "Event type" }) }}
{{ form_row(form.themes) }}
{{ form_row(form.moderator) }}

View File

@@ -37,4 +37,9 @@ class ChillDateTimeType extends AbstractType
{
return DateTimeType::class;
}
public function getBlockPrefix(): string
{
return 'chill_datetime';
}
}

View File

@@ -311,3 +311,32 @@
</div>
</div>
{% endblock %}
{% block chill_datetime_label %}
<label for="{{ form.date.vars.id }}" class="col-form-label col-sm-4 required">
{{ "Date"|trans }}
</label>
{% endblock %}
{% block chill_datetime_widget %}
<div class="col-sm-8 d-flex align-items-start gap-2">
{#date#}
{{ form_widget(form.date, {
attr: { class: 'form-control', style: 'flex: 1 1 auto;' }
}) }}
{#time#}
{{ form_widget(form.time, {
attr: {
class: 'form-select',
style: 'flex: 0 0 200px; max-width: 200px; white-space: nowrap; padding:0;'
}
}) }}
</div>
{% endblock %}
{% block chill_datetime_row %}
<div class="mb-3 row">
{{ block('chill_datetime_label') }}
{{ block('chill_datetime_widget') }}
</div>
{% endblock %}