src/AdminBundle/Admin/DCAutoSite/FaqAdmin.php line 15

Open in your IDE?
  1. <?php
  2. namespace AdminBundle\Admin\DCAutoSite;
  3. use AdminBundle\Admin\BaseAdmin;
  4. use CoreBundle\Entity\User;
  5. use DcSiteBundle\Model\FaqModel;
  6. use FOS\CKEditorBundle\Form\Type\CKEditorType;
  7. use Sonata\AdminBundle\Datagrid\ListMapper;
  8. use Sonata\AdminBundle\Form\FormMapper;
  9. use Symfony\Component\Finder\Exception\AccessDeniedException;
  10. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  11. class FaqAdmin extends BaseAdmin
  12. {
  13.     public function prePersist($object): void
  14.     {
  15.         /** @var User $User */
  16.         $User $this->security->getUser();
  17.         if (!$User->getDealer() && !$object->getDealer()) {
  18.             throw new AccessDeniedException('User without dealer');
  19.         }
  20.         $object->setDealer($User->getDealer());
  21.     }
  22.     protected function configureFormFields(FormMapper $formMapper): void
  23.     {
  24.         $formMapper
  25.             ->with('Question', ['class' => 'col-md-6'])
  26.             ->add('question_ua'null, ['label' => 'Питання (UA)'])
  27.             ->add('answer_ua'CKEditorType::class, ['label' => 'Відповідь (UA)'])
  28.             ->add('page'ChoiceType::class, [
  29.                 'label' => 'Тип',
  30.                 'choices' => array_flip(FaqModel::getPage())])
  31.             ->end()
  32.             ->with('Answer', ['class' => 'col-md-6'])
  33.             ->add('question_ru'null, ['label' => 'Питання (RU)'])
  34.             ->add('answer_ru'CKEditorType::class, ['label' => 'Відповідь (RU)'])
  35.             ->end();
  36.     }
  37.     /**
  38.      * @param ListMapper $listMapper
  39.      */
  40.     protected function configureListFields(ListMapper $listMapper): void
  41.     {
  42.         $listMapper->addIdentifier('id')
  43.             ->add('question_ua'null, ['label' => 'Питання'])
  44.             ->add('answer_ua'null, ['label' => 'Відповідь'])
  45.             ->add('page''choice', ['label' => 'Тип''choices' => FaqModel::getPage()])
  46.             ->add('_action''actions', array(
  47.                 'label' => 'Действия',
  48.                 'actions' => array(
  49.                     'edit' => array(),
  50.                     'delete' => array(),
  51.                 )
  52.             ));
  53.     }
  54. }