Browse Source

Merge branch 'develop' of https://forge.laclic.fr/Laclic/SovBundle into develop

feature/symfony6.1
Guillaume 3 years ago
parent
commit
1bba69ea4f
1 changed files with 250 additions and 244 deletions
  1. +250
    -244
      Controller/AbstractAdminController.php

+ 250
- 244
Controller/AbstractAdminController.php View File

if ($entity !== null) { if ($entity !== null) {
if ($entity->getParent() !== null) { if ($entity->getParent() !== null) {
$url = $adminUrlGenerator $url = $adminUrlGenerator
->setController($context->getCrud()->getControllerFqcn())
->set('entityId', $entity->getParent()->getId())
->generateUrl();
->setController($context->getCrud()->getControllerFqcn())
->set('entityId', $entity->getParent()->getId())
->generateUrl();
$action->setLinkUrl($url); $action->setLinkUrl($url);
} }
} else { } else {
$entityId = $context->getRequest()->get('entityId'); $entityId = $context->getRequest()->get('entityId');
if ($entityId != null) { if ($entityId != null) {
$url = $adminUrlGenerator $url = $adminUrlGenerator
->setController($context->getCrud()->getControllerFqcn())
->setAction($action->getName())
->set('entityId', $entityId)
->generateUrl();
->setController($context->getCrud()->getControllerFqcn())
->setAction($action->getName())
->set('entityId', $entityId)
->generateUrl();
$action->setLinkUrl($url); $action->setLinkUrl($url);
} }
} }


if ($this->isInstanceOf(SortableInterface::class)) { if ($this->isInstanceOf(SortableInterface::class)) {
$crud->setDefaultSort(['position' => 'ASC']); $crud->setDefaultSort(['position' => 'ASC']);
}
else {
} else {
$crud->setDefaultSort(['id' => 'DESC']); $crud->setDefaultSort(['id' => 'DESC']);
} }


$this->get('session')->set($paramSessionListMaxResults, $requestListMaxResults); $this->get('session')->set($paramSessionListMaxResults, $requestListMaxResults);
} }
$maxResults = $this->get('session')->get($paramSessionListMaxResults) ? $this->get('session')->get( $maxResults = $this->get('session')->get($paramSessionListMaxResults) ? $this->get('session')->get(
$paramSessionListMaxResults
$paramSessionListMaxResults
) : 30; ) : 30;


$crud->setPaginatorPageSize($maxResults); $crud->setPaginatorPageSize($maxResults);
{ {
if ($this->isInstanceOf(SeoInterface::class)) { if ($this->isInstanceOf(SeoInterface::class)) {
return [ 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'
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(), )->hideOnIndex(),
CollectionField::new('oldUrls')
->setFormTypeOption('entry_type', TextType::class)->setLabel(
'Anciennes urls du document'
)->hideOnIndex(),
]; ];
} else { } else {
return null; return null;
{ {
if ($this->isInstanceOf(DevAliasInterface::class)) { if ($this->isInstanceOf(DevAliasInterface::class)) {
return [ return [
FormField::addPanel('configuration')->setTemplateName('crud/field/generic'),
TextField::new('devAlias')->hideOnIndex(),
FormField::addPanel('configuration')->setTemplateName('crud/field/generic'),
TextField::new('devAlias')->hideOnIndex(),
]; ];
} else { } else {
return null; return null;


$fields = FieldCollection::new($this->configureFields(Crud::PAGE_INDEX)); $fields = FieldCollection::new($this->configureFields(Crud::PAGE_INDEX));
$filters = $this->get(FilterFactory::class)->create( $filters = $this->get(FilterFactory::class)->create(
$context->getCrud()->getFiltersConfig(),
$fields,
$context->getEntity()
$context->getCrud()->getFiltersConfig(),
$fields,
$context->getEntity()
); );
$queryBuilder = $this->createIndexQueryBuilder($context->getSearch(), $context->getEntity(), $fields, $filters); $queryBuilder = $this->createIndexQueryBuilder($context->getSearch(), $context->getEntity(), $fields, $filters);
$paginator = $this->get(PaginatorFactory::class)->create($queryBuilder); $paginator = $this->get(PaginatorFactory::class)->create($queryBuilder);
$this->get(EntityFactory::class)->processFieldsForAll($entities, $fields); $this->get(EntityFactory::class)->processFieldsForAll($entities, $fields);


$sortableForm = $this->createFormBuilder(array('entities', $paginator->getResults())) $sortableForm = $this->createFormBuilder(array('entities', $paginator->getResults()))
->add(
'entities',
CollectionType::class,
array(
'required' => true,
'allow_add' => true,
'entry_type' => PositionType::class,
)
->add(
'entities',
CollectionType::class,
array(
'required' => true,
'allow_add' => true,
'entry_type' => PositionType::class,
) )
->getForm();
)
->getForm();


$entityManager = $this->getDoctrine()->getManagerForClass($this->getEntityFqcn()); $entityManager = $this->getDoctrine()->getManagerForClass($this->getEntityFqcn());
$repository = $entityManager->getRepository($this->getEntityFqcn()); $repository = $entityManager->getRepository($this->getEntityFqcn());
} }


$url = $this->get(AdminUrlGenerator::class) $url = $this->get(AdminUrlGenerator::class)
->setAction(ActionDefinition::INDEX)
->generateUrl();
->setAction(ActionDefinition::INDEX)
->generateUrl();
$this->addFlashTranslator('success', 'sorted'); $this->addFlashTranslator('success', 'sorted');


return $this->redirect($url); return $this->redirect($url);
} }


$responseParameters = $this->configureResponseParameters( $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,
]
)
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')); $responseParameters->set('fields', $this->configureFields('index'));
$event = new AfterCrudActionEvent($context, $responseParameters); $event = new AfterCrudActionEvent($context, $responseParameters);
} }


