|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?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;
- }
- );
- }
-
- $actionSaveAndReturn = [
- 'add-class' => 'float-right',
- 'icon' => 'check',
- ];
- $actionIndex = [
- 'icon' => 'chevron-left',
- 'class' => 'btn btn-link',
- ];
-
- /* Boutons des actions dans les listes */
- $actionsArray[Crud::PAGE_INDEX] = [
- Action::EDIT => [
- 'class' => 'btn btn-sm btn-primary',
- 'icon' => 'edit',
- 'label' => false,
- ],
- Action::DELETE => [
- 'class' => 'btn btn-sm btn-default',
- 'icon' => 'trash',
- 'label' => false,
- ],
- ];
-
- /* Boutons des actions dans l'édition */
- $actionsArray[Crud::PAGE_EDIT] = [
- Action::SAVE_AND_CONTINUE => [
- 'class' => 'btn btn-info float-right',
- ],
- Action::DELETE => [
- 'icon' => 'trash',
- 'class' => 'btn btn-link text-danger',
- ],
- Action::SAVE_AND_RETURN => $actionSaveAndReturn,
- Action::INDEX=>$actionIndex
- ];
- $actionsArray[Crud::PAGE_NEW] = [
- Action::SAVE_AND_ADD_ANOTHER => [
- 'class' => 'btn btn-info float-right',
- ],
- Action::SAVE_AND_RETURN => $actionSaveAndReturn,
- Action::INDEX=>$actionIndex
- ];
-
- $actions->add(Crud::PAGE_EDIT, Action::INDEX);
- $actions->add(Crud::PAGE_EDIT, Action::DELETE);
- $actions->add(Crud::PAGE_NEW, Action::INDEX);
- $actions->add(Crud::PAGE_NEW, Action::DELETE);
-
- $actions->reorder(Crud::PAGE_EDIT, [Action::INDEX, Action::SAVE_AND_RETURN, Action::SAVE_AND_CONTINUE]);
- $actions->reorder(Crud::PAGE_NEW, [Action::INDEX, Action::SAVE_AND_RETURN, Action::SAVE_AND_ADD_ANOTHER]);
-
-
- foreach ($actionsArray as $crudActionName => $actionsStyle) {
- foreach ($actionsStyle as $actionName => $button) {
- $actions->update(
- $crudActionName,
- $actionName,
- function (Action $action) use ($button) {
- if (isset($button['add-class'])) {
- $action->addCssClass($button['add-class']);
- }
- if (isset($button['class'])) {
- $action->setCssClass($button['class']);
- }
- if (isset($button['icon'])) {
- $action->setIcon('fa fa-'.$button['icon']);
- }
- if (isset($button['label'])) {
- $action->setLabel($button['label']);
- }
-
-
- 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);
- }
-
- }
|