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 action-delete', '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-outline-danger action-delete', ], 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->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); } public function configureFields(string $pageName): iterable { if (in_array(SeoInterface::class, class_implements($this->getEntityFqcn()))) { $seoPanel = [ FormField::addPanel('Seo'), TextareaField::new('metaTitle')->setLabel('Meta Title')->setHelp('Affiché dans les résultats de recherche Google'), TextareaField::new('metaDescription')->setLabel('Meta description')->setHelp('Affiché dans les résultats de recherche Google'), ]; } if (in_array(DevAliasInterface::class, class_implements($this->getEntityFqcn()))) { $confPanel = [ FormField::addPanel('Conf'), TextField::new('devAlias') ]; } return array_merge($seoPanel, $confPanel); } }