public function duplicate( public function duplicate(
AdminContext $context,
EntityComponent $entityComponent,
TranslatorAdmin $translatorAdmin,
EntityManagerInterface $em
AdminContext $context,
EntityComponent $entityComponent,
TranslatorAdmin $translatorAdmin,
EntityManagerInterface $em
) { ) {
if (!$this->isGranted( if (!$this->isGranted(
Permission::EA_EXECUTE_ACTION,
['action' => "duplicate", 'entity' => $context->getEntity()]
Permission::EA_EXECUTE_ACTION,
['action' => "duplicate", 'entity' => $context->getEntity()]
)) { )) {
throw new ForbiddenActionException($context); throw new ForbiddenActionException($context);
} }
$em->flush(); $em->flush();


$url = $this->get(AdminUrlGenerator::class) $url = $this->get(AdminUrlGenerator::class)
->setAction(ActionDefinition::EDIT)
->setEntityId($newEntity->getId())
->generateUrl();
->setAction(ActionDefinition::EDIT)
->setEntityId($newEntity->getId())
->generateUrl();


$this->addFlashTranslator('success', 'duplicated'); $this->addFlashTranslator('success', 'duplicated');


EntityDto $entityDto, EntityDto $entityDto,
FieldCollection $fields, FieldCollection $fields,
FilterCollection $filters FilterCollection $filters
): RepositoryQueryInterface
{
$repositoryQuery = $this->get(EntityRepository::class)->createRepositoryQuery($this->getRepositoryQuery(), $searchDto, $entityDto, $fields, $filters);
): RepositoryQueryInterface {
$repositoryQuery = $this->get(EntityRepository::class)->createRepositoryQuery(
$this->getRepositoryQuery(),
$searchDto,
$entityDto,
$fields,
$filters
);


// TODO : déplacer dans EntotyRepository // TODO : déplacer dans EntotyRepository
if ($this->isInstanceOf(TreeInterface::class)) { if ($this->isInstanceOf(TreeInterface::class)) {
return $repositoryQuery; return $repositoryQuery;
} }


public function createIndexQueryBuilder(
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
FilterCollection $filters
): QueryBuilder {

$repositoryQuery = $this->createIndexRepositoryQuery($searchDto, $entityDto, $fields, $filters);
return $repositoryQuery->getQueryBuilder();
public function createIndexQueryBuilder(
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
FilterCollection $filters
): QueryBuilder {
$repositoryQuery = $this->createIndexRepositoryQuery($searchDto, $entityDto, $fields, $filters);
return $repositoryQuery->getQueryBuilder();
} }


public function createSortQueryBuilder( public function createSortQueryBuilder(
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
FilterCollection $filters
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
FilterCollection $filters
): QueryBuilder { ): QueryBuilder {
$queryBuilder = $this->createIndexQueryBuilder($searchDto, $entityDto, $fields, $filters); $queryBuilder = $this->createIndexQueryBuilder($searchDto, $entityDto, $fields, $filters);


$context = $this->get(AdminContextProvider::class)->getContext(); $context = $this->get(AdminContextProvider::class)->getContext();


return $context->getCrudControllers()->findCrudFqcnByEntityFqcn( return $context->getCrudControllers()->findCrudFqcnByEntityFqcn(
$this->get(EntityManagerInterface::class)->getEntityName($interface)
$this->get(EntityManagerInterface::class)->getEntityName($interface)
); );
} }


$entityManager->delete($entityInstance); $entityManager->delete($entityInstance);
$entityManager->flush(); $entityManager->flush();
$this->get(FlashBagTranslator::class)->add('success', 'deleted', $this->getTranslationEntityName()); $this->get(FlashBagTranslator::class)->add('success', 'deleted', $this->getTranslationEntityName());

} }


