Skip to content

Commit

Permalink
list form filters OK
Browse files Browse the repository at this point in the history
  • Loading branch information
alterphp committed Oct 22, 2018
1 parent 7a33466 commit 7831c89
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 19 deletions.
6 changes: 2 additions & 4 deletions TODO_mongo_odm.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
# Passer les configPass en mongo_odm
- EmbeddedListViewConfigPass
- ExcludeFieldsConfigPass
- ListFormFiltersConfigPass
- ShortFormTypeConfigPass: OK (use PropertyPath to include [list][form_filters])
- ListFormFiltersConfigPass OK
- ShortFormTypeConfigPass: OK
- ShowViewConfigPass

# POST LIST MONGO ODM QUERY BUILDER

# Tests !
4 changes: 2 additions & 2 deletions src/Configuration/ListFormFiltersConfigPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private function configureEntityFormFilter(string $entityClass, array &$filterCo
$entityClass, $entityMetadata->getFieldMapping($filterConfig['property']), $filterConfig
);
} elseif ($entityMetadata->hasAssociation($filterConfig['property'])) {
$this->configureAssociationFilter(
$this->configureEntityAssociationFilter(
$entityClass, $entityMetadata->getAssociationMapping($filterConfig['property']), $filterConfig
);
}
Expand Down Expand Up @@ -157,7 +157,7 @@ private function configureEntityPropertyFilter(string $entityClass, array $field
}
}

