<?php
namespace AdminBundle\Admin\References;
use AdminBundle\Admin\BaseAdmin;
use CoreBundle\Entity\User;
use CoreBundle\Model\Vehicles\EquipmentOptions;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Route\RouteCollectionInterface;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
class EquipmentOptionAdmin extends BaseAdmin
{
protected function configureRoutes(RouteCollectionInterface $collection): void
{
//$collection->remove('delete');
$collection->remove('view');
$collection->add('exportEquipmentOptions', 'export-options');
}
public function configureActionButtons(array $buttonList, string $action, $object = null): array
{
$list = parent::configureActionButtons($buttonList, $action, $object);
$list['export'] = [
'template' => '@AdminBundle/admin/export_equipment_options_button.html.twig',
];
return $list;
}
protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
{
$datagridMapper->add('id');
$datagridMapper->add('title_ru',null, ['label' => 'Название (RU)']);
$datagridMapper->add('title_ua',null, ['label' => 'Название (UA)']);
$datagridMapper->add('dealer',null, ['label' => 'Дилер']);
$datagridMapper->add('option_type', null, ['label' => 'Группа опций'], ChoiceType::class, [ 'choices' => array_flip(EquipmentOptions::getTypes())]);
}
public function configureQuery($context = 'list'): ProxyQueryInterface
{
$query = parent::configureQuery($context);
$query->orderBy($query->getRootAliases()[0] .'.sort','ASC');
return $query;
}
protected function configureFormFields(FormMapper $formMapper): void
{
/** @var User $User */
$User = $this->getUser();
$formMapper
->tab('Основная информация') // The tab call is optional
->with('Данные опции', ['class' => 'col-lg-4'])
->add('title_ru', null, ['label' => 'Название (ru)'])
->add('title_ua', null, ['label' => 'Название (ua)'])
->add('sort', null, ['label' => 'Сортировка'])
->add('option_type', ChoiceType::class, ['label' => 'Группа опций','choices' => array_flip(EquipmentOptions::getTypes())])
->add('has_value', ChoiceType::class, ['label' => 'Тип опции','choices' => array_flip([0 => 'Опция без значения',1 => 'Опция cо значением'])])
->end()
->end();
if($User->hasRole('ROLE_CONTENT_MANAGER') || $User->hasRole('ROLE_SUPER_ADMIN')) {
$formMapper
->tab('Основная информация') //
->with('Данные опции', ['class' => 'col-lg-4'])
->add('dealer', null, ['label' => 'Опция только для ДЦ'])
->end()
->end();
}
}
protected function configureListFields(ListMapper $listMapper): void
{
$listMapper->addIdentifier('id')
->add('sort',null, ['label' => 'Сорт.'])
->add('title_ru',null, ['label' => 'Название'])
->add('option_type','choice', ['label' => 'Группа опций', 'choices' => EquipmentOptions::getTypes(),'header_style' => 'width:210px;'])
->add('dealer', null, ['label' => 'Опция для дилера','header_style' => 'width:160px;'])
->add('_action', 'actions', [
'label' => 'Действия',
'header_style' => 'width:210px;',
'actions' => [
'edit' => [],
'delete' => [],
]
])
;
}
protected function configure(): void
{
parent::configure(); // TODO: Change the autogenerated stub
$this->setTemplate('list', '@Admin/CRUD/Equipment/equipment_options_list.html.twig');
}
}