public function configureActions(Actions $actions): Actions public function configureActions(Actions $actions): Actions
public function getDuplicateAction(): Action public function getDuplicateAction(): Action
{ {
$duplicateAction = Action::new( $duplicateAction = Action::new(
ActionDefinition::DUPLICATE,
$this->get(TranslatorAdmin::class)->transAction(ActionDefinition::DUPLICATE),
'fa fa-fw fa-copy'
ActionDefinition::DUPLICATE,
$this->get(TranslatorAdmin::class)->transAction(ActionDefinition::DUPLICATE),
'fa fa-fw fa-copy'
) )
->linkToCrudAction(ActionDefinition::DUPLICATE)
->setLabel($this->get(TranslatorAdmin::class)->transAction(ActionDefinition::DUPLICATE))
->setCssClass('in-dropdown text-info action-confirm');
->linkToCrudAction(ActionDefinition::DUPLICATE)
->setLabel($this->get(TranslatorAdmin::class)->transAction(ActionDefinition::DUPLICATE))
->setCssClass('in-dropdown text-info action-confirm');


return $duplicateAction; return $duplicateAction;
} }
$actions->add(Crud::PAGE_INDEX, $this->getDuplicateAction()); $actions->add(Crud::PAGE_INDEX, $this->getDuplicateAction());


$this->actionUpdate( $this->actionUpdate(
$actions,
Crud::PAGE_INDEX,
ActionDefinition::NEW,
[
'icon' => 'plus',
'label' => $this->get(TranslatorAdmin::class)->transAction('create'),
'add_class' => 'btn-sm',
]
$actions,
Crud::PAGE_INDEX,
ActionDefinition::NEW,
[
'icon' => 'plus',
'label' => $this->get(TranslatorAdmin::class)->transAction('create'),
'add_class' => 'btn-sm',
]
); );


$this->actionUpdate( $this->actionUpdate(
$actions,
Crud::PAGE_INDEX,
ActionDefinition::EDIT,
[
'class' => 'btn btn-sm btn-primary',
'icon' => 'edit',
'label' => false,
'html_attributes' => array(
'data-toggle' => 'tooltip',
'title' => $this->get(TranslatorAdmin::class)->transAction('edit'),
),
]
$actions,
Crud::PAGE_INDEX,
ActionDefinition::EDIT,
[
'class' => 'btn btn-sm btn-primary',
'icon' => 'edit',
'label' => false,
'html_attributes' => array(
'data-toggle' => 'tooltip',
'title' => $this->get(TranslatorAdmin::class)->transAction('edit'),
),
]
); );


$this->actionUpdate( $this->actionUpdate(
$actions,
Crud::PAGE_INDEX,
ActionDefinition::DETAIL,
[
'icon' => 'eye',
'add_class' => 'btn btn-sm btn-success',
'label' => false,
'html_attributes' => array(
'data-toggle' => 'tooltip',
'title' => $this->get(TranslatorAdmin::class)->transAction('detail'),
),
]
$actions,
Crud::PAGE_INDEX,
ActionDefinition::DETAIL,
[
'icon' => 'eye',
'add_class' => 'btn btn-sm btn-success',
'label' => false,
'html_attributes' => array(
'data-toggle' => 'tooltip',
'title' => $this->get(TranslatorAdmin::class)->transAction('detail'),
),
]
); );


