From 28864529d4f6603f58d12072f9f7511835d768b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9C=C3=A9?= Date: Wed, 5 Jun 2019 00:38:04 +0200 Subject: [PATCH] Rebase from master --- README.md | 12 ++++----- .../MongoOdmEasyAdminController.php | 25 ++++++++++++++++++- src/Form/Type/EasyAdminEmbeddedListType.php | 4 --- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 7f66ea93..e1ebe6fd 100644 --- a/README.md +++ b/README.md @@ -228,20 +228,20 @@ easy_admin_extension: #### Options -Embedded lists are useful to show relations to en entity in its *NEW/EDIT/FORM* or *SHOW* view. It relies on the *LIST* view of the related entities you want to embed in the parent EDIT/SHOW view. Options must be defined in `type_options` key for a *NEW/EDIT/FORM* view, or in `template_options` for a *SHOW* view. +Embedded lists are useful to show relations to an object in its *NEW/EDIT/FORM* or *SHOW* view. It relies on the *LIST* view of the related objects you want to embed in the parent EDIT/SHOW view. Options must be defined in `type_options` key for a *NEW/EDIT/FORM* view, or in `template_options` for a *SHOW* view. Available options are : -- `entity`: Entity config name (key under the EasyAdmin `entities` config) +- `entity`/`document`: Entity/Document config name (key under the EasyAdmin `entities`/`documents` config) - `filters`: Request filters to apply on the list - `hidden_fields`: List of fields (columns) to hide from list fields config - `max_results`: Number of items par page (list.max_results config is used if not defined) - `sort`: Sort to apply -- `parent_entity_fqcn`: Parent entity FQCN in order to guess default filters (only when embedded in *SHOW* view, almost never required) -- `parent_entity_property`: Matching property name on parent entity FQCN (only when embedded in *SHOW* view, if `property` is not an ORM field) -- `entity_fqcn`: Listed entities FQCN in order to guess default filters (only when embedded in *SHOW* view, almost never required) +- `parent_object_fqcn`: Parent object FQCN in order to guess default filters (only when embedded in *SHOW* view, almost never required) +- `parent_object_property`: Matching property name on parent object FQCN (only when embedded in *SHOW* view, if `property` is not an ORM/ODM field) +- `object_fqcn`: Listed entities FQCN in order to guess default filters (only when embedded in *SHOW* view, almost never required) -#### Options guesser based on ORM metadata +#### Options guesser based on ORM metadata (for entities only) Service EmbeddedListHelper is intended to guess `entity` entry for embedded_list. It's reads ORM metadata, based on parent entity (the one that embeds the list) and property name. diff --git a/src/Controller/MongoOdmEasyAdminController.php b/src/Controller/MongoOdmEasyAdminController.php index 2ae12700..474f72d3 100644 --- a/src/Controller/MongoOdmEasyAdminController.php +++ b/src/Controller/MongoOdmEasyAdminController.php @@ -5,6 +5,8 @@ use AlterPHP\EasyAdminExtensionBundle\Security\AdminAuthorizationChecker; use AlterPHP\EasyAdminMongoOdmBundle\Controller\EasyAdminController as BaseEasyAdminController; use AlterPHP\EasyAdminMongoOdmBundle\Event\EasyAdminMongoOdmEvents; +use League\Uri\Modifiers\RemoveQueryParams; +use League\Uri\Schemes\Http; class MongoOdmEasyAdminController extends BaseEasyAdminController { @@ -28,11 +30,32 @@ protected function embeddedListAction() $this->dispatch(EasyAdminMongoOdmEvents::POST_LIST, ['paginator' => $paginator]); + // Filter displaid columns + $hiddenFields = $this->request->query->get('hidden-fields', []); + $fields = \array_filter( + $this->document['list']['fields'], + function ($name) use ($hiddenFields) { + return !\in_array($name, $hiddenFields); + }, + ARRAY_FILTER_USE_KEY + ); + + // Removes existing referer + $baseMasterRequestUri = !$this->request->isXmlHttpRequest() + ? $this->get('request_stack')->getMasterRequest()->getUri() + : $this->request->headers->get('referer'); + $baseMasterRequestUri = Http::createFromString($baseMasterRequestUri); + $removeRefererModifier = new RemoveQueryParams(['referer']); + $masterRequestUri = $removeRefererModifier->process($baseMasterRequestUri); + + $requestParameters = $this->request->query->all(); + $requestParameters['referer'] = (string) $masterRequestUri; + return $this->render('@EasyAdminExtension/default/embedded_list.html.twig', [ 'objectType' => 'document', 'paginator' => $paginator, 'fields' => $fields, - 'masterRequest' => $this->get('request_stack')->getMasterRequest(), + '_request_parameters' => $requestParameters, ]); } diff --git a/src/Form/Type/EasyAdminEmbeddedListType.php b/src/Form/Type/EasyAdminEmbeddedListType.php index 6beff57a..393485b4 100644 --- a/src/Form/Type/EasyAdminEmbeddedListType.php +++ b/src/Form/Type/EasyAdminEmbeddedListType.php @@ -61,7 +61,6 @@ private function buildViewForEntityList(FormView $view, FormInterface $form, arr $parentData = $form->getParent()->getData(); $embeddedListEntity = $options['entity']; $embeddedListFilters = $options['filters']; - // Guess entity FQCN from parent metadata $entityFqcn = $this->embeddedListHelper->getEntityFqcnFromParent(\get_class($parentData), $form->getName()); if (null !== $entityFqcn) { @@ -71,7 +70,6 @@ private function buildViewForEntityList(FormView $view, FormInterface $form, arr $embeddedListEntity = $this->embeddedListHelper->guessEntityEntry($entityFqcn); } } - $view->vars['entity'] = $embeddedListEntity; $view->vars['parent_object_property'] = $form->getConfig()->getName(); @@ -84,7 +82,6 @@ private function buildViewForEntityList(FormView $view, FormInterface $form, arr return $filter; }, $embeddedListFilters); - $view->vars['filters'] = $filters; } @@ -103,7 +100,6 @@ private function buildViewForDocumentList(FormView $view, FormInterface $form, a return $filter; }, $embeddedListFilters); - $view->vars['filters'] = $filters; }