From 498c71081dfeb811a9676a18c21c499ae185548a Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Wed, 25 Oct 2023 19:59:28 +0200 Subject: [PATCH] add red * on required label --- src/core/Entity/Site/Navigation.php | 2 +- src/core/Resources/assets/css/admin.scss | 10 ++++ .../form/bootstrap_4_form_theme.html.twig | 48 +++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/src/core/Entity/Site/Navigation.php b/src/core/Entity/Site/Navigation.php index 679ec3f..d538df1 100644 --- a/src/core/Entity/Site/Navigation.php +++ b/src/core/Entity/Site/Navigation.php @@ -67,7 +67,7 @@ class Navigation implements EntityInterface return $this->label; } - public function setLabel(string $label): self + public function setLabel(?string $label): self { $this->label = $label; diff --git a/src/core/Resources/assets/css/admin.scss b/src/core/Resources/assets/css/admin.scss index b4ac473..e6ac634 100644 --- a/src/core/Resources/assets/css/admin.scss +++ b/src/core/Resources/assets/css/admin.scss @@ -704,6 +704,16 @@ form { } } +label.required::after { + content: '*'; + margin-left: 3px; + color: #b41215; +} + +.invalid-feedback { + margin-top: -3px; +} + .gjs-editor-cont { border-radius: 10px; overflow: hidden !important; diff --git a/src/core/Resources/views/form/bootstrap_4_form_theme.html.twig b/src/core/Resources/views/form/bootstrap_4_form_theme.html.twig index 66d1862..05895ce 100644 --- a/src/core/Resources/views/form/bootstrap_4_form_theme.html.twig +++ b/src/core/Resources/views/form/bootstrap_4_form_theme.html.twig @@ -254,3 +254,51 @@ {{- form_help(form) -}} {%- endblock form_row %} + + +{% block form_label -%} + {% if label is not same as(false) -%} + {%- if compound is defined and compound -%} + {%- set element = 'legend' -%} + {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' col-form-label')|trim}) -%} + {%- else -%} + {%- set label_attr = label_attr|merge({for: id}) -%} + {%- endif -%} + {% if required -%} + {% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) %} + {%- endif -%} + {% if label is empty -%} + {%- if label_format is not empty -%} + {% set label = label_format|replace({ + '%name%': name, + '%id%': id, + }) %} + {%- else -%} + {% set label = name|humanize %} + {%- endif -%} + {%- endif -%} + <{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}> + {%- if translation_domain is same as(false) -%} + {%- if label_html is same as(false) -%} + {{- label -}} + {%- else -%} + {{- label|raw -}} + {%- endif -%} + {%- else -%} + {%- if label_html is same as(false) -%} + {{- label|trans(label_translation_parameters, translation_domain) -}} + {%- else -%} + {{- label|trans(label_translation_parameters, translation_domain)|raw -}} + {%- endif -%} + {%- endif -%} + + {% block form_label_errors %}{{- form_errors(form) -}}{% endblock form_label_errors %} + {%- else -%} + {%- if errors|length > 0 -%} +
+ {{- form_errors(form) -}} +
+ {%- endif -%} + {%- endif -%} +{%- endblock form_label %} +