Skip to content
This repository has been archived by the owner on Aug 9, 2022. It is now read-only.

Commit

Permalink
#2 Add ParameterAdmin
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieu-ducrot committed Jul 5, 2021
1 parent 8486def commit bb5927d
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 4 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -47,7 +48,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
"dev-master": "1.0.x-dev"
}
}
}
9 changes: 9 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
74 changes: 74 additions & 0 deletions src/Admin/ParameterAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace Smart\ParameterBundle\Admin;

use Smart\SonataBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\AdminBundle\Show\ShowMapper;

/**
* @author Mathieu Ducrot <[email protected]>
*/
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()
;
}
}
2 changes: 1 addition & 1 deletion tests/config_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ doctrine:

smart_parameter:
parameters:
# Textual paramter
# Textual parameter
dummy_support_emails:
value: "[email protected], [email protected]"
help: "This parameter is used by the mailer for support recipients. Format : Separate email by comma."
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/config/full.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Full config fixture
smart_parameter:
parameters:
# Textual paramter
# Textual parameter
dummy_support_emails:
value: "[email protected], [email protected]"
help: "This parameter is used by the mailer for support recipients. Format : Separate email by comma."
Expand Down
43 changes: 43 additions & 0 deletions translations/admin.en.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="fr" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="dashboard.label_settings">
<source>dashboard.label_settings</source>
<target>Settings</target>
</trans-unit>
<trans-unit id="dashboard.label_parameter">
<source>dashboard.label_parameter</source>
<target>Parameters</target>
</trans-unit>
<trans-unit id="breadcrumb.link_parameter_list">
<source>breadcrumb.link_parameter_list</source>
<target>Parameter list</target>
</trans-unit>
<trans-unit id="breadcrumb.link_parameter_create">
<source>breadcrumb.link_parameter_create</source>
<target>Creating a parameter</target>
</trans-unit>
<trans-unit id="fieldset.label_general">
<source>fieldset.label_general</source>
<target>General informations</target>
</trans-unit>
<trans-unit id="field.label_id">
<source>field.label_id</source>
<target>#</target>
</trans-unit>
<trans-unit id="field.label_code">
<source>field.label_code</source>
<target>Code</target>
</trans-unit>
<trans-unit id="field.label_help">
<source>field.label_help</source>
<target>Help</target>
</trans-unit>
<trans-unit id="field.label_value">
<source>field.label_value</source>
<target>Value</target>
</trans-unit>
</body>
</file>
</xliff>
43 changes: 43 additions & 0 deletions translations/admin.fr.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="fr" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="dashboard.label_settings">
<source>dashboard.label_settings</source>
<target>Paramètrages</target>
</trans-unit>
<trans-unit id="dashboard.label_parameter">
<source>dashboard.label_parameter</source>
<target>Paramètres</target>
</trans-unit>
<trans-unit id="breadcrumb.link_parameter_list">
<source>breadcrumb.link_parameter_list</source>
<target>Liste des paramètres</target>
</trans-unit>
<trans-unit id="breadcrumb.link_parameter_create">
<source>breadcrumb.link_parameter_create</source>
<target>Création d'un paramètre</target>
</trans-unit>
<trans-unit id="fieldset.label_general">
<source>fieldset.label_general</source>
<target>Informations générales</target>
</trans-unit>
<trans-unit id="field.label_id">
<source>field.label_id</source>
<target>#</target>
</trans-unit>
<trans-unit id="field.label_code">
<source>field.label_code</source>
<target>Code</target>
</trans-unit>
<trans-unit id="field.label_help">
<source>field.label_help</source>
<target>Aide</target>
</trans-unit>
<trans-unit id="field.label_value">
<source>field.label_value</source>
<target>Valeur</target>
</trans-unit>
</body>
</file>
</xliff>

0 comments on commit bb5927d

Please sign in to comment.