GlobalParameterAdmin.php 2.44 KB
Newer Older
Julien Jorry committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
<?php

namespace App\Admin;

use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextType;

/**
 * Administration des paramètres généraux de l'outil de MLC.
 *
 * KOHINOS : Outil de gestion de Monnaie Locale Complémentaire
 *
 * @author Julien Jorry <julien.jorry@gmail.com>
 */
class GlobalParameterAdmin extends AbstractAdmin
{
    protected $translator;
    protected $datagridValues = [
        '_sort_order' => 'ASC',
        '_sort_by' => 'name',
    ];

    /**
     * {@inheritdoc}
     */
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->add('name', TextType::class, [
                'label' => 'Nom :',
                'attr' => ['class' => 'text-uppercase'],
            ])
            ->add('description', TextType::class, [
                'label' => 'Description :',
            ])
            ->add('value', TextType::class, [
                'label' => 'Valeur :',
            ])
            ->add('mandatory', HiddenType::class, [
                'empty_data' => false,
                'data' => false,
            ])
        ;
    }

    /**
     * {@inheritdoc}
     */
    protected function configureListFields(ListMapper $listMapper)
    {
        unset($this->listModes['mosaic']);
        $listMapper
56
            ->add('name', null, ['label' => 'Nom'])
Julien Jorry committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
            ->add('description', null, ['label' => 'Description'])
            ->add('value', null, ['editable' => true, 'truncate' => ['length' => 80], 'label' => 'Value'])
            ->add('_action', null, [
                'label' => 'Action(s)',
                'actions' => [
                    'edit' => ['template' => '@kohinos/bundles/SonataAdminBundle/CRUD/list__action_edit_gp.html.twig'],
                    'delete' => ['template' => '@kohinos/bundles/SonataAdminBundle/CRUD/list__action_delete_gp.html.twig'],
                ],
            ])
        ;
    }

    public function getTemplate($name)
    {
        if ('list' == $name) {
            return '@kohinos/admin/globalparameter_list.html.twig';
        }

        return parent::getTemplate($name);
    }

    public function getBatchActions()
    {
        $actions = parent::getBatchActions();
        unset($actions['delete']);
        unset($actions['edit']);

        return $actions;
    }
}