src/AdminBundle/Admin/SubAutoSite/InnerMailAdmin.php line 18

Open in your IDE?
  1. <?php
  2. namespace AdminBundle\Admin\SubAutoSite;
  3. use Sonata\AdminBundle\Datagrid\ListMapper;
  4. use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
  5. use Sonata\AdminBundle\Form\FormMapper;
  6. use Sonata\AdminBundle\Route\RouteCollection;
  7. use Sonata\AdminBundle\Route\RouteCollectionInterface;
  8. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  9. /**
  10.  * Class InnerMailAdmin
  11.  * @package AdminBundle\Admin\SubAutoSite
  12.  */
  13. class InnerMailAdmin extends BaseImporterAdmin
  14. {
  15.     /**
  16.      * @param RouteCollection $collection
  17.      */
  18.     protected function configureRoutes(RouteCollectionInterface $collection): void
  19.     {
  20.         $collection->remove('view');
  21.         $collection->remove('delete');
  22.     }
  23.     /**
  24.      * @param $object
  25.      */
  26.     public function prePersist($object): void
  27.     {
  28.         $dealer $this->security->getUser()->getSubDealer();
  29.         $object->setDealer($dealer);
  30.     }
  31.     /**
  32.      * @param string $context
  33.      * @return ProxyQueryInterface
  34.      */
  35.     public function configureQuery($context 'list'): ProxyQueryInterface
  36.     {
  37.         $user $this->security->getUser();
  38.         $dealer $user->getSubDealer();
  39.         $query parent::configureQuery($context);
  40.         $query->andWhere(
  41.             $query->expr()->eq($query->getRootAliases()[0] . '.dealer'':dealer')
  42.         );
  43.         $query->setParameter('dealer'$dealer);
  44.         return $query;
  45.     }
  46.     /**
  47.      * @param ListMapper $listMapper
  48.      */
  49.     protected function configureListFields(ListMapper $listMapper): void
  50.     {
  51.         $listMapper
  52.             ->add('dealer'null, ['admin_code' => 'admin.sub.contact'])
  53.             ->add('_action'null, [
  54.                 'actions' => [
  55.                     'edit' => [],
  56.                 ],
  57.             ])
  58.         ;
  59.     }
  60.     /**
  61.      * @param FormMapper $formMapper
  62.      */
  63.     protected function configureFormFields(FormMapper $formMapper): void
  64.     {
  65.         $options = [
  66.             'required' => false,
  67.             'allow_add' => true,
  68.             'allow_delete' => true,
  69.             'prototype' => true,
  70.             'by_reference' => false,
  71.         ];
  72.         $formMapper
  73.             ->with(' ', ['class' => 'col-md-4'])
  74.                 ->add('serviceType',    CollectionType::class, array_merge($options, ['label' => 'Запис на сервіс']))
  75.                 ->add('sparePartsType'CollectionType::class, array_merge($options, ['label' => 'Замовлення запчастин']))
  76.                 ->add('orderType',      CollectionType::class, array_merge($options, ['label' => 'Заявка на купівлю ТЗ']))
  77.             ->end()
  78.             ->with('  ', ['class' => 'col-md-4'])
  79.                 ->add('questionType',   CollectionType::class, array_merge($options, ['label' => 'Зворотний зв\'язок']))
  80.                 ->add('creditType',     CollectionType::class, array_merge($options, ['label' => 'Консультація щодо кредиту']))
  81.                 ->add('insuranceType',  CollectionType::class, array_merge($options, ['label' => 'Консультація щодо страхування']))
  82.             ->end()
  83.             ->with('   ', ['class' => 'col-md-4'])
  84.                 ->add('commisionType',  CollectionType::class, array_merge($options, ['label' => 'Заявка техніки на комісію']))
  85.                 ->add('testDriveType',  CollectionType::class, array_merge($options, ['label' => 'Заявка на тест-драйв']))
  86.                 ->add('accessoriesType',       CollectionType::class, array_merge($options, ['label' => 'Заявка аксессуарів']))
  87.             ->end()
  88.         ;
  89.     }
  90. }