$this->actionUpdate( $this->actionUpdate(
$actions,
Crud::PAGE_INDEX,
ActionDefinition::DELETE,
[
'icon' => 'trash',
'dropdown' => true,
'label' => $this->get(TranslatorAdmin::class)->transAction('delete'),
'class' => 'dropdown-item text-danger in-dropdown action-delete',
]
$actions,
Crud::PAGE_INDEX,
ActionDefinition::DELETE,
[
'icon' => 'trash',
'dropdown' => true,
'label' => $this->get(TranslatorAdmin::class)->transAction('delete'),
'class' => 'dropdown-item text-danger in-dropdown action-delete',
]
); );


$this->actionUpdate( $this->actionUpdate(
$actions,
Crud::PAGE_INDEX,
ActionDefinition::BATCH_DELETE,
[
'class' => 'btn btn-sm btn-danger',
'icon' => 'trash',
'label' => $this->get(TranslatorAdmin::class)->transAction('delete'),
]
$actions,
Crud::PAGE_INDEX,
ActionDefinition::BATCH_DELETE,
[
'class' => 'btn btn-sm btn-danger',
'icon' => 'trash',
'label' => $this->get(TranslatorAdmin::class)->transAction('delete'),
]
); );
} }






$this->actionUpdate( $this->actionUpdate(
$actions,
Crud::PAGE_EDIT,
ActionDefinition::SAVE_AND_RETURN,
[
'add_class' => 'float-right ',
'icon' => 'check',
'label' => $this->get(TranslatorAdmin::class)->transAction('save_and_return'),
]
$actions,
Crud::PAGE_EDIT,
ActionDefinition::SAVE_AND_RETURN,
[
'add_class' => 'float-right ',
'icon' => 'check',
'label' => $this->get(TranslatorAdmin::class)->transAction('save_and_return'),
]
); );


$this->actionUpdate( $this->actionUpdate(
$actions,
Crud::PAGE_EDIT,
ActionDefinition::INDEX,
[
'icon' => 'chevron-left',
'class' => 'btn btn-link',
'label' => $this->get(TranslatorAdmin::class)->transAction('back_index'),
]
$actions,
Crud::PAGE_EDIT,
ActionDefinition::INDEX,
[
'icon' => 'chevron-left',
'class' => 'btn btn-link',
'label' => $this->get(TranslatorAdmin::class)->transAction('back_index'),
]
); );




$this->actionUpdate( $this->actionUpdate(
$actions,
Crud::PAGE_EDIT,
ActionDefinition::SAVE_AND_CONTINUE,
[
'class' => 'btn btn-info float-right action-save-continue',
'label' => $this->get(TranslatorAdmin::class)->transAction('save_and_continue'),
]
$actions,
Crud::PAGE_EDIT,
ActionDefinition::SAVE_AND_CONTINUE,
[
'class' => 'btn btn-info float-right action-save-continue',
'label' => $this->get(TranslatorAdmin::class)->transAction('save_and_continue'),
]
); );


$this->actionUpdate( $this->actionUpdate(
$actions,
Crud::PAGE_EDIT,
ActionDefinition::DELETE,
[
'icon' => 'trash',
'class' => 'btn btn-outline-danger action-delete',
'label' => $this->get(TranslatorAdmin::class)->transAction('delete'),
]
$actions,
Crud::PAGE_EDIT,
ActionDefinition::DELETE,
[
'icon' => 'trash',
'class' => 'btn btn-outline-danger action-delete',
'label' => $this->get(TranslatorAdmin::class)->transAction('delete'),
]
); );
} }


$actions->add(Crud::PAGE_NEW, ActionDefinition::INDEX); $actions->add(Crud::PAGE_NEW, ActionDefinition::INDEX);


