src/AdminBundle/Admin/References/MarkdownAdmin.php line 16

Open in your IDE?
  1. <?php
  2. namespace AdminBundle\Admin\References;
  3. use AdminBundle\Admin\BaseAdmin;
  4. use DcSiteBundle\Entity\Markdown;
  5. use Exception;
  6. use Sonata\AdminBundle\Datagrid\ListMapper;
  7. use Sonata\AdminBundle\Form\FormMapper;
  8. use Sonata\AdminBundle\Route\RouteCollectionInterface;
  9. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  10. use Symfony\Component\Form\Extension\Core\Type\TextType;
  11. use Symfony\Component\OptionsResolver\OptionsResolverInterface;
  12. class MarkdownAdmin extends BaseAdmin
  13. {
  14.     /**
  15.      * @param RouteCollectionInterface $collection
  16.      */
  17.     protected function configureRoutes(RouteCollectionInterface $collection): void
  18.     {
  19.         $collection->remove('view');
  20.     }
  21.     /**
  22.      * @param FormMapper $formMapper
  23.      * @throws Exception
  24.      */
  25.     protected function configureFormFields(FormMapper $formMapper): void
  26.     {
  27.         $brands $this->autoRia->getBrands();
  28.         $cBrands = [];
  29.         foreach ($brands as $item) {
  30.             $cBrands[$item['title']] = $item['id'];
  31.         }
  32.         /** @var Markdown $sub */
  33.         $sub $this->getSubject();
  34.         $models false;
  35.         if($sub->getRiaBrandId()) {
  36.             $models $this->autoRia->getModels($sub->getRiaBrandId());
  37.             $choices = [];
  38.             foreach ($models as $row) {
  39.                 $choices[$row['title']] = $row['id'];
  40.             }
  41.         }
  42.         $formMapper
  43.             ->with('Данные авто', ['class' => 'col-lg-6']);
  44.         $formMapper->add('ria_brand_id'ChoiceType::class, ['label' => 'Бренд''attr' => ['class' => 'riaBrand'], 'choices' => $cBrands]);
  45.         if($models) {
  46.             $formMapper->add('ria_model_id'ChoiceType::class, ['label' => 'Модель''attr' => ['class' => 'riaModel'], 'choices' => $choices'required' => false]);
  47.         } else {
  48.             $formMapper->add('ria_model_id'TextType::class,  ['attr' => ['disabled' => 'disabled'], 'label' => 'Для начала нужно указать бренд и нажать кнопку Сохранить и редактировать''required' => false]);
  49.         }
  50.         $formMapper->end()
  51.             ->with('Уцінка від роздрібної ціни нового автомобіля', ['class' => 'col-lg-6'])
  52.                 ->add('retail_6'null, ['label' => '6 місяців''required' => $models != false])
  53.                 ->add('retail_12'null, ['label' => '12 місяців''required' => $models != false])
  54.                 ->add('retail_24'null, ['label' => '24 місяців''required' => $models != false])
  55.                 ->add('retail_36'null, ['label' => '36 місяців''required' => $models != false])
  56.                 ->add('retail_48'null, ['label' => '48 місяців''required' => $models != false])
  57.                 ->add('retail_60'null, ['label' => '60 місяців''required' => $models != false])
  58.             ->end();
  59.     }
  60.     public function setDefaultOptions(OptionsResolverInterface $resolver)
  61.     {
  62.         $resolver->setDefaults([
  63.             'validation_groups' => false,
  64.         ]);
  65.     }
  66.     /**
  67.      * @param ListMapper $listMapper
  68.      */
  69.     protected function configureListFields(ListMapper $listMapper): void
  70.     {
  71.         $listMapper->addIdentifier('id')
  72.             ->add('ria_brand_id',null, ['label' => 'Бренд'])
  73.             ->add('ria_model_id',null, ['label' => 'Модель'])
  74.             ->add('_action','actions',[
  75.                 'label' => 'Действия',
  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('edit''@Admin/admin/CRUD/edit-markdown.html.twig');
  87.     }
  88. }