src/AdminBundle/Admin/Vidi/AnnouncementBarAdmin.php line 14

Open in your IDE?
  1. <?php
  2. namespace AdminBundle\Admin\Vidi;
  3. use FOS\CKEditorBundle\Form\Type\CKEditorType;
  4. use PortalBundle\Entity\AnnouncementBar;
  5. use Sonata\AdminBundle\Admin\AbstractAdmin;
  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\CheckboxType;
  10. class AnnouncementBarAdmin extends AbstractAdmin
  11. {
  12.     /**
  13.      * @param RouteCollectionInterface $collection
  14.      */
  15.     protected function configureRoutes(RouteCollectionInterface $collection): void
  16.     {
  17.         $collection->remove('view');
  18.         $collection->remove('delete');
  19.     }
  20.     /**
  21.      * @param AnnouncementBar $object
  22.      */
  23.     public function prePersist($object): void
  24.     {
  25.         $object->setState((int)$object->getState());
  26.         $this->updateObject($object);
  27.     }
  28.     /**
  29.      * @param $object
  30.      */
  31.     public function preUpdate($object): void
  32.     {
  33.         $this->updateObject($object);
  34.         parent::preUpdate($object);
  35.     }
  36.     /**
  37.      * @param AnnouncementBar $object
  38.      */
  39.     private function updateObject($object)
  40.     {
  41.         $object->setState((int)$object->getState());
  42.     }
  43.     /**
  44.      * @param FormMapper $formMapper
  45.      */
  46.     protected function configureFormFields(FormMapper $formMapper): void
  47.     {
  48.         $formMapper
  49.             ->tab('Анонс Бар')
  50.             ->with('UA', ['class' => 'col-lg-6'])
  51.             ->add('text_ua_mob'CKEditorType::class, ['label' => 'Текст моб'])
  52.             ->add('text_ua_desktop'CKEditorType::class, ['label' => 'Текст десктоп',])
  53.             ->add('url_ua'null, ['label' => 'URL'])
  54.             ->end()
  55.             ->with('RU', ['class' => 'col-lg-6'])
  56.             ->add('text_ru_mob'CKEditorType::class, ['label' => 'Текст моб.',])
  57.             ->add('text_ru_desktop'CKEditorType::class, ['label' => 'Текст десктоп',])
  58.             ->add('url_ru'null, ['label' => 'URL'])
  59.             ->end()
  60.             ->add('state'CheckboxType::class, ['label' => 'Відображати на сайті''required' => false])
  61.             ->end();
  62.     }
  63.     /**
  64.      * @param ListMapper $listMapper
  65.      */
  66.     protected function configureListFields(ListMapper $listMapper): void
  67.     {
  68.         $listMapper->addIdentifier('id')
  69.             ->add('text_ua_mob'null, ['label' => 'Текст моб.'])
  70.             ->add('text_ua_desktop'null, ['label' => 'Текст десктоп'])
  71.             ->add('state''choice', ['label' => 'Показувати на сайті''editable' => true'choices' => [
  72.                 => 'Так',
  73.                 => 'Ні',
  74.             ]])
  75.             ->add('_action''actions', [
  76.                 'label' => 'Дії',
  77.                 'actions' => [
  78.                     'edit' => [],
  79.                 ]
  80.             ]);
  81.     }
  82. }