From bb5927d538619e3836c0a207bfddbcd30f5616e1 Mon Sep 17 00:00:00 2001 From: Mathieu Ducrot Date: Mon, 5 Jul 2021 16:16:45 +0200 Subject: [PATCH] #2 Add ParameterAdmin --- composer.json | 5 ++- config/services.yaml | 9 +++++ src/Admin/ParameterAdmin.php | 74 ++++++++++++++++++++++++++++++++++ tests/config_test.yml | 2 +- tests/fixtures/config/full.yml | 2 +- translations/admin.en.xlf | 43 ++++++++++++++++++++ translations/admin.fr.xlf | 43 ++++++++++++++++++++ 7 files changed, 174 insertions(+), 4 deletions(-) create mode 100644 src/Admin/ParameterAdmin.php create mode 100644 translations/admin.en.xlf create mode 100644 translations/admin.fr.xlf diff --git a/composer.json b/composer.json index 28b7243..916e15d 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,8 @@ "symfony/yaml": "^4.4", "symfony/dependency-injection": "^4.4", "doctrine/orm": "^2.9", - "doctrine/doctrine-bundle": "^2.4" + "doctrine/doctrine-bundle": "^2.4", + "smartbooster/sonata-bundle": "^1.1" }, "require-dev": { "squizlabs/php_codesniffer": "^3.6", @@ -47,7 +48,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "1.0.x-dev" } } } diff --git a/config/services.yaml b/config/services.yaml index 825c3c6..01631cc 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -29,3 +29,12 @@ services: Smart\ParameterBundle\Command\ParameterLoadCommand: public: false alias: smart_parameter.parameter_load_command + + admin.parameter: + class: Smart\ParameterBundle\Admin\ParameterAdmin + arguments: + - ~ + - Smart\ParameterBundle\Entity\Parameter + - ~ + tags: + - { name: sonata.admin, manager_type: orm, label: dashboard.label_parameter } diff --git a/src/Admin/ParameterAdmin.php b/src/Admin/ParameterAdmin.php new file mode 100644 index 0000000..3a8f0b0 --- /dev/null +++ b/src/Admin/ParameterAdmin.php @@ -0,0 +1,74 @@ + + */ +class ParameterAdmin extends AbstractAdmin +{ + protected function configureRoutes(RouteCollection $collection): void + { + $collection + ->remove('create') + ->remove('delete') + ; + parent::configureRoutes($collection); + } + + protected function configureListFields(ListMapper $list): void + { + $list + ->addIdentifier('id', null, ['label' => 'field.label_id']) + ->addIdentifier('code', null, ['label' => 'field.label_code']) + ->add('help', null, ['label' => 'field.label_help']) + ->add('value', null, ['label' => 'field.label_value']) + ; + } + + protected function configureDatagridFilters(DatagridMapper $filter): void + { + $filter + ->add('code', null, [ + 'show_filter' => true, + 'label' => 'field.label_code' + ]) + ; + } + + protected function configureShowFields(ShowMapper $show): void + { + $show + ->with('fieldset.label_general') + ->add('id', null, ['label' => 'field.label_id']) + ->add('code', null, ['label' => 'field.label_code']) + ->add('help', null, ['label' => 'field.label_help']) + ->add('value', null, ['label' => 'field.label_value']) + ->end() + ; + } + + protected function configureFormFields(FormMapper $form): void + { + $form + ->with('fieldset.label_general') + ->add('code', null, [ + 'label' => 'field.label_code', + 'disabled' => true + ]) + ->add('help', null, [ + 'label' => 'field.label_help', + 'disabled' => true + ]) + ->add('value', null, ['label' => 'field.label_value']) + ->end() + ; + } +} diff --git a/tests/config_test.yml b/tests/config_test.yml index 727bc5b..cb00c3e 100644 --- a/tests/config_test.yml +++ b/tests/config_test.yml @@ -13,7 +13,7 @@ doctrine: smart_parameter: parameters: - # Textual paramter + # Textual parameter dummy_support_emails: value: "support@example.com, technical-support@example.com" help: "This parameter is used by the mailer for support recipients. Format : Separate email by comma." diff --git a/tests/fixtures/config/full.yml b/tests/fixtures/config/full.yml index aac4eb4..7acdc06 100644 --- a/tests/fixtures/config/full.yml +++ b/tests/fixtures/config/full.yml @@ -1,7 +1,7 @@ # Full config fixture smart_parameter: parameters: - # Textual paramter + # Textual parameter dummy_support_emails: value: "support@example.com, technical-support@example.com" help: "This parameter is used by the mailer for support recipients. Format : Separate email by comma." diff --git a/translations/admin.en.xlf b/translations/admin.en.xlf new file mode 100644 index 0000000..64c1e53 --- /dev/null +++ b/translations/admin.en.xlf @@ -0,0 +1,43 @@ + + + + + + dashboard.label_settings + Settings + + + dashboard.label_parameter + Parameters + + + breadcrumb.link_parameter_list + Parameter list + + + breadcrumb.link_parameter_create + Creating a parameter + + + fieldset.label_general + General informations + + + field.label_id + # + + + field.label_code + Code + + + field.label_help + Help + + + field.label_value + Value + + + + diff --git a/translations/admin.fr.xlf b/translations/admin.fr.xlf new file mode 100644 index 0000000..344a809 --- /dev/null +++ b/translations/admin.fr.xlf @@ -0,0 +1,43 @@ + + + + + + dashboard.label_settings + Paramètrages + + + dashboard.label_parameter + Paramètres + + + breadcrumb.link_parameter_list + Liste des paramètres + + + breadcrumb.link_parameter_create + Création d'un paramètre + + + fieldset.label_general + Informations générales + + + field.label_id + # + + + field.label_code + Code + + + field.label_help + Aide + + + field.label_value + Valeur + + + +