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

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