<?php
namespace AdminBundle\Admin\DCAutoSite;
use AdminBundle\Admin\BaseAdmin;
use CoreBundle\Entity\User;
use DcSiteBundle\Model\FaqModel;
use FOS\CKEditorBundle\Form\Type\CKEditorType;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Symfony\Component\Finder\Exception\AccessDeniedException;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
class FaqAdmin extends BaseAdmin
{
public function prePersist($object): void
{
/** @var User $User */
$User = $this->security->getUser();
if (!$User->getDealer() && !$object->getDealer()) {
throw new AccessDeniedException('User without dealer');
}
$object->setDealer($User->getDealer());
}
protected function configureFormFields(FormMapper $formMapper): void
{
$formMapper
->with('Question', ['class' => 'col-md-6'])
->add('question_ua', null, ['label' => 'Питання (UA)'])
->add('answer_ua', CKEditorType::class, ['label' => 'Відповідь (UA)'])
->add('page', ChoiceType::class, [
'label' => 'Тип',
'choices' => array_flip(FaqModel::getPage())])
->end()
->with('Answer', ['class' => 'col-md-6'])
->add('question_ru', null, ['label' => 'Питання (RU)'])
->add('answer_ru', CKEditorType::class, ['label' => 'Відповідь (RU)'])
->end();
}
/**
* @param ListMapper $listMapper
*/
protected function configureListFields(ListMapper $listMapper): void
{
$listMapper->addIdentifier('id')
->add('question_ua', null, ['label' => 'Питання'])
->add('answer_ua', null, ['label' => 'Відповідь'])
->add('page', 'choice', ['label' => 'Тип', 'choices' => FaqModel::getPage()])
->add('_action', 'actions', array(
'label' => 'Действия',
'actions' => array(
'edit' => array(),
'delete' => array(),
)
));
}
}