src/AdminBundle/Admin/DCAutoSite/BoatAdmin.php line 19

Open in your IDE?
  1. <?php
  2. namespace AdminBundle\Admin\DCAutoSite;
  3. use AdminBundle\Admin\BaseAdmin;
  4. use FOS\CKEditorBundle\Form\Type\CKEditorType;
  5. use Sonata\AdminBundle\Datagrid\DatagridMapper;
  6. use Sonata\AdminBundle\Datagrid\ListMapper;
  7. use Sonata\AdminBundle\Form\FormMapper;
  8. use Sonata\AdminBundle\Form\Type\ModelListType;
  9. use Sonata\AdminBundle\Form\Type\ModelType;
  10. use Sonata\AdminBundle\Route\RouteCollectionInterface;
  11. use Sonata\MediaBundle\Form\Type\MediaType;
  12. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  13. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  14. use Symfony\Component\Form\Extension\Core\Type\IntegerType;
  15. class BoatAdmin extends BaseAdmin
  16. {
  17.     /**
  18.      * @param RouteCollectionInterface $collection
  19.      */
  20.     protected function configureRoutes(RouteCollectionInterface $collection): void
  21.     {
  22.         $collection->remove('view');
  23.         $collection->remove('delete');
  24.     }
  25.     /**
  26.      * @param ListMapper $listMapper
  27.      */
  28.     public function configureListFields(ListMapper $listMapper): void
  29.     {
  30.         $listMapper
  31.             ->addIdentifier('title_ru'null, ['label' => 'Название'])
  32.             ->add('state','choice', ['label' => 'Показывать на сайте''editable' => true'choices' => [
  33.                 => 'Да',
  34.                 => 'Нет',
  35.                 null => 'Нет',
  36.             ]])
  37.             ->add('_action','actions',[
  38.                 'label' => 'Действия',
  39.                 'actions' => [
  40.                     'edit' => [],
  41.                 ]
  42.             ])
  43.         ;
  44.     }
  45.     /**
  46.      * @param $object
  47.      */
  48.     public function prePersist($object): void
  49.     {
  50.         $dealer $this->security->getUser()->getDealer();
  51.         $object->setDealer($dealer);
  52.         $object->setYamahaEngine((int) $object->getYamahaEngine());
  53.         $object->setState((int) $object->getState());
  54.     }
  55.     public function preUpdate($object): void
  56.     {
  57.         $object->setYamahaEngine((int) $object->getYamahaEngine());
  58.         $object->setState((int) $object->getState());
  59.         parent::preUpdate($object);
  60.     }
  61.     /**
  62.      * @param FormMapper $formMapper
  63.      */
  64.     public function configureFormFields(FormMapper $formMapper): void
  65.     {
  66.         $dealer $this->security->getUser()->getDealer();
  67.         $formMapper
  68.             ->tab('Характеристики')
  69.             ->with('Русский', ['class' => 'col-md-6'])
  70.             ->add('title_ru'null, ['label' => 'Название RU'])
  71.             ->add('description_ru'TextareaType::class, ['label' => 'Краткое описание RU''required' => false,])
  72.             ->add('content_ru'CKEditorType::class, ['label' => 'Описание RU''required' => false])
  73.             ->end()
  74.             ->with('Украинский', ['class' => 'col-md-6'])
  75.             ->add('title_ua'null, ['label' => 'Название UA'])
  76.             ->add('description_ua'TextareaType::class, ['label' => 'Краткое описание UA''required' => false,])
  77.             ->add('content_ua'CKEditorType::class, ['label' => 'Описание UA''required' => false])
  78.             ->end()
  79.             ->with('Общие')
  80.             ->add('price'null, ['label' => 'Цена в валюте'])
  81.             ->add('alt_price'null, ['label' => 'Акционная цена'])
  82.             ->add('alt_rate'null, ['label' => 'Акционный курс'])
  83.             ->add('state',CheckboxType::class, ['label' => 'Показывать на сайте' ,'required' => false])
  84.             ->add('group'ModelType::class, [
  85.                 'label' => 'Группа',
  86.                 'btn_add' => false,
  87.                 'required' => true,
  88.             ])
  89.             ->add('url'null, ['label' => 'URL'])
  90.             ->end()
  91.             ->with('Характеристики', ['class' => 'col-md-6'])
  92.             ->add('max_capacity'null, [
  93.                 'label' => 'Максимальная вместимость',
  94.                 'required' => false,
  95.             ])
  96.             ->add('weight'IntegerType::class, [
  97.                 'label' => 'Вес',
  98.                 'required' => false,
  99.             ])
  100.             ->add('max_weight'IntegerType::class, [
  101.                 'label' => 'Максимальный вес',
  102.                 'required' => false,
  103.             ])
  104.             ->add('length'null, [
  105.                 'label' => 'Длина',
  106.                 'required' => false,
  107.             ])
  108.             ->add('width'null, [
  109.                 'label' => 'Ширина',
  110.                 'required' => false,
  111.             ])
  112.             ->add('recommended_power'null, [
  113.                 'label' => 'Рекомендованная мощность двигателя',
  114.                 'required' => false,
  115.             ])
  116.             ->add('transom'null, [
  117.                 'label' => 'Транец',
  118.                 'required' => false,
  119.             ])
  120.             ->add('yamaha_engine'CheckboxType::class, ['label' => 'Предустановка под моторы Yamaha ''required' => false])
  121.             ->end()
  122.             ->end()
  123.             ->tab('Медиа контент')
  124.             ->with('Изображения', ['class' => 'col-lg-6'])
  125.             ->add('preview'MediaType::class, [
  126.                 'label' => 'Превью',
  127.                 'provider' => 'sonata.media.provider.image',
  128.                 'context'  => 'dc_site'
  129.             ])
  130.             ->add('preview_second'MediaType::class, [
  131.                 'label' => 'Превью второй',
  132.                 'provider' => 'sonata.media.provider.image',
  133.                 'context'  => 'dc_site'
  134.             ])
  135.             ->end()
  136.             ->with('Галереи', ['class' => 'col-lg-6'])
  137.             ->add('gallery'ModelListType::class, [
  138.                 'label' => 'Галерея изображений',
  139.                 'btn_list' => false,
  140.                 'required' => false,
  141.             ], [
  142.                     'edit' => 'inline',
  143.                     'inline' => 'table',
  144.                     'sortable' => 'position',
  145.                     'link_parameters' => [
  146.                         'context' => 'dc_car_gallery',
  147.                         'provider' => 'sonata.media.provider.image'
  148.                     ],
  149.                     'admin_code' => 'sonata.media.admin.gallery',
  150.                 ]
  151.             )
  152.             ->add('video'ModelListType::class, [
  153.                 'label' => 'Галерея видео',
  154.                 'btn_list' => false,
  155.                 'required' => false,
  156.             ], [
  157.                 'edit' => 'inline',
  158.                 'inline' => 'table',
  159.                 'sortable' => 'position',
  160.                 'link_parameters' => [
  161.                     'context' => 'dc_car_video',
  162.                     'provider' => 'sonata.media.provider.youtube'
  163.                 ],
  164.                 'admin_code' => 'sonata.media.admin.gallery',
  165.             ])
  166.             ->end()
  167.             ->end()
  168.             ->tab('SEO')
  169.             ->with('RU', ['class' => 'col-md-6'])
  170.             ->add('seo_title_ru'null, ['label' => 'Seo-title (RU)''required' => false])
  171.             ->add('seo_description_ru'TextareaType::class, ['label' => 'Seo-description (RU)''required' => false])
  172.             ->end()
  173.             ->with('UA', ['class' => 'col-md-6'])
  174.             ->add('seo_title_ua'null, ['label' => 'Seo-title (UA)''required' => false])
  175.             ->add('seo_description_ua'TextareaType::class, ['label' => 'Seo-description (UA)''required' => false])
  176.             ->end()
  177.             ->end()
  178.         ;
  179.     }
  180.     /**
  181.      * @param DatagridMapper $datagridMapper
  182.      */
  183.     public function configureDatagridFilters(DatagridMapper $datagridMapper): void
  184.     {
  185.         $datagridMapper
  186.             ->add('title_ru')
  187.         ;
  188.     }
  189. }