Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Admin/CRUD/Context/FormElementContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected function supportsElement(Element $element): bool
*/
private function getObject(Request $request)
{
$id = $request->get('id');
$id = $request->attributes->get('id');
if (null === $id || '' === $id) {
$this->checkAllowAddOption();
return null;
Expand Down
7 changes: 6 additions & 1 deletion Admin/DependentElementImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ protected function getParentObjectId(): ?string
return null;
}

return $currentRequest->get(DependentElement::PARENT_REQUEST_PARAMETER);
$parentObjectId = $currentRequest->query->get(DependentElement::PARENT_REQUEST_PARAMETER);
if (null === $parentObjectId) {
return null;
}

return (string) $parentObjectId;
}
}
2 changes: 1 addition & 1 deletion Admin/Display/Context/DisplayContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected function supportsElement(Element $element): bool
*/
private function getObject(Request $request)
{
$id = $request->get('id');
$id = $request->attributes->get('id');

return $this->element->getDataIndexer()->getData($id);
}
Expand Down
4 changes: 2 additions & 2 deletions EventSubscriber/TranslationLocaleMenuSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private function createRootItem(bool $isCurrentElementTranslatable): Item
private function populateTranslationLocaleMenu(Item $menu): void
{
$requestParameters = $this->getRequestParameters();
$route = $this->getRequest()->get('_route');
$route = $this->getRequest()->attributes->get('_route');

if (true === array_key_exists('redirect_uri', $requestParameters)) {
$redirectRequest = $this->createRedirectRequest($requestParameters['redirect_uri']);
Expand Down Expand Up @@ -241,7 +241,7 @@ private function localeToLangaugeName(string $locale): string
private function getRequestParameters(): array
{
return array_merge(
$this->getRequest()->get('_route_params'),
$this->getRequest()->attributes->get('_route_params'),
$this->getRequest()->query->all()
);
}
Expand Down
2 changes: 1 addition & 1 deletion Resources/doc/embedding_element.md
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ class UserListener
public function userEditPostCreate(FormEvent $event)
{
if ($event->getElement()->getId() === 'users') {
$this->invoicesDatasource = $event->getRequest()->get('invoices_datasource', array());
$this->invoicesDatasource = $event->getRequest()->query->all('invoices_datasource', array());
}
}

Expand Down
36 changes: 11 additions & 25 deletions Resources/views/CRUD/datagrid.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% block datagrid %}
{% apply spaceless %}
<table class="table table-hover table-striped table-bordered table-datagrid" id="{{ datagrid.name }}">
<thead>
{{ datagrid_header_widget(datagrid) }}
Expand All @@ -8,11 +7,9 @@
{{ datagrid_rowset_widget(datagrid) }}
</tbody>
</table>
{% endapply %}
{% endblock %}

{% block datagrid_column_cell %}
{% apply spaceless %}
<td{{ block('datagrid_cell_attributes') }}>
<div{{ block('datagrid_container_attributes') }}>
{{ block('datagrid_column_cell_form_link') }}
Expand All @@ -21,7 +18,6 @@
</span>
</div>
</td>
{% endapply %}
{% endblock %}

{% block datagrid_column_cell_form_link %}
Expand Down Expand Up @@ -49,34 +45,29 @@
{%- endblock datagrid_column_cell_form_popover -%}

{% block datagrid_column_cell_form %}
{% apply spaceless %}
{% form_theme form '@FSiAdmin/CRUD/datagrid_edit_form.html.twig' %}
{{ form_start(form) }}
{{ form_widget(form) }}
<div class="col-sm-12 form-group editable-buttons">
<input type="submit" name="submit" value="{{ 'crud.list.datagrid.editable.save'|trans({}, 'FSiAdminBundle') }}" class="btn btn-sm btn-primary">
</div>
{{ form_end(form) }}
{% endapply %}
{% endblock %}

{% block datagrid_column_header %}
{% apply spaceless %}
<th{{ block('datagrid_header_attributes') }}>
<span>{{ header.getAttribute('label')|trans({}, translation_domain) }}</span>
{% if vars.datasource is defined and vars.datasource[header.name] is defined %}
{% set filter = vars.datasource[header.name] %}
{% if filter.getAttribute('sortable') == true %}
{{ datasource_sort_widget(filter) }}
{% endif %}
<th{{ block('datagrid_header_attributes') }}>
<span>{{ header.getAttribute('label')|trans({}, translation_domain) }}</span>
{% if vars.datasource is defined and vars.datasource[header.name] is defined %}
{% set filter = vars.datasource[header.name] %}
{% if filter.getAttribute('sortable') == true %}
{{ datasource_sort_widget(filter) }}
{% endif %}
</th>
{% endapply %}
{% endif %}
</th>
{% endblock %}

{# pattern: datagrid_{grid_name}_column_name_{column_name}_cell #}
{% block datagrid_column_type_action_cell %}
{% apply spaceless %}
<td{{ block('datagrid_cell_attributes') }}>
<div{{ block('datagrid_container_attributes') }}>
{% for action_name, action in cell.value %}
Expand All @@ -90,25 +81,20 @@
{% endfor %}
</div>
</td>
{% endapply %}
{% endblock %}

{# pattern: datagrid_column_type_action_cell_action_{action_name} #}
{% block datagrid_column_type_action_cell_action_edit %}
{% apply spaceless %}
<a href="{{ attr.href }}" title="{{ 'crud.list.datagrid.action.edit'|trans({}, 'FSiAdminBundle') }}" class="btn btn-warning btn-sm">
<span class="glyphicon glyphicon-edit icon-white"></span>
</a>
{% endapply %}
{% endblock %}

{# pattern: datagrid_column_type_action_cell_action_{action_name} #}
{% block datagrid_column_type_action_cell_action_display %}
{% apply spaceless %}
<a href="{{ attr.href }}" title="{{ 'crud.list.datagrid.action.display'|trans({}, 'FSiAdminBundle') }}" class="btn btn-warning btn-sm">
<span class="glyphicon glyphicon-zoom-in icon-white"></span>
</a>
{% endapply %}
<a href="{{ attr.href }}" title="{{ 'crud.list.datagrid.action.display'|trans({}, 'FSiAdminBundle') }}" class="btn btn-warning btn-sm">
<span class="glyphicon glyphicon-zoom-in icon-white"></span>
</a>
{% endblock %}

{%- block datagrid_header_class -%}
Expand Down
54 changes: 22 additions & 32 deletions Resources/views/CRUD/datasource.html.twig
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
{% extends 'bootstrap_3_layout.html.twig' %}

{% block datasource_field %}
{% apply spaceless %}
{% if field.hasAttribute('form') is not empty %}
{% for child in field.getAttribute('form').children %}
{% for grandchild in child %}
{% form_theme grandchild _self %}
{{ form_row(grandchild) }}
{% endfor %}
{% if field.hasAttribute('form') is not empty %}
{% for child in field.getAttribute('form').children %}
{% for grandchild in child %}
{% form_theme grandchild _self %}
{{ form_row(grandchild) }}
{% endfor %}
{% endif %}
{% endapply %}
{% endfor %}
{% endif %}
{% endblock %}

{% block datasource_max_results %}
Expand All @@ -28,21 +26,16 @@
{% endblock %}

{% block datasource_between_row %}
{% apply spaceless %}
{{ form_widget(form) }}
{% endapply %}
{{ form_widget(form) }}
{% endblock datasource_between_row %}

{% block datasource_between_widget %}
{% apply spaceless %}
{% for child in form %}
{{ form_row(child) }}
{% endfor %}
{% endapply %}
{% endblock datasource_between_widget %}

{% block datasource_pagination %}
{% apply spaceless %}
<ul class="pagination">
<li{% if current == first %} class="{{ disabled_class }}"{% endif %}>
<a href="{% if current != first %}{{ first_url }}{% else %}#{% endif %}">{{ 'datasource.pagination.first'|trans({}, translation_domain) }}</a>
Expand All @@ -62,24 +55,21 @@
<a href="{% if current != last %}{{ last_url }}{% else %}#{% endif %}">{{ 'datasource.pagination.last'|trans({}, translation_domain) }}</a>
</li>
</ul>
{% endapply %}
{% endblock %}

{% block datasource_sort %}
{% apply spaceless %}
{% if (field.getAttribute('sorted_ascending')) %}
<button type="button" class="btn btn-default btn-xs sort-asc" disabled="disabled">
<span class="glyphicon glyphicon-sort-by-alphabet"></span>
</button>
{% else %}
<a href="{{ ascending_url }}" class="btn btn-default btn-xs sort-asc"><span class="glyphicon glyphicon-sort-by-alphabet"></span></a>
{% endif %}
{% if (field.getAttribute('sorted_descending')) %}
<button type="button" class="btn btn-default btn-xs sort-desc" disabled="disabled">
<span class="glyphicon glyphicon-sort-by-alphabet-alt"></span>
</button>
{% else %}
<a href="{{ descending_url }}" class="btn btn-default btn-xs sort-desc"><span class="glyphicon glyphicon-sort-by-alphabet-alt"></span></a>
{% endif %}
{% endapply %}
{% if (field.getAttribute('sorted_ascending')) %}
<button type="button" class="btn btn-default btn-xs sort-asc" disabled="disabled">
<span class="glyphicon glyphicon-sort-by-alphabet"></span>
</button>
{% else %}
<a href="{{ ascending_url }}" class="btn btn-default btn-xs sort-asc"><span class="glyphicon glyphicon-sort-by-alphabet"></span></a>
{% endif %}
{% if (field.getAttribute('sorted_descending')) %}
<button type="button" class="btn btn-default btn-xs sort-desc" disabled="disabled">
<span class="glyphicon glyphicon-sort-by-alphabet-alt"></span>
</button>
{% else %}
<a href="{{ descending_url }}" class="btn btn-default btn-xs sort-desc"><span class="glyphicon glyphicon-sort-by-alphabet-alt"></span></a>
{% endif %}
{% endblock %}
6 changes: 2 additions & 4 deletions Resources/views/Form/form_theme.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
{% endblock %}

{% block collection_prototype -%}
{% apply spaceless %}
{% set form = prototype %}
{{ block('collection_item') }}
{% endapply %}
{% set form = prototype %}
{{ block('collection_item') }}
{%- endblock %}

{% block collection_item %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
use Prophecy\Argument;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\HttpFoundation\InputBag;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
Expand All @@ -45,6 +47,7 @@ public function it_has_array_data(
FormView $formView,
Request $request
): void {
$request->attributes = new ParameterBag();
$form->createView()->willReturn($formView);
$form->getData()->willReturn(null);

Expand All @@ -68,6 +71,8 @@ public function it_returns_template_from_element_if_it_has_one(FormElement $elem

public function it_handles_request_with_request_handlers(HandlerInterface $handler, Request $request): void
{
$request->attributes = new ParameterBag();

$handler->handleRequest(Argument::type(FormEvent::class), $request)
->willReturn(null);

Expand All @@ -76,6 +81,8 @@ public function it_handles_request_with_request_handlers(HandlerInterface $handl

public function it_returns_response_from_handler(HandlerInterface $handler, Request $request): void
{
$request->attributes = new ParameterBag();

$handler->handleRequest(Argument::type(FormEvent::class), $request)
->willReturn(new Response());

Expand All @@ -85,7 +92,7 @@ public function it_returns_response_from_handler(HandlerInterface $handler, Requ

public function it_throws_exception_when_adding_is_not_allowed(Request $request, FormElement $element): void
{
$request->get('id')->willReturn(null);
$request->attributes = new ParameterBag(['id' => null]);
$element->getOption('allow_add')->willReturn(false);
$this->shouldThrow(NotFoundHttpException::class)->during('handleRequest', [$request]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@
use FSi\Component\DataIndexer\DataIndexerInterface;
use FSi\Component\Translatable\LocaleProvider;
use PhpSpec\ObjectBehavior;
use Symfony\Component\HttpFoundation\InputBag;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use FSi\Bundle\AdminBundle\spec\fixtures\MyDependentBatch;
use FSi\Bundle\AdminBundle\Admin\CRUD\GenericBatchElement;
use FSi\Bundle\AdminBundle\Admin\CRUD\BatchElement;

use function class_exists;

class DependentBatchElementSpec extends ObjectBehavior
{
public function let(LocaleProvider $localeProvider): void
Expand Down Expand Up @@ -53,7 +57,13 @@ public function it_returns_null_if_parent_object_id_is_not_available(
): void {
$parentElement->getDataIndexer()->willReturn($parentDataIndexer);
$requestStack->getCurrentRequest()->willReturn($currentRequest);
$currentRequest->get(DependentElement::PARENT_REQUEST_PARAMETER)->willReturn(null);
if (class_exists(InputBag::class)) {
$requestQueryBag = new InputBag();
} else {
$requestQueryBag = new ParameterBag();
}
$requestQueryBag->set(DependentElement::PARENT_REQUEST_PARAMETER, null);
$currentRequest->query = $requestQueryBag;

$this->setRequestStack($requestStack);
$this->setParentElement($parentElement);
Expand All @@ -69,7 +79,13 @@ public function it_returns_parent_object_if_its_available(
): void {
$parentElement->getDataIndexer()->willReturn($parentDataIndexer);
$requestStack->getCurrentRequest()->willReturn($currentRequest);
$currentRequest->get(DependentElement::PARENT_REQUEST_PARAMETER)->willReturn('parent_object_id');
if (class_exists(InputBag::class)) {
$requestQueryBag = new InputBag();
} else {
$requestQueryBag = new ParameterBag();
}
$requestQueryBag->set(DependentElement::PARENT_REQUEST_PARAMETER, 'parent_object_id');
$currentRequest->query = $requestQueryBag;
$parentDataIndexer->getData('parent_object_id')->willReturn('parent_object');

$this->setRequestStack($requestStack);
Expand All @@ -86,7 +102,13 @@ public function its_route_parameters_contain_parent_object_id_if_its_available(
): void {
$parentElement->getDataIndexer()->willReturn($parentDataIndexer);
$requestStack->getCurrentRequest()->willReturn($currentRequest);
$currentRequest->get(DependentElement::PARENT_REQUEST_PARAMETER)->willReturn('parent_object_id');
if (class_exists(InputBag::class)) {
$requestQueryBag = new InputBag();
} else {
$requestQueryBag = new ParameterBag();
}
$requestQueryBag->set(DependentElement::PARENT_REQUEST_PARAMETER, 'parent_object_id');
$currentRequest->query = $requestQueryBag;

$this->setRequestStack($requestStack);
$this->setParentElement($parentElement);
Expand Down
Loading