src/AdminBundle/Admin/References/EquipmentOptionAdmin.php line 18

Open in your IDE?
  1. <?php
  2. namespace AdminBundle\Admin\References;
  3. use AdminBundle\Admin\BaseAdmin;
  4. use CoreBundle\Entity\User;
  5. use CoreBundle\Model\Vehicles\EquipmentOptions;
  6. use Sonata\AdminBundle\Datagrid\DatagridMapper;
  7. use Sonata\AdminBundle\Datagrid\ListMapper;
  8. use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
  9. use Sonata\AdminBundle\Form\FormMapper;
  10. use Sonata\AdminBundle\Route\RouteCollectionInterface;
  11. use Sonata\DoctrineORMAdminBundle\Filter\ChoiceFilter;
  12. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  13. class EquipmentOptionAdmin extends BaseAdmin
  14. {
  15.     protected function configureRoutes(RouteCollectionInterface $collection): void
  16.     {
  17.         //$collection->remove('delete');
  18.         $collection->remove('view');
  19.         $collection->add('exportEquipmentOptions''export-options');
  20.     }
  21.     public function configureActionButtons(array $buttonListstring $action$object null): array
  22.     {
  23.         $list parent::configureActionButtons($buttonList$action$object);
  24.         $list['export'] = [
  25.             'template' => '@AdminBundle/admin/export_equipment_options_button.html.twig',
  26.         ];
  27.         return $list;
  28.     }
  29.     protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
  30.     {
  31.         $datagridMapper->add('id');
  32.         $datagridMapper->add('title_ru',null, ['label' => 'Название (RU)']);
  33.         $datagridMapper->add('title_ua',null, ['label' => 'Название (UA)']);
  34.         $datagridMapper->add('dealer',null, ['label' => 'Дилер']);
  35.         $datagridMapper->add('option_type'ChoiceFilter::class, ['label' => 'Группа опций'], [ 'choices' => array_flip(EquipmentOptions::getTypes())]);
  36.     }
  37.     public function configureQuery($context 'list'): ProxyQueryInterface
  38.     {
  39.         $query parent::configureQuery($context);
  40.         $query->orderBy($query->getRootAliases()[0] .'.sort','ASC');
  41.         return $query;
  42.     }
  43.     protected function configureFormFields(FormMapper $formMapper): void
  44.     {
  45.         /** @var User $User */
  46.         $User $this->getUser();
  47.         $formMapper
  48.             ->tab('Основная информация'// The tab call is optional
  49.                 ->with('Данные опции', ['class' => 'col-lg-4'])
  50.                     ->add('title_ru'null, ['label' => 'Название (ru)'])
  51.                     ->add('title_ua'null, ['label' => 'Название (ua)'])
  52.                     ->add('sort'null, ['label' => 'Сортировка'])
  53.                     ->add('option_type'ChoiceType::class, ['label' => 'Группа опций','choices' => array_flip(EquipmentOptions::getTypes())])
  54.                     ->add('has_value'ChoiceType::class, ['label' => 'Тип опции','choices' => array_flip([=> 'Опция без значения',=> 'Опция cо значением'])])
  55.                 ->end()
  56.             ->end();
  57.         if($User->hasRole('ROLE_CONTENT_MANAGER') || $User->hasRole('ROLE_SUPER_ADMIN')) {
  58.             $formMapper
  59.                 ->tab('Основная информация'//
  60.                     ->with('Данные опции', ['class' => 'col-lg-4'])
  61.                         ->add('dealer'null, ['label' => 'Опция только для ДЦ'])
  62.                     ->end()
  63.                 ->end();
  64.         }
  65.     }
  66.     protected function configureListFields(ListMapper $listMapper): void
  67.     {
  68.         $listMapper->addIdentifier('id')
  69.             ->add('sort',null, ['label' => 'Сорт.'])
  70.             ->add('title_ru',null, ['label' => 'Название'])
  71.             ->add('option_type','choice', ['label' => 'Группа опций''choices' => EquipmentOptions::getTypes(),'header_style' => 'width:210px;'])
  72.             ->add('dealer'null, ['label' => 'Опция для дилера','header_style' => 'width:160px;'])
  73.             ->add('_action''actions', [
  74.                 'label' => 'Действия',
  75.                 'header_style' => 'width:210px;',
  76.                 'actions' => [
  77.                     'edit' => [],
  78.                     'delete' => [],
  79.                 ]
  80.             ])
  81.         ;
  82.     }
  83.     protected function configure(): void
  84.     {
  85.         parent::configure(); // TODO: Change the autogenerated stub
  86.         $this->setTemplate('list''@Admin/CRUD/Equipment/equipment_options_list.html.twig');
  87.     }
  88. }