src/Nolimit/CashInType/Admin/CashInTypeAdmin.php line 16

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Nolimit\CashInType\Admin;
  4. use Sonata\AdminBundle\Admin\AbstractAdmin;
  5. use Sonata\AdminBundle\Datagrid\DatagridMapper;
  6. use Sonata\AdminBundle\Datagrid\ListMapper;
  7. use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
  8. use Sonata\AdminBundle\Form\FormMapper;
  9. use Sonata\AdminBundle\Route\RouteCollectionInterface;
  10. use Sonata\AdminBundle\Show\ShowMapper;
  11. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  12. final class CashInTypeAdmin extends AbstractAdmin
  13. {
  14.     protected function configureDatagridFilters(DatagridMapper $filter): void
  15.     {
  16.         $filter
  17.             ->add('name')
  18.         ;
  19.     }
  20.     protected function configureListFields(ListMapper $list): void
  21.     {
  22.         $list
  23.             ->add('name')
  24.         //    ->add('deletable', null, [
  25.         //        'template' => '/CRUD/custom_row_template.html.twig', // specify your custom template here
  26.         //    ]);
  27.             ->add(ListMapper::NAME_ACTIONSnull, [
  28.                 'actions' => [
  29.                     'show' => [],
  30.                     'edit' => [],
  31.                     'delete' => [],
  32.                     'delete_log' => [
  33.                         'template' => '/CRUD/logical_delete_with_condition.html.twig',
  34.                     ]
  35.                 ],
  36.             ])
  37.         ;
  38.     }
  39.     protected function configureFormFields(FormMapper $form): void
  40.     {
  41.         $form
  42.             ->add('name')
  43.             ->add('deleted',HiddenType::class, array('empty_data' => false))
  44.             ->add('deletable',HiddenType::class, array('empty_data' => true))
  45.         ;
  46.     }
  47.     protected function configureShowFields(ShowMapper $show): void
  48.     {
  49.         $show
  50.             ->add('name')
  51.         ;
  52.     }
  53.     protected function configureRoutes(RouteCollectionInterface $collection): void
  54.     {
  55.         $collection
  56.         ->remove('delete')
  57.         ->add('delete_log'$this->getRouterIdParameter().'/delete_log');
  58.     }
  59.     protected function configureQuery(ProxyQueryInterface $query): ProxyQueryInterface
  60.     {
  61.         $query parent::configureQuery($query);
  62.         $rootAlias current($query->getRootAliases());
  63.         $query->andWhere(
  64.             $query->expr()->eq($rootAlias '.deleted'':type')
  65.         );
  66.         $query->setParameter(':type''0');
  67.         return $query;
  68.     }
  69. }