Skip to content

Commit

Permalink
Rebase from master
Browse files Browse the repository at this point in the history
  • Loading branch information
alterphp committed Jun 24, 2019
1 parent b9e97d1 commit 2886452
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
25 changes: 24 additions & 1 deletion src/Controller/MongoOdmEasyAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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,
]);
}

Expand Down
4 changes: 0 additions & 4 deletions src/Form/Type/EasyAdminEmbeddedListType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();

Expand All @@ -84,7 +82,6 @@ private function buildViewForEntityList(FormView $view, FormInterface $form, arr

return $filter;
}, $embeddedListFilters);

$view->vars['filters'] = $filters;
}

Expand All @@ -103,7 +100,6 @@ private function buildViewForDocumentList(FormView $view, FormInterface $form, a

return $filter;
}, $embeddedListFilters);

$view->vars['filters'] = $filters;
}

Expand Down

0 comments on commit 2886452

Please sign in to comment.