private function configureAssociationFilter(string $entityClass, array $associationMapping, array &$filterConfig)
private function configureEntityAssociationFilter(string $entityClass, array $associationMapping, array &$filterConfig)
{
// To-One (EasyAdminAutocompleteType)
if ($associationMapping['type'] & ClassMetadataInfo::TO_ONE) {
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/MongoOdmAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ protected function isActionAllowed($actionName)
}

// Get item for edit/show or custom actions => security voters may apply
$easyadmin = $this->request->attributes->get('easyadmin');
$subject = $easyadmin['item'] ?? null;
$easyadminMongoOdm = $this->request->attributes->get('easyadmin_mongo_odm');
$subject = $easyadminMongoOdm['item'] ?? null;
$this->get('alterphp.easyadmin_extension.admin_authorization_checker')->checksUserAccess(
$this->document, $actionName, $subject
);
Expand Down
5 changes: 4 additions & 1 deletion src/Helper/ListFormFiltersHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace AlterPHP\EasyAdminExtensionBundle\Helper;

use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\FormFactory;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\RequestStack;
Expand Down Expand Up @@ -40,7 +41,9 @@ public function __construct(FormFactory $formFactory, RequestStack $requestStack
public function getListFiltersForm(array $formFilters): FormInterface
{
if (!isset($this->listFiltersForm)) {
$formBuilder = $this->formFactory->createNamedBuilder('form_filters');
$formBuilder = $this->formFactory->createNamedBuilder(
'form_filters', FormType::class, null, array('csrf_protection' => false)
);

foreach ($formFilters as $name => $config) {
$formBuilder->add(
Expand Down
3 changes: 3 additions & 0 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<services>

<service id="alterphp.easyadmin_extension.twig.extension.easy_admin_extension" class="AlterPHP\EasyAdminExtensionBundle\Twig\EasyAdminExtensionTwigExtension">
<argument type="service" id="router" />
<argument type="service" id="easyadmin.config.manager" />
<argument type="service" id="easyadmin_mongo_odm.config.manager" on-invalid="null" />
<tag name="twig.extension"/>
Expand All @@ -25,6 +26,7 @@
<argument>%easy_admin_extension.custom_form_types%</argument>
<!-- Makes it process just before PropertyConfigPass -->
<tag name="easyadmin.config_pass" priority="41"/>
<tag name="easyadmin_mongo_odm.config_pass" priority="41"/>
</service>
<service id="alterphp.easyadmin_extension.config_pass.embedded_list_view" class="AlterPHP\EasyAdminExtensionBundle\Configuration\EmbeddedListViewConfigPass">
<argument>%easy_admin_extension.embedded_list.open_new_tab%</argument>
Expand All @@ -49,6 +51,7 @@
<service id="alterphp.easyadmin_extension.config_pass.list_form_filters" class="AlterPHP\EasyAdminExtensionBundle\Configuration\ListFormFiltersConfigPass">
<argument type="service" id="doctrine" />
<tag name="easyadmin.config_pass" priority="0"/>
<tag name="easyadmin_mongo_odm.config_pass" priority="0"/>
</service>
<service id="alterphp.easyadmin_extension.helper.list_form_filters" class="AlterPHP\EasyAdminExtensionBundle\Helper\ListFormFiltersHelper">
<argument type="service" id="form.factory"/>
Expand Down
6 changes: 3 additions & 3 deletions src/Resources/views/default/embedded_list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

<th data-property-name="{{ metadata.property }}" class="{{ isSortingField ? 'sorted' }} {{ metadata.virtual ? 'virtual' }} {{ metadata.dataType|lower }} {{ metadata.css_class }}">
{% if metadata.sortable %}
<a href="{{ path('easyadmin', _request_parameters|merge({ sortField: metadata.property, sortDirection: nextSortDirection })) }}">
<a href="{{ easyadmin_path(_request_parameters|merge({ sortField: metadata.property, sortDirection: nextSortDirection })) }}">
<i class="fa {{ _column_icon }}"></i>
{{ _column_label|raw }}
</a>
Expand Down Expand Up @@ -103,7 +103,7 @@
<tr>
<td colspan="{{ _columns_count }}" class="text-center">
{% block open_new_tab %}
<a class="btn btn-info btn-xs open-new-tab" title="{{ 'open.new_tab'|trans({}, 'EasyAdminBundle') }}" target="_blank" href="{{ path('easyadmin', _request_parameters|merge({action: 'list'})) }}">
<a class="btn btn-info btn-xs open-new-tab" title="{{ 'open.new_tab'|trans({}, 'EasyAdminBundle') }}" target="_blank" href="{{ easyadmin_path(_request_parameters|merge({action: 'list'})) }}">
<i class="fa fa-external-link-square"></i>
<span>{{ 'open.new_tab'|trans({}, 'EasyAdminBundle') }}</span>
</a>
Expand All @@ -120,7 +120,7 @@
<script type="text/javascript">
reloadEmbeddedList(
'{{ widget_identifier|e('js') }}',
'{{ path('easyadmin', { action: 'edit', entity: _entity_config.name, view: 'list' })|raw }}'
'{{ easyadmin_path({ action: 'edit', entity: _entity_config.name, view: 'list' })|raw }}'
);
</script>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/views/default/includes/_actions.html.twig
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% for action in actions %}
{% if 'list' == action.name %}
{% set action_href = request_parameters.referer|default('') ? request_parameters.referer|easyadmin_urldecode : path('easyadmin', request_parameters|merge({ action: 'list' })) %}
{% set action_href = request_parameters.referer|default('') ? request_parameters.referer|easyadmin_urldecode : easyadmin_path(request_parameters|merge({ action: 'list' })) %}
{% elseif 'method' == action.type %}
{% set action_href = path('easyadmin', request_parameters|merge({ action: action.name, id: item_id })) %}
{% set action_href = easyadmin_path(request_parameters|merge({ action: action.name, id: item_id })) %}
{% elseif 'route' == action.type %}
{% set action_href = path(action.name, request_parameters|merge({ action: action.name, id: item_id })) %}
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/views/default/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<small>{{ 'list_form_filters.heading_expandcollapse'|trans(_trans_parameters, 'EasyAdminBundle') }}</small>
</em>
</div>
<form id="list-form-filters-form" class="collapse {{ list_form_filters.vars.submitted ? 'in' }}" method="GET" action="{{ path('easyadmin', _request_parameters) }}">
<form id="list-form-filters-form" class="collapse {{ list_form_filters.vars.submitted ? 'in' }}" method="GET" action="{{ easyadmin_path(_request_parameters) }}">
<div id="list-form-filters-panel-body" class="panel-body" style="display: flex; align-items: stretch;">
<div class="col-sm-10">
{% form_theme list_form_filters '@EasyAdmin/form/bootstrap_3_layout.html.twig' %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
{% set action_params = action_params|merge({ sortField: sort.field, sortDirection: sort.direction}) %}
{% endif %}

{{ render(path('easyadmin', action_params)) }}
{{ render(easyadmin_path(action_params)) }}
29 changes: 26 additions & 3 deletions src/Twig/EasyAdminExtensionTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@
use AlterPHP\EasyAdminMongoOdmBundle\Configuration\ConfigManager as MongoOdmConfigManager;
use EasyCorp\Bundle\EasyAdminBundle\Configuration\ConfigManager as EntityConfigManager;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\RouterInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

class EasyAdminExtensionTwigExtension extends AbstractExtension
{
private $entityConfigManager;
private $mongoOdmConfigManager;
private $router;

public function __construct(EntityConfigManager $entityConfigManager, MongoOdmConfigManager $mongoOdmConfigManager = null)
{
public function __construct(
RouterInterface $router, EntityConfigManager $entityConfigManager, MongoOdmConfigManager $mongoOdmConfigManager = null
) {
$this->entityConfigManager = $entityConfigManager;
$this->mongoOdmConfigManager = $mongoOdmConfigManager;
$this->router = $router;
}

public function getFunctions()
Expand All @@ -25,6 +29,7 @@ public function getFunctions()
new TwigFunction('easyadmin_base_twig_path', array($this, 'getBaseTwigPath')),
new TwigFunction('easyadmin_object', array($this, 'getObjectConfiguration')),
new TwigFunction('easyadmin_object_type', array($this, 'getObjectType')),
new TwigFunction('easyadmin_path', array($this, 'getEasyAdminPath')),
);
}

Expand Down Expand Up @@ -77,7 +82,7 @@ public function getObjectConfiguration(Request $request)
}

/**
* Returns the the given object type.
* Returns the given object type.
*
* @param Request $request
*
Expand All @@ -101,4 +106,22 @@ public function getObjectType(Request $request)

return null;
}

/**
* Returns easyadmin path for given parameters.
*
* @param array $parameters
*
* @return string
*/
public function getEasyAdminPath(array $parameters)
{
if (array_key_exists('entity', $parameters)) {
return $this->router->generate('easyadmin', $parameters);
} elseif (array_key_exists('document', $parameters)) {
return $this->router->generate('easyadmin_mongo_odm', $parameters);
}

throw new \RuntimeException('Parameters must contain either "entity" or "document" key !');
}
}

0 comments on commit 7831c89

Please sign in to comment.