src/AdminBundle/Admin/Founders/PublicationsAdmin.php line 17

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