From bda9584346ca466d90393de6d4291a599fe456b1 Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Wed, 30 Oct 2019 13:59:53 +0100 Subject: [PATCH] reformat edit forms (#1192) --- src/Form/EntityFormTrait.php | 1 + src/Form/Extension/IconExtension.php | 47 +++++++++++++++ src/Form/Type/AvatarType.php | 35 +++++++++++ src/Form/UserEditType.php | 4 +- templates/activity/edit.html.twig | 47 ++++++++++++++- templates/customer/edit.html.twig | 86 +++++++++++++++++++++++++++- templates/form/kimai-theme.html.twig | 13 +++++ templates/project/edit.html.twig | 54 ++++++++++++++++- 8 files changed, 279 insertions(+), 8 deletions(-) create mode 100644 src/Form/Extension/IconExtension.php create mode 100644 src/Form/Type/AvatarType.php diff --git a/src/Form/EntityFormTrait.php b/src/Form/EntityFormTrait.php index 0c39f74b..1c815303 100644 --- a/src/Form/EntityFormTrait.php +++ b/src/Form/EntityFormTrait.php @@ -43,6 +43,7 @@ trait EntityFormTrait ]) ->add('timeBudget', DurationType::class, [ 'label' => 'label.timeBudget', + 'icon' => 'clock', 'required' => false, ]) ; diff --git a/src/Form/Extension/IconExtension.php b/src/Form/Extension/IconExtension.php new file mode 100644 index 00000000..d1f4897c --- /dev/null +++ b/src/Form/Extension/IconExtension.php @@ -0,0 +1,47 @@ +vars['icon'] = $options['icon'] ?? null; + } + + /** + * @param OptionsResolver $resolver + */ + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefined(['icon']); + $resolver->setAllowedTypes('icon', 'string'); + $resolver->setDefault('icon', ''); + } +} diff --git a/src/Form/Type/AvatarType.php b/src/Form/Type/AvatarType.php new file mode 100644 index 00000000..291c2abe --- /dev/null +++ b/src/Form/Type/AvatarType.php @@ -0,0 +1,35 @@ +setDefaults([ + 'label' => 'label.avatar', + ]); + } + + /** + * {@inheritdoc} + */ + public function getParent() + { + return TextType::class; + } +} diff --git a/src/Form/UserEditType.php b/src/Form/UserEditType.php index 743ab842..2d552900 100644 --- a/src/Form/UserEditType.php +++ b/src/Form/UserEditType.php @@ -10,6 +10,7 @@ namespace App\Form; use App\Entity\User; +use App\Form\Type\AvatarType; use App\Form\Type\YesNoType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\EmailType; @@ -36,8 +37,7 @@ class UserEditType extends AbstractType 'label' => 'label.title', 'required' => false, ]) - ->add('avatar', TextType::class, [ - 'label' => 'label.avatar', + ->add('avatar', AvatarType::class, [ 'required' => false, ]) ->add('email', EmailType::class, [ diff --git a/templates/activity/edit.html.twig b/templates/activity/edit.html.twig index 8b7af6cb..d37203b7 100644 --- a/templates/activity/edit.html.twig +++ b/templates/activity/edit.html.twig @@ -6,9 +6,52 @@ {% block page_actions %}{{ actions.activity(activity, 'edit') }}{% endblock %} {% block main %} - {{ include(app.request.xmlHttpRequest ? 'default/_form_modal.html.twig' : 'default/_form.html.twig', { + {% set formEditTemplate = app.request.xmlHttpRequest ? 'default/_form_modal.html.twig' : 'default/_form.html.twig' %} + {% set formOptions = { 'title': activity.name|default('create'|trans), 'form': form, 'back': path('admin_activity') - }) }} + } %} + {% embed formEditTemplate with formOptions %} + {% block form_body %} +
+
+ {{ form_row(form.name) }} +
+
+ {{ form_row(form.color) }} +
+
+ {{ form_row(form.comment) }} + {{ form_row(form.customer) }} + {{ form_row(form.project) }} +
+ {#Financial data#} +
+
+ {{ form_row(form.fixedRate) }} +
+
+ {{ form_row(form.hourlyRate) }} +
+
+
+
+ {{ form_row(form.budget) }} +
+
+ {{ form_row(form.timeBudget) }} +
+
+
+ {{ form_row(form.visible) }} + {% if form.metaFields is defined and form.metaFields is not empty %} +
+ {#Custom fields#} + {{ form_row(form.metaFields) }} +
+ {% endif %} + {{ form_widget(form) }} + {% endblock %} + {% endembed %} {% endblock %} diff --git a/templates/customer/edit.html.twig b/templates/customer/edit.html.twig index 212d9bfc..3b0639f2 100644 --- a/templates/customer/edit.html.twig +++ b/templates/customer/edit.html.twig @@ -6,9 +6,91 @@ {% block page_actions %}{{ actions.customer(customer, 'edit') }}{% endblock %} {% block main %} - {{ include(app.request.xmlHttpRequest ? 'default/_form_modal.html.twig' : 'default/_form.html.twig', { + {% set formEditTemplate = app.request.xmlHttpRequest ? 'default/_form_modal.html.twig' : 'default/_form.html.twig' %} + {% set formOptions = { 'title': customer.name|default('create'|trans), 'form': form, 'back': path('admin_customer') - }) }} + } %} + {% embed formEditTemplate with formOptions %} + {% block form_body %} +
+
+ {{ form_row(form.name) }} +
+
+ {{ form_row(form.color) }} +
+
+ {{ form_row(form.comment) }} +
+ {#Company data#} + {{ form_row(form.company) }} + {{ form_row(form.address) }} +
+
+ {{ form_row(form.country) }} +
+
+ {{ form_row(form.currency) }} +
+
+ {{ form_row(form.timezone) }} +
+
+
+
+ {#Contact data#} +
+
+ {{ form_row(form.contact) }} +
+
+ {{ form_row(form.email) }} +
+
+ {{ form_row(form.homepage) }} +
+
+
+
+ {{ form_row(form.mobile) }} +
+
+ {{ form_row(form.phone) }} +
+
+ {{ form_row(form.fax) }} +
+
+
+
+ {#Financial data#} +
+
+ {{ form_row(form.fixedRate) }} +
+
+ {{ form_row(form.hourlyRate) }} +
+
+
+
+ {{ form_row(form.budget) }} +
+
+ {{ form_row(form.timeBudget) }} +
+
+
+ {{ form_row(form.visible) }} + {% if form.metaFields is defined and form.metaFields is not empty %} +
+ {#Custom fields#} + {{ form_row(form.metaFields) }} +
+ {% endif %} + {{ form_widget(form) }} + {% endblock %} + {% endembed %} {% endblock %} diff --git a/templates/form/kimai-theme.html.twig b/templates/form/kimai-theme.html.twig index 7e7bcb75..c6d8a361 100644 --- a/templates/form/kimai-theme.html.twig +++ b/templates/form/kimai-theme.html.twig @@ -32,3 +32,16 @@ {{ block('form_widget_simple') }} {%- endif -%} {%- endblock datetime_widget %} + +{% block text_widget -%} + {% if icon is not empty %} +
+
+ +
+ {{ block('form_widget_simple') }} +
+ {% else %} + {{ block('form_widget_simple') }} + {% endif %} +{%- endblock text_widget %} diff --git a/templates/project/edit.html.twig b/templates/project/edit.html.twig index cc428d92..c4c466d5 100644 --- a/templates/project/edit.html.twig +++ b/templates/project/edit.html.twig @@ -6,9 +6,59 @@ {% block page_actions %}{{ actions.project(project, 'edit') }}{% endblock %} {% block main %} - {{ include(app.request.xmlHttpRequest ? 'default/_form_modal.html.twig' : 'default/_form.html.twig', { + {% set formEditTemplate = app.request.xmlHttpRequest ? 'default/_form_modal.html.twig' : 'default/_form.html.twig' %} + {% set formOptions = { 'title': project.name|default('create'|trans), 'form': form, 'back': path('admin_project') - }) }} + } %} + {% embed formEditTemplate with formOptions %} + {% block form_body %} +
+
+ {{ form_row(form.name) }} +
+
+ {{ form_row(form.color) }} +
+
+ {{ form_row(form.comment) }} + {{ form_row(form.customer) }} +
+
+ {{ form_row(form.orderNumber) }} +
+
+ {{ form_row(form.orderDate) }} +
+
+
+ {#Financial data#} +
+
+ {{ form_row(form.fixedRate) }} +
+
+ {{ form_row(form.hourlyRate) }} +
+
+
+
+ {{ form_row(form.budget) }} +
+
+ {{ form_row(form.timeBudget) }} +
+
+
+ {{ form_row(form.visible) }} + {% if form.metaFields is defined and form.metaFields is not empty %} +
+ {#Custom fields#} + {{ form_row(form.metaFields) }} +
+ {% endif %} + {{ form_widget(form) }} + {% endblock %} + {% endembed %} {% endblock %}