Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

94 lines
3.1KB

  1. <?php
  2. namespace Lc\SovBundle\Controller\Admin;
  3. use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
  4. use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
  5. use EasyCorp\Bundle\EasyAdminBundle\Config\Assets;
  6. use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
  7. use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController as EaAbstractCrudController;
  8. use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
  9. use Lc\SovBundle\Doctrine\Extension\TranslatableInterface;
  10. use Symfony\Component\HttpFoundation\RequestStack;
  11. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  12. abstract class AbstractCrudController extends EaAbstractCrudController
  13. {
  14. protected $session;
  15. protected $request;
  16. public function __construct(SessionInterface $session, RequestStack $request)
  17. {
  18. $this->session = $session;
  19. $this->request = $request;
  20. }
  21. public function configureActions(Actions $actions): Actions
  22. {
  23. /* Translatable */
  24. if (in_array(TranslatableInterface::class, class_implements($this->getEntityFqcn()))) {
  25. $actions->update(
  26. Crud::PAGE_INDEX,
  27. Action::EDIT,
  28. function (Action $action) {
  29. $action->setTemplatePath('@LcSov/adminlte/crud/action/translatable.html.twig');
  30. return $action;
  31. }
  32. );
  33. }
  34. /* Boutons des actions dans les listes */
  35. $listButtonsStyleArray = [
  36. Action::EDIT => [
  37. 'class' => 'btn btn-sm btn-primary',
  38. 'icon' => 'edit'
  39. ],
  40. Action::DELETE => [
  41. 'class' => 'btn btn-sm btn-default',
  42. 'icon' => 'trash'
  43. ]
  44. ];
  45. foreach($listButtonsStyleArray as $actionName => $button) {
  46. $actions->update(
  47. Crud::PAGE_INDEX,
  48. $actionName,
  49. function (Action $action) use ($button) {
  50. $action->setCssClass($button['class']);
  51. $action->setIcon('fa fa-'.$button['icon'])->setLabel(false);
  52. return $action;
  53. }
  54. );
  55. }
  56. return $actions;
  57. }
  58. public function configureCrud(Crud $crud): Crud
  59. {
  60. $crud = parent::configureCrud($crud);;
  61. $this->setMaxResults($crud);
  62. return $crud;
  63. }
  64. public function setMaxResults(Crud $crud)
  65. {
  66. $entityClass = $this->getEntityFqcn();
  67. $paramListMaxResults = 'listMaxResults';
  68. $paramSessionListMaxResults = $entityClass . '-' . $paramListMaxResults;
  69. $requestListMaxResults = $this->request->getCurrentRequest()->get($paramListMaxResults);
  70. if ($requestListMaxResults) {
  71. $this->session->set($paramSessionListMaxResults, $requestListMaxResults);
  72. }
  73. $maxResults = $this->session->get($paramSessionListMaxResults) ? $this->session->get(
  74. $paramSessionListMaxResults
  75. ) : 30;
  76. $crud->setPaginatorPageSize($maxResults);
  77. }
  78. }