$this->actionUpdate( $this->actionUpdate(
$actions,
Crud::PAGE_EDIT,
ActionDefinition::SAVE_AND_RETURN,
[
'add_class' => 'float-right',
'icon' => 'check',
'label' => $this->get(TranslatorAdmin::class)->transAction('save_and_return'),
]
$actions,
Crud::PAGE_EDIT,
ActionDefinition::SAVE_AND_RETURN,
[
'add_class' => 'float-right',
'icon' => 'check',
'label' => $this->get(TranslatorAdmin::class)->transAction('save_and_return'),
]
); );


$this->actionUpdate( $this->actionUpdate(
$actions,
Crud::PAGE_EDIT,
ActionDefinition::INDEX,
[
'icon' => 'chevron-left',
'class' => 'btn btn-link',
'label' => $this->get(TranslatorAdmin::class)->transAction('back_index'),
]
$actions,
Crud::PAGE_EDIT,
ActionDefinition::INDEX,
[
'icon' => 'chevron-left',
'class' => 'btn btn-link',
'label' => $this->get(TranslatorAdmin::class)->transAction('back_index'),
]
); );


$this->actionUpdate( $this->actionUpdate(
$actions,
Crud::PAGE_EDIT,
ActionDefinition::SAVE_AND_ADD_ANOTHER,
[
'class' => 'btn btn-info float-right',
'label' => $this->get(TranslatorAdmin::class)->transAction('save_and_add_another'),
]
$actions,
Crud::PAGE_EDIT,
ActionDefinition::SAVE_AND_ADD_ANOTHER,
[
'class' => 'btn btn-info float-right',
'label' => $this->get(TranslatorAdmin::class)->transAction('save_and_add_another'),
]
); );
} }


