<?php
declare(strict_types=1);
namespace App\Nolimit\CashOutType\Admin;
use Sonata\AdminBundle\Admin\AbstractAdmin;
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 Sonata\AdminBundle\Show\ShowMapper;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
final class CashOutTypeAdmin extends AbstractAdmin
{
protected function configureDatagridFilters(DatagridMapper $filter): void
{
$filter
->add('name')
;
}
protected function configureListFields(ListMapper $list): void
{
$list
->add('name')
->add('value')
->add('fixed')
->add('cash_out_deletable')
->add(ListMapper::NAME_ACTIONS, null, [
'actions' => [
'show' => [],
'edit' => [],
'delete' => [],
'delete_log' => [
'template' => '/CRUD/logical_delete_with_condition.html.twig',
]
],
]);
}
protected function configureFormFields(FormMapper $form): void
{
$form
->add('name')
->add('value')
->add('fixed')
->add('cash_out_deletable')
->add('deleted',HiddenType::class, array('empty_data' => false))
->add('deletable',HiddenType::class, array('empty_data' => true))
;
}
protected function configureShowFields(ShowMapper $show): void
{
$show
->add('name')
->add('value')
->add('fixed')
->add('cash_out_deletable')
;
}
protected function configureRoutes(RouteCollectionInterface $collection): void
{
$collection
->remove('delete')
->add('delete_log', $this->getRouterIdParameter().'/delete_log');
}
protected function configureQuery(ProxyQueryInterface $query): ProxyQueryInterface
{
$query = parent::configureQuery($query);
$rootAlias = current($query->getRootAliases());
$query->andWhere(
$query->expr()->eq($rootAlias . '.deleted', ':type')
);
$query->setParameter(':type', '0');
return $query;
}
}