|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
-
- namespace Lc\SovBundle\Controller\Admin;
-
- use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
- use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
- use EasyCorp\Bundle\EasyAdminBundle\Config\Assets;
- use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
- use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController as EaAbstractCrudController;
- use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
- use Lc\SovBundle\Doctrine\Extension\TranslatableInterface;
- use Symfony\Component\HttpFoundation\RequestStack;
- use Symfony\Component\HttpFoundation\Session\SessionInterface;
-
- abstract class AbstractCrudController extends EaAbstractCrudController
- {
- protected $session;
- protected $request;
-
- public function __construct(SessionInterface $session, RequestStack $request)
- {
- $this->session = $session;
- $this->request = $request;
- }
-
- public function configureActions(Actions $actions): Actions
- {
- /* Translatable */
- if (in_array(TranslatableInterface::class, class_implements($this->getEntityFqcn()))) {
- $actions->update(
- Crud::PAGE_INDEX,
- Action::EDIT,
- function (Action $action) {
- $action->setTemplatePath('@LcSov/adminlte/crud/action/translatable.html.twig');
- return $action;
- }
- );
- }
-
- /* Boutons des actions dans les listes */
- $listButtonsStyleArray = [
- Action::EDIT => [
- 'class' => 'btn btn-sm btn-primary',
- 'icon' => 'edit'
- ],
- Action::DELETE => [
- 'class' => 'btn btn-sm btn-default',
- 'icon' => 'trash'
- ]
- ];
-
- foreach($listButtonsStyleArray as $actionName => $button) {
- $actions->update(
- Crud::PAGE_INDEX,
- $actionName,
- function (Action $action) use ($button) {
- $action->setCssClass($button['class']);
- $action->setIcon('fa fa-'.$button['icon'])->setLabel(false);
- return $action;
- }
- );
- }
-
- return $actions;
- }
-
- public function configureCrud(Crud $crud): Crud
- {
- $crud = parent::configureCrud($crud);;
-
- $this->setMaxResults($crud);
-
- return $crud;
- }
-
- public function setMaxResults(Crud $crud)
- {
- $entityClass = $this->getEntityFqcn();
- $paramListMaxResults = 'listMaxResults';
- $paramSessionListMaxResults = $entityClass . '-' . $paramListMaxResults;
- $requestListMaxResults = $this->request->getCurrentRequest()->get($paramListMaxResults);
-
- if ($requestListMaxResults) {
- $this->session->set($paramSessionListMaxResults, $requestListMaxResults);
- }
- $maxResults = $this->session->get($paramSessionListMaxResults) ? $this->session->get(
- $paramSessionListMaxResults
- ) : 30;
-
- $crud->setPaginatorPageSize($maxResults);
- }
-
- }
|