{ {
if ($this->isInstanceOf(TranslatableInterface::class)) { if ($this->isInstanceOf(TranslatableInterface::class)) {
$actions->update( $actions->update(
Crud::PAGE_INDEX,
ActionDefinition::EDIT,
function (Action $action) {
$action->setTemplatePath('@LcSov/adminlte/crud/action/translatable.html.twig');
Crud::PAGE_INDEX,
ActionDefinition::EDIT,
function (Action $action) {
$action->setTemplatePath('@LcSov/adminlte/crud/action/translatable.html.twig');


return $action;
}
return $action;
}
); );
} }
} }
public function handleSortableEntityActions(Actions $actions): void public function handleSortableEntityActions(Actions $actions): void
{ {
if ($this->isInstanceOf(SortableInterface::class)) { if ($this->isInstanceOf(SortableInterface::class)) {
$sortAction = Action::new(ActionDefinition::SORT, $this->get(TranslatorAdmin::class)->transAction(ActionDefinition::SORT), 'fa fa-sort')
->linkToCrudAction(ActionDefinition::SORT)
->setCssClass('btn btn-sm btn-success')
->createAsGlobalAction();
$sortAction = Action::new(
ActionDefinition::SORT,
$this->get(TranslatorAdmin::class)->transAction(ActionDefinition::SORT),
'fa fa-sort'
)
->linkToCrudAction(ActionDefinition::SORT)
->setCssClass('btn btn-sm btn-success')
->createAsGlobalAction();


$actions->add(Crud::PAGE_INDEX, $sortAction); $actions->add(Crud::PAGE_INDEX, $sortAction);
} }
{ {
if ($this->isInstanceOf(TreeInterface::class)) { if ($this->isInstanceOf(TreeInterface::class)) {
$indexChildAction = Action::new( $indexChildAction = Action::new(
ActionDefinition::INDEX_CHILDREN,
$this->get(TranslatorAdmin::class)->transAction(ActionDefinition::INDEX_CHILDREN),
'fa fa-list'
ActionDefinition::INDEX_CHILDREN,
$this->get(TranslatorAdmin::class)->transAction(ActionDefinition::INDEX_CHILDREN),
'fa fa-list'
) )
->linkToCrudAction(ActionDefinition::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');
->linkToCrudAction(ActionDefinition::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( $backParentAction = Action::new(
ActionDefinition::INDEX_PARENT,
$this->get(TranslatorAdmin::class)->transAction(ActionDefinition::INDEX_PARENT),
'fa fa-chevron-left'
ActionDefinition::INDEX_PARENT,
$this->get(TranslatorAdmin::class)->transAction(ActionDefinition::INDEX_PARENT),
'fa fa-chevron-left'
) )
->linkToCrudAction(ActionDefinition::INDEX)
->setCssClass('btn btn-sm btn-info')
->createAsGlobalAction();
->linkToCrudAction(ActionDefinition::INDEX)
->setCssClass('btn btn-sm btn-info')
->createAsGlobalAction();


$actions->add(Crud::PAGE_INDEX, $backParentAction); $actions->add(Crud::PAGE_INDEX, $backParentAction);
$actions->add(Crud::PAGE_INDEX, $indexChildAction); $actions->add(Crud::PAGE_INDEX, $indexChildAction);
{ {
if ($actions->getAsDto('actions')->getAction($crudActionName, $actionName)) { if ($actions->getAsDto('actions')->getAction($crudActionName, $actionName)) {
$actions->update( $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']);
}
$crudActionName,
$actionName,
function (Action $action) use ($button) {
if (isset($button['add_class'])) {
$action->addCssClass($button['add_class']);
}


if (isset($button['icon'])) {
$action->setIcon('fa fa-' . $button['icon']);
}
if (isset($button['class'])) {
$action->setCssClass($button['class']);
}


if (isset($button['label'])) {
$action->setLabel($button['label']);
}
if (isset($button['icon'])) {
$action->setIcon('fa fa-' . $button['icon']);
}


if (isset($button['dropdown']) && $button['dropdown']) {
$action->addCssClass('in-dropdown');
}
if (isset($button['label'])) {
$action->setLabel($button['label']);
}


if (isset($button['html_attributes']) && $button['html_attributes']) {
$action->setHtmlAttributes($button['html_attributes']);
}
if (isset($button['dropdown']) && $button['dropdown']) {
$action->addCssClass('in-dropdown');
}


return $action;
if (isset($button['html_attributes']) && $button['html_attributes']) {
$action->setHtmlAttributes($button['html_attributes']);
} }

return $action;
}
); );
} }
} }
public function autocompleteFilter(AdminContext $context): JsonResponse public function autocompleteFilter(AdminContext $context): JsonResponse
{ {
$queryBuilder = $this->createIndexQueryBuilder( $queryBuilder = $this->createIndexQueryBuilder(
$context->getSearch(),
$context->getEntity(),
FieldCollection::new([]),
FilterCollection::new()
$context->getSearch(),
$context->getEntity(),
FieldCollection::new([]),
FilterCollection::new()
); );
$autocompleteContext = $context->getRequest()->get(AssociationField::PARAM_AUTOCOMPLETE_CONTEXT); $autocompleteContext = $context->getRequest()->get(AssociationField::PARAM_AUTOCOMPLETE_CONTEXT);


/** @var CrudControllerInterface $controller */ /** @var CrudControllerInterface $controller */
$controller = $this->get(ControllerFactory::class)->getCrudControllerInstance( $controller = $this->get(ControllerFactory::class)->getCrudControllerInstance(
$autocompleteContext[EA::CRUD_CONTROLLER_FQCN],
ActionDefinition::INDEX,
$context->getRequest()
$autocompleteContext[EA::CRUD_CONTROLLER_FQCN],
ActionDefinition::INDEX,
$context->getRequest()
); );
/** @var FieldDto $field */ /** @var FieldDto $field */
$field = FieldCollection::new( $field = FieldCollection::new(
$controller->configureFields($autocompleteContext['originatingPage'])
$controller->configureFields($autocompleteContext['originatingPage'])
)->getByProperty($autocompleteContext['propertyName']); )->getByProperty($autocompleteContext['propertyName']);


$filterManager = $this->get(FilterManager::class); $filterManager = $this->get(FilterManager::class);
{ {
if ($dataInOption) { if ($dataInOption) {
$data = $entity; $data = $entity;
}else{
} else {
$data = null; $data = null;
} }


$options['action'] = $this->get(AdminUrlGenerator::class) $options['action'] = $this->get(AdminUrlGenerator::class)
->setAction($action)
->setController($controller)
->setEntityId($entity->getId())
->generateUrl();
->setAction($action)
->setController($controller)
->setEntityId($entity->getId())
->generateUrl();


return $this->createForm($class, $data, $options); return $this->createForm($class, $data, $options);
} }

Loading…
Cancel
Save