src/AdminBundle/Admin/Founders/SocialInvestmentsAdmin.php line 21

Open in your IDE?
  1. <?php
  2. namespace AdminBundle\Admin\Founders;
  3. use AdminBundle\Admin\BaseAdmin;
  4. use FOS\CKEditorBundle\Form\Type\CKEditorType;
  5. use FoundersBundle\Entity\CategoryPost;
  6. use FoundersBundle\Entity\Post;
  7. use FoundersBundle\Model\Post as ModelPost;
  8. use Sonata\AdminBundle\Datagrid\ListMapper;
  9. use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
  10. use Sonata\AdminBundle\Form\FormMapper;
  11. use Sonata\AdminBundle\Form\Type\ModelType;
  12. use Sonata\MediaBundle\Form\Type\MediaType;
  13. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  14. use Symfony\Component\Form\Extension\Core\Type\DateType;
  15. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  16. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  17. use Symfony\Component\Validator\Constraints\Length;
  18. class SocialInvestmentsAdmin extends BasePostAdmin
  19. {
  20.     protected $baseRouteName 'adminbundle_founders_social_investments_admin';
  21.     protected $baseRoutePattern 'founders-post-social-investments';
  22.     /**
  23.      * @param Post $object
  24.      */
  25.     public function prePersist($object): void
  26.     {
  27.         $object->setPostType(ModelPost::POST_TYPE_SOCIAL_INVESTMENT);
  28.         parent::prePersist($object);
  29.     }
  30.     public function configureQuery($context 'list'): ProxyQueryInterface
  31.     {
  32.         $query parent::configureQuery($context);
  33.         $query->where($query->getRootAliases()[0].'.post_type = ' ModelPost::POST_TYPE_SOCIAL_INVESTMENT);
  34.         return $query;
  35.     }
  36.     protected function configureFormFields(FormMapper $form): void
  37.     {
  38.         $form
  39.             ->with('Контент', ['class' => 'col-md-6'])
  40.                 ->add('title'null, ['label' => 'Заголовок''required' => true,
  41.                     'attr' => ['maxlength' => 125],
  42.                     'constraints' => [
  43.                         new Length([
  44.                             'max' => 125,
  45.                             'maxMessage' => 'Заголовок не може містити більше {{ limit }} символів.'
  46.                         ])
  47.                     ]
  48.                 ])
  49.                 ->add('description_shot'TextareaType::class, ['label' => 'Опис короткий'])
  50.                 ->add('description'CKEditorType::class, ['config_name' => 'default''label' => 'Опис повний'])
  51.                 ->add('category'ModelType::class, ['label' => 'Категорія''required' => true'btn_add' => false'query' => $this->getCategoryPost()])
  52.                 ->add('seo_title'TextareaType::class, ['label' => 'SEO Title''required' => false])
  53.                 ->add('seo_description'TextareaType::class, ['label' => 'SEO Description''required' => false])
  54.             ->end()
  55.             ->with('Додатково', ['class' => 'col-md-6'])
  56.                 ->add('state'CheckboxType::class, ['label' => 'Відображати на сайті''required' => false])
  57.                 ->add('image_preview'MediaType::class, [
  58.                     'label' => 'Попередній перегляд',
  59.                     'provider' => 'sonata.media.provider.image',
  60.                     'context' => 'dc_site'
  61.                 ])
  62.                 ->add('image'MediaType::class, [
  63.                     'label' => 'Зображення',
  64.                     'provider' => 'sonata.media.provider.image',
  65.                     'context' => 'dc_site'
  66.                 ])
  67.                 ->add('created'DateType::class, ['label' => 'Дата створення''widget' => 'single_text',])
  68.                 ->add('url'null, ['label' => 'URL''required' => false])
  69.                 ->add('position'NumberType::class, ['label' => 'Порядок виводу'])
  70.                 ->end()
  71.             ->end();
  72.     }
  73. }