src/AdminBundle/Admin/Vehicles/EquipmentAdmin.php line 15

Open in your IDE?
  1. <?php
  2. namespace AdminBundle\Admin\Vehicles;
  3. use AdminBundle\Admin\BaseAdmin;
  4. use AdminBundle\Form\Type\Vehicle\EditEquipmentType;
  5. use Sonata\AdminBundle\Datagrid\DatagridMapper;
  6. use Sonata\AdminBundle\Datagrid\ListMapper;
  7. use Sonata\AdminBundle\Form\FormMapper;
  8. use Sonata\AdminBundle\Route\RouteCollectionInterface;
  9. use Symfony\Component\Finder\Exception\AccessDeniedException;
  10. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  11. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  12. class EquipmentAdmin extends BaseAdmin
  13. {
  14.     /**
  15.      * @param RouteCollectionInterface $collection
  16.      */
  17.     protected function configureRoutes(RouteCollectionInterface $collection): void
  18.     {
  19.         $collection->remove('delete');
  20.         $collection->remove('view');
  21.         $collection->add('editOption'$this->getRouterIdParameter() . '/edit_option');
  22.         $collection->add('cloneEquipment'$this->getRouterIdParameter() . '/clone');
  23.     }
  24.     protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
  25.     {
  26.         $datagridMapper
  27.             ->add('vehicle.id'null, ['label' => 'id основної машинки'])
  28.             ->add('vehicle.vin'null, ['label' => 'ВІН'])
  29.             ->add('vehicle.url'null, ['label' => 'SEO url']);
  30.     }
  31.     /**
  32.      * @param ListMapper $listMapper
  33.      */
  34.     protected function configureListFields(ListMapper $listMapper): void
  35.     {
  36.         $listMapper
  37.             ->addIdentifier('id')
  38.             ->add('vehicle.model'null, ['label' => 'Підв\'язано до моделі',])
  39.             ->add('vehicle.model.brand'null, ['label' => 'Підв\'язано до бренда',])
  40.             ->add('vehicle.vin'null, ['label' => 'Він машинки',])
  41.             ->add('vehicle.id'null, ['label' => 'ID машинки',])
  42.             ->add('_action''actions', [
  43.                 'actions' => [
  44.                     'edit' => [],
  45.                 ]
  46.             ]);
  47.     }
  48.     /**
  49.      * @param FormMapper $formMapper
  50.      */
  51.     protected function configureFormFields(FormMapper $formMapper): void
  52.     {
  53.         if (!$this->getUser()->getDealer()) {
  54.             throw new AccessDeniedException('User without dealer');
  55.         }
  56.         $formMapper
  57.             ->tab('Основная информация')
  58.             ->with('Данные комплектации', ['class' => 'col-lg-4'])
  59.             ->add('title'null, ['label' => 'Название комплектации'])
  60.             ->add('position'NumberType::class, ['label' => 'Позиция'])
  61.             ->add('state'CheckboxType::class, ['label' => 'Отображать на сайте'])
  62.             ->add('actions'EditEquipmentType::class, [
  63.                 'label' => 'Действия',
  64.                 'mapped' => false,
  65.             ])
  66.             ->end()
  67.             ->end();
  68.     }
  69. }