|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749 |
- <?php
-
- namespace Lc\SovBundle\Controller;
-
- use Doctrine\ORM\EntityManagerInterface;
- use Doctrine\ORM\QueryBuilder;
- use EasyCorp\Bundle\EasyAdminBundle\Collection\ActionCollection;
- use EasyCorp\Bundle\EasyAdminBundle\Collection\EntityCollection;
- use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
- use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection;
- use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
- use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
- use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
- use EasyCorp\Bundle\EasyAdminBundle\Config\KeyValueStore;
- use EasyCorp\Bundle\EasyAdminBundle\Config\Option\EA;
- use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
- use EasyCorp\Bundle\EasyAdminBundle\Contracts\Controller\CrudControllerInterface;
- use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController as EaAbstractCrudController;
- use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
- use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto;
- use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto;
- use EasyCorp\Bundle\EasyAdminBundle\Event\AfterCrudActionEvent;
- use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityUpdatedEvent;
- use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeCrudActionEvent;
- use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityDeletedEvent;
- use EasyCorp\Bundle\EasyAdminBundle\Exception\ForbiddenActionException;
- use EasyCorp\Bundle\EasyAdminBundle\Exception\InsufficientEntityPermissionException;
- use EasyCorp\Bundle\EasyAdminBundle\Factory\ControllerFactory;
- use EasyCorp\Bundle\EasyAdminBundle\Factory\EntityFactory;
- use EasyCorp\Bundle\EasyAdminBundle\Factory\FilterFactory;
- use EasyCorp\Bundle\EasyAdminBundle\Factory\PaginatorFactory;
- use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
- use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
- use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
- use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
- use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
- use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
- use EasyCorp\Bundle\EasyAdminBundle\Security\Permission;
- use Lc\SovBundle\Component\EntityComponent;
- use Lc\SovBundle\Doctrine\Extension\DevAliasInterface;
- use Lc\SovBundle\Doctrine\Extension\SeoInterface;
- use Lc\SovBundle\Doctrine\Extension\SortableInterface;
- use Lc\SovBundle\Doctrine\Extension\TranslatableInterface;
- use Lc\SovBundle\Doctrine\Extension\TreeInterface;
- use Lc\SovBundle\Field\CollectionField;
- use Lc\SovBundle\Field\Filter\FilterManager;
- use Lc\SovBundle\Form\Common\FiltersFormType;
- use Lc\SovBundle\Form\Common\PositionType;
- use Lc\SovBundle\Translation\TranslatorAdmin;
- use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
- use Symfony\Component\Form\Extension\Core\Type\CollectionType;
- use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
- use Symfony\Component\Form\Extension\Core\Type\DateType;
- use Symfony\Component\Form\Extension\Core\Type\IntegerType;
- use Symfony\Component\Form\Extension\Core\Type\TextType;
- use Symfony\Component\HttpFoundation\JsonResponse;
- use Symfony\Component\HttpFoundation\RequestStack;
- use Symfony\Component\HttpFoundation\Session\SessionInterface;
-
-
- abstract class AbstractAdminController extends EaAbstractCrudController
- {
- protected $filtersForm;
-
- public static function getSubscribedServices()
- {
- return array_merge(
- parent::getSubscribedServices(),
- [
- 'session' => SessionInterface::class,
- 'request' => RequestStack::class,
- 'em' => EntityManagerInterface::class,
- 'translator_admin' => TranslatorAdmin::class,
- 'filter_manager' => FilterManager::class,
- ]
- );
- }
-
-
- public function configureResponseParameters(KeyValueStore $responseParameters): KeyValueStore
- {
- $this->overrideGlobalActions($responseParameters->get('global_actions'));
- $this->overrideEntitiesActions($responseParameters->get('entities'));
- if (Crud::PAGE_INDEX === $responseParameters->get('pageName')) {
- $responseParameters->set('fields', $this->configureFields('index'));
-
- if ($this->filtersForm === null) {
- die('nncncd');
- //TODO delete under code
- $options['fields'] = $responseParameters->get('fields');
- $options['entity_class'] = $this->getEntityFqcn();
- $options['entity_name'] = $responseParameters->get('entity')->getName();
- $this->filtersForm = $this->createForm(FiltersFormType::class, null, $options);
- }
- $responseParameters->set('filters_form', $this->filtersForm);
- }
-
- return $responseParameters;
- }
-
- public function overrideEntitiesActions(?EntityCollection $entities): void
- {
- }
-
- public function overrideGlobalActions(?ActionCollection $actions): void
- {
- if ($actions) {
- $context = $this->get(AdminContextProvider::class)->getContext();
- $adminUrlGenerator = $this->get(AdminUrlGenerator::class);
-
- foreach ($actions as $i => $action) {
- //récriture du bouton 'retour au parent'
- if ($action->getName() == 'index_parent') {
- $entity = $context->getEntity()->getInstance();
- if ($entity !== null) {
- if ($entity->getParent() !== null) {
- $url = $adminUrlGenerator
- ->setController($context->getCrud()->getControllerFqcn())
- ->set('entityId', $entity->getParent()->getId())
- ->generateUrl();
- $action->setLinkUrl($url);
- }
- } else {
- unset($actions[$i]);
- }
- }
-
- if ($action->getName() == 'sort') {
- $entityId = $context->getRequest()->get('entityId');
- if ($entityId != null) {
- $url = $adminUrlGenerator
- ->setController($context->getCrud()->getControllerFqcn())
- ->setAction($action->getName())
- ->set('entityId', $entityId)
- ->generateUrl();
- $action->setLinkUrl($url);
- }
- }
- }
- }
- }
-
- public function configureCrud(Crud $crud): Crud
- {
- $crud = parent::configureCrud($crud);
-
- $this->setMaxResults($crud);
-
- if ($this->isInstanceOf(SortableInterface::class)) {
- $crud->setDefaultSort(['position' => 'ASC']);
- }
-
- return $crud;
- }
-
- public function setMaxResults(Crud $crud): void
- {
- $entityClass = $this->getEntityFqcn();
- $paramListMaxResults = 'listMaxResults';
- $paramSessionListMaxResults = $entityClass.'-'.$paramListMaxResults;
- $requestListMaxResults = $this->get('request')->getCurrentRequest()->get($paramListMaxResults);
-
- if ($requestListMaxResults) {
- $this->get('session')->set($paramSessionListMaxResults, $requestListMaxResults);
- }
- $maxResults = $this->get('session')->get($paramSessionListMaxResults) ? $this->get('session')->get(
- $paramSessionListMaxResults
- ) : 30;
-
- $crud->setPaginatorPageSize($maxResults);
- }
-
- public function getSeoPanel(): ?array
- {
- if ($this->isInstanceOf(SeoInterface::class)) {
- return [
- FormField::addPanel('seo')->setTemplateName('crud/field/generic'),
- TextField::new('metaTitle')->setLabel('Meta Title')->setHelp(
- 'Affiché dans les résultats de recherche Google'
- )->hideOnIndex(),
- TextareaField::new('metaDescription')->setLabel('Meta description')->setHelp(
- 'Affiché dans les résultats de recherche Google'
- )->hideOnIndex(),
- CollectionField::new('oldUrls')
- ->setFormTypeOption('entry_type', TextType::class)->setLabel(
- 'Anciennes urls du document'
- )->hideOnIndex(),
- ];
- } else {
- return null;
- }
- }
-
- public function getConfPanel(): ?array
- {
- if ($this->isInstanceOf(DevAliasInterface::class)) {
- return [
- FormField::addPanel('configuration')->setTemplateName('crud/field/generic'),
- TextField::new('devAlias')->hideOnIndex(),
- ];
- } else {
- return null;
- }
- }
-
- public function sort(AdminContext $context)
- {
- $event = new BeforeCrudActionEvent($context);
- $this->get('event_dispatcher')->dispatch($event);
- if ($event->isPropagationStopped()) {
- return $event->getResponse();
- }
-
- //if (!$this->isGranted(Permission::EA_EXECUTE_ACTION) || !$this->isInstanceOf(SortableInterface::class)) {
- if (!$this->isInstanceOf(SortableInterface::class)) {
- throw new ForbiddenActionException($context);
- }
-
- $fields = FieldCollection::new($this->configureFields(Crud::PAGE_INDEX));
- $filters = $this->get(FilterFactory::class)->create(
- $context->getCrud()->getFiltersConfig(),
- $fields,
- $context->getEntity()
- );
- $queryBuilder = $this->createIndexQueryBuilder($context->getSearch(), $context->getEntity(), $fields, $filters);
- $paginator = $this->get(PaginatorFactory::class)->create($queryBuilder);
-
- $entities = $this->get(EntityFactory::class)->createCollection($context->getEntity(), $paginator->getResults());
- $this->get(EntityFactory::class)->processFieldsForAll($entities, $fields);
-
- $sortableForm = $this->createFormBuilder(array('entities', $paginator->getResults()))
- ->add(
- 'entities',
- CollectionType::class,
- array(
- 'required' => true,
- 'allow_add' => true,
- 'entry_type' => PositionType::class,
- )
- )
- ->getForm();
-
- $entityManager = $this->getDoctrine()->getManagerForClass($this->getEntityFqcn());
- $repository = $entityManager->getRepository($this->getEntityFqcn());
-
- $sortableForm->handleRequest($context->getRequest());
-
- if ($sortableForm->isSubmitted() && $sortableForm->isValid()) {
- foreach ($sortableForm->get('entities')->getData() as $elm) {
- $entityInstance = $repository->find($elm['id']);
- $entityDto = $context->getEntity()->newWithInstance($entityInstance);
-
- if (!$entityDto->isAccessible()) {
- throw new InsufficientEntityPermissionException($context);
- }
-
- $event = new BeforeEntityDeletedEvent($entityInstance);
- $this->get('event_dispatcher')->dispatch($event);
- $entityInstance = $event->getEntityInstance();
-
- $entityInstance->setPosition($elm['position']);
- $this->updateEntity($entityManager, $entityInstance);
-
- $this->get('event_dispatcher')->dispatch(new AfterEntityUpdatedEvent($entityInstance));
- }
-
- $url = $this->get(AdminUrlGenerator::class)
- ->setAction(Action::INDEX)
- ->generateUrl();
- $this->addFlash('success', $this->translatorAdmin->transFlashMessage('sort'), array());
-
- return $this->redirect($url);
- }
-
- $responseParameters = $this->configureResponseParameters(
- KeyValueStore::new(
- [
- 'pageName' => Crud::PAGE_INDEX,
- 'templatePath' => '@LcSov/adminlte/crud/sort.html.twig',
- 'entities' => $entities,
- 'paginator' => $paginator,
- 'global_actions' => array(),
- 'batch_actions' => array(),
- 'filters' => $filters,
- 'sortable_form' => $sortableForm,
- ]
- )
- );
- $responseParameters->set('fields', $this->configureFields('index'));
- $event = new AfterCrudActionEvent($context, $responseParameters);
- $this->get('event_dispatcher')->dispatch($event);
- if ($event->isPropagationStopped()) {
- return $event->getResponse();
- }
-
- return $responseParameters;
- }
-
- public function duplicate(AdminContext $context, EntityComponent $entityComponent, TranslatorAdmin $translatorAdmin, EntityManagerInterface $em)
- {
-
- if (!$this->isGranted(
- Permission::EA_EXECUTE_ACTION,
- ['action' => "duplicate", 'entity' => $context->getEntity()]
- )) {
- throw new ForbiddenActionException($context);
- }
-
- if (!$context->getEntity()->isAccessible()) {
- throw new InsufficientEntityPermissionException($context);
- }
-
- $newEntity = $entityComponent->duplicateEntity($context->getEntity()->getInstance());
- $em->create($newEntity);
- $em->flush();
-
- $url = $this->get(AdminUrlGenerator::class)
- ->setAction(Action::EDIT)
- ->setEntityId($newEntity->getId())
- ->generateUrl();
-
- $this->addFlash('success', $translatorAdmin->transFlashMessage('duplicate'), array());
-
- return $this->redirect($url);
- }
-
-
- public function createIndexQueryBuilder(
- SearchDto $searchDto,
- EntityDto $entityDto,
- FieldCollection $fields,
- FilterCollection $filters
- ): QueryBuilder {
- $queryBuilder = parent::createIndexQueryBuilder(
- $searchDto,
- $entityDto,
- $fields,
- $filters
- );
-
- //TOdo utiliser les repositoryQuery ?
- if ($this->isInstanceOf(TreeInterface::class)) {
- $entityId = $searchDto->getRequest()->get('entityId');
- if ($entityId !== null) {
- $queryBuilder->andWhereParent('entity', $entityId);
- } else {
- $queryBuilder->andWhereParentIsNull('entity');
- }
- }
-
- $this->filtersForm = $this->createForm(
- FiltersFormType::class,
- null,
- array(
- 'fields' => $fields,
- 'entity_dto' => $entityDto,
- 'entity_class' => $this->getEntityFqcn(),
- 'entity_name' => $entityDto->getName(),
- )
- );
-
- $filterManager = $this->get('filter_manager');
-
- $this->filtersForm->handleRequest($searchDto->getRequest());
- /*if (($this->filtersForm->isSubmitted() && $this->filtersForm->isValid())) {
-
- }*/
- $filterManager->handleFiltersForm($queryBuilder, $this->filtersForm, $fields, $entityDto);
-
-
- return $queryBuilder;
- }
-
- public function createSortQueryBuilder(
- SearchDto $searchDto,
- EntityDto $entityDto,
- FieldCollection $fields,
- FilterCollection $filters
- ): QueryBuilder {
- $queryBuilder = $this->createIndexQueryBuilder($searchDto, $entityDto, $fields, $filters);
-
- return $queryBuilder;
- }
-
- public function edit(AdminContext $context)
- {
- $response = parent::edit($context);;
-
- // on vide le flash bag si édition en ajax (notification déjà affichée en Javascript)
- if ($context->getRequest()->isXmlHttpRequest()) {
- $this->get('session')->getFlashBag()->clear();
- }
-
- return $response;
- }
-
- public function isInstanceOf(string $interfaceName): bool
- {
- return in_array($interfaceName, class_implements($this->getEntityFqcn()));
- }
-
- public function getControllerFqcnByInterface(string $interface): string
- {
- $context = $this->get(AdminContextProvider::class)->getContext();
-
- return $context->getCrudControllers()->findCrudFqcnByEntityFqcn(
- $this->get('em')->getEntityName($interface)
- );
- }
-
- public function updateEntity(EntityManagerInterface $entityManager, $entityInstance): void
- {
- $entityManager->update($entityInstance);
- $entityManager->flush();
- }
-
- public function persistEntity(EntityManagerInterface $entityManager, $entityInstance): void
- {
- $entityManager->create($entityInstance);
- $entityManager->flush();
- }
-
-
- public function configureActions(Actions $actions): Actions
- {
- $this->buildIndexActions($actions);
- $this->buildEditActions($actions);
- $this->buildDetailActions($actions);
- $this->buildNewActions($actions);
- $this->handleTranslatableEntityActions($actions);
- $this->handleSortableEntityActions($actions);
- $this->handleTreeEntityActions($actions);
-
- /*$actions->reorder(Crud::PAGE_EDIT, [Action::INDEX, Action::SAVE_AND_RETURN, Action::SAVE_AND_CONTINUE, Action::DELETE]);
- $actions->reorder(Crud::PAGE_NEW, [Action::INDEX, Action::SAVE_AND_RETURN, Action::SAVE_AND_ADD_ANOTHER]);*/
-
- return $actions;
- }
-
- public function getDuplicateAction(): Action
- {
- $duplicateAction = Action::new(
- 'duplicate',
- $this->get('translator_admin')->transAction('duplicate'),
- 'fa fa-fw fa-copy'
- )
- ->linkToCrudAction('duplicate')
- ->setLabel($this->get('translator_admin')->transAction('duplicate'))
- ->setCssClass('in-dropdown text-info action-confirm');
-
- return $duplicateAction;
- }
-
- public function buildIndexActions(Actions $actions): void
- {
- $actions->add(Crud::PAGE_INDEX, $this->getDuplicateAction());
-
- $this->actionUpdate(
- $actions,
- Crud::PAGE_INDEX,
- Action::NEW,
- [
- 'icon' => 'plus',
- 'label' => $this->get('translator_admin')->transAction('create'),
- 'add_class' => 'btn-sm',
- ]
- );
-
- $this->actionUpdate(
- $actions,
- Crud::PAGE_INDEX,
- Action::EDIT,
- [
- 'class' => 'btn btn-sm btn-primary',
- 'icon' => 'edit',
- 'label' => false,
- 'html_attributes' => array(
- 'data-toggle' => 'tooltip',
- 'title' => $this->get('translator_admin')->transAction('edit'),
- ),
- ]
- );
-
- $this->actionUpdate(
- $actions,
- Crud::PAGE_INDEX,
- Action::DETAIL,
- [
- 'icon' => 'eye',
- 'add_class' => 'btn btn-sm btn-success',
- 'label' => false,
- 'html_attributes' => array(
- 'data-toggle' => 'tooltip',
- 'title' => $this->get('translator_admin')->transAction('detail'),
- ),
- ]
- );
-
- $this->actionUpdate(
- $actions,
- Crud::PAGE_INDEX,
- Action::DELETE,
- [
- 'icon' => 'trash',
- 'dropdown' => true,
- 'label' => $this->get('translator_admin')->transAction('delete'),
- ]
- );
-
- $this->actionUpdate(
- $actions,
- Crud::PAGE_INDEX,
- Action::BATCH_DELETE,
- [
- 'class' => 'btn btn-sm btn-danger',
- 'icon' => 'trash',
- 'label' => $this->get('translator_admin')->transAction('delete'),
- ]
- );
- }
-
-
- public function buildEditActions(Actions $actions): void
- {
- $actions->add(Crud::PAGE_EDIT, Action::INDEX);
- $actions->add(Crud::PAGE_EDIT, Action::DELETE);
-
-
- $this->actionUpdate(
- $actions,
- Crud::PAGE_EDIT,
- Action::SAVE_AND_RETURN,
- [
- 'add_class' => 'float-right',
- 'icon' => 'check',
- 'label' => $this->get('translator_admin')->transAction('save_and_return'),
- ]
- );
-
- $this->actionUpdate(
- $actions,
- Crud::PAGE_EDIT,
- Action::INDEX,
- [
- 'icon' => 'chevron-left',
- 'class' => 'btn btn-link',
- 'label' => $this->get('translator_admin')->transAction('back_index'),
- ]
- );
-
-
- $this->actionUpdate(
- $actions,
- Crud::PAGE_EDIT,
- Action::SAVE_AND_CONTINUE,
- [
- 'class' => 'btn btn-info float-right',
- 'label' => $this->get('translator_admin')->transAction('save_and_continue'),
- ]
- );
-
- $this->actionUpdate(
- $actions,
- Crud::PAGE_EDIT,
- Action::DELETE,
- [
- 'icon' => 'trash',
- 'class' => 'btn btn-outline-danger action-delete',
- 'label' => $this->get('translator_admin')->transAction('delete'),
- ]
- );
- }
-
- public function buildDetailActions(Actions $actions): void
- {
- }
-
- public function buildNewActions(Actions $actions): void
- {
- $actions->add(Crud::PAGE_NEW, Action::INDEX);
-
- $this->actionUpdate(
- $actions,
- Crud::PAGE_EDIT,
- Action::SAVE_AND_RETURN,
- [
- 'add_class' => 'float-right',
- 'icon' => 'check',
- 'label' => $this->get('translator_admin')->transAction('save_and_return'),
- ]
- );
-
- $this->actionUpdate(
- $actions,
- Crud::PAGE_EDIT,
- Action::INDEX,
- [
- 'icon' => 'chevron-left',
- 'class' => 'btn btn-link',
- 'label' => $this->get('translator_admin')->transAction('back_index'),
- ]
- );
-
- $this->actionUpdate(
- $actions,
- Crud::PAGE_EDIT,
- Action::SAVE_AND_ADD_ANOTHER,
- [
- 'class' => 'btn btn-info float-right',
- 'label' => $this->get('translator_admin')->transAction('save_and_add_another'),
- ]
- );
- }
-
- public function handleTranslatableEntityActions(Actions $actions): void
- {
- if ($this->isInstanceOf(TranslatableInterface::class)) {
- $actions->update(
- Crud::PAGE_INDEX,
- Action::EDIT,
- function (Action $action) {
- $action->setTemplatePath('@LcSov/adminlte/crud/action/translatable.html.twig');
-
- return $action;
- }
- );
- }
- }
-
- public function handleSortableEntityActions(Actions $actions): void
- {
- if ($this->isInstanceOf(SortableInterface::class)) {
- $sortAction = Action::new('sort', $this->get('translator_admin')->transAction('sort'), 'fa fa-sort')
- ->linkToCrudAction('sort')
- ->setCssClass('btn btn-sm btn-success')
- ->createAsGlobalAction();
-
- $actions->add(Crud::PAGE_INDEX, $sortAction);
- }
- }
-
-
- public function handleTreeEntityActions(Actions $actions): void
- {
- if ($this->isInstanceOf(TreeInterface::class)) {
- $indexChildAction = Action::new(
- 'index_children',
- $this->get('translator_admin')->transAction('index_children'),
- 'fa fa-list'
- )
- ->linkToCrudAction(Action::INDEX)
- ->setLabel('')
- ->setHtmlAttributes(array('data-toggle' => 'tooltip', 'title' => 'Afficher les enfants'))
- ->setTemplatePath('@LcSov/adminlte/crud/action/index_children.html.twig')
- ->setCssClass('btn btn-sm btn-success');
-
- $backParentAction = Action::new(
- 'index_parent',
- $this->get('translator_admin')->transAction('index_parent'),
- 'fa fa-chevron-left'
- )
- ->linkToCrudAction(Action::INDEX)
- ->setCssClass('btn btn-sm btn-info')
- ->createAsGlobalAction();
-
- $actions->add(Crud::PAGE_INDEX, $backParentAction);
- $actions->add(Crud::PAGE_INDEX, $indexChildAction);
- }
- }
-
- public function actionUpdate($actions, $crudActionName, $actionName, array $button): void
- {
- if ($actions->getAsDto('actions')->getAction($crudActionName, $actionName)) {
- $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']);
- }
-
- if (isset($button['dropdown']) && $button['dropdown']) {
- $action->addCssClass('in-dropdown');
- }
-
- if (isset($button['html_attributes']) && $button['html_attributes']) {
- $action->setHtmlAttributes($button['html_attributes']);
- }
-
- return $action;
- }
- );
- }
- }
-
- public function autocompleteFilter(AdminContext $context): JsonResponse
- {
- $queryBuilder = $this->createIndexQueryBuilder(
- $context->getSearch(),
- $context->getEntity(),
- FieldCollection::new([]),
- FilterCollection::new()
- );
- $autocompleteContext = $context->getRequest()->get(AssociationField::PARAM_AUTOCOMPLETE_CONTEXT);
-
- /** @var CrudControllerInterface $controller */
- $controller = $this->get(ControllerFactory::class)->getCrudControllerInstance(
- $autocompleteContext[EA::CRUD_CONTROLLER_FQCN],
- Action::INDEX,
- $context->getRequest()
- );
- /** @var FieldDto $field */
- $field = FieldCollection::new(
- $controller->configureFields($autocompleteContext['originatingPage'])
- )->getByProperty($autocompleteContext['propertyName']);
-
- $filterManager = $this->get('filter_manager');
-
- $filterManager->applyFilter($queryBuilder, $field, $context->getRequest()->query->get('q'));
- if ($filterManager->isRelationField($field->getProperty())) {
- $queryBuilder->select($autocompleteContext['propertyName']);
- } else {
- $queryBuilder->select('entity.'.$autocompleteContext['propertyName']);
- }
-
- $responses = array();
- foreach ($queryBuilder->getQuery()->getArrayResult() as $result) {
- $responses[] = array_values($result)[0];
- }
-
-
- return JsonResponse::fromJsonString(json_encode($responses));
- }
-
-
- }
-
|