<?php
namespace AdminBundle\Admin\Vidi;
use FOS\CKEditorBundle\Form\Type\CKEditorType;
use PortalBundle\Entity\AnnouncementBar;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Route\RouteCollectionInterface;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
class AnnouncementBarAdmin extends AbstractAdmin
{
/**
* @param RouteCollectionInterface $collection
*/
protected function configureRoutes(RouteCollectionInterface $collection): void
{
$collection->remove('view');
$collection->remove('delete');
}
/**
* @param AnnouncementBar $object
*/
public function prePersist($object): void
{
$object->setState((int)$object->getState());
$this->updateObject($object);
}
/**
* @param $object
*/
public function preUpdate($object): void
{
$this->updateObject($object);
parent::preUpdate($object);
}
/**
* @param AnnouncementBar $object
*/
private function updateObject($object)
{
$object->setState((int)$object->getState());
}
/**
* @param FormMapper $formMapper
*/
protected function configureFormFields(FormMapper $formMapper): void
{
$formMapper
->tab('Анонс Бар')
->with('UA', ['class' => 'col-lg-6'])
->add('text_ua_mob', CKEditorType::class, ['label' => 'Текст моб'])
->add('text_ua_desktop', CKEditorType::class, ['label' => 'Текст десктоп',])
->add('url_ua', null, ['label' => 'URL'])
->end()
->with('RU', ['class' => 'col-lg-6'])
->add('text_ru_mob', CKEditorType::class, ['label' => 'Текст моб.',])
->add('text_ru_desktop', CKEditorType::class, ['label' => 'Текст десктоп',])
->add('url_ru', null, ['label' => 'URL'])
->end()
->add('state', CheckboxType::class, ['label' => 'Відображати на сайті', 'required' => false])
->end();
}
/**
* @param ListMapper $listMapper
*/
protected function configureListFields(ListMapper $listMapper): void
{
$listMapper->addIdentifier('id')
->add('text_ua_mob', null, ['label' => 'Текст моб.'])
->add('text_ua_desktop', null, ['label' => 'Текст десктоп'])
->add('state', 'choice', ['label' => 'Показувати на сайті', 'editable' => true, 'choices' => [
1 => 'Так',
0 => 'Ні',
]])
->add('_action', 'actions', [
'label' => 'Дії',
'actions' => [
'edit' => [],
]
]);
}
}