Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symfony 5 support #1045

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6eefbf4
Update Twig version 2.x, fix tests
jmontoyaa Dec 17, 2019
d873ffe
Add php 7.2, 7.3 and 7.4
jmontoyaa Dec 17, 2019
40e9648
Remove PHP 5.6 tests
jmontoyaa Dec 17, 2019
3ff4e7a
Add php 7.1 remove 7.4
jmontoyaa Dec 17, 2019
9c771d4
Fix phpunit test add Symfony 5 support, remove Symfony 2 deps.
jmontoyaa Jan 6, 2020
3ec3cfa
Add mongodb
jmontoyaa Jan 6, 2020
a9d3ac8
Fix coveralls file name
jmontoyaa Jan 6, 2020
3aa46c3
Remove extra.symfony.require
jmontoyaa Jan 6, 2020
b7c8046
Update PHp to version 7.2, update travis matrix
jmontoyaa Apr 1, 2020
fff01cb
Merge pull request #1 from APY/master
jmontoyaa Dec 14, 2020
f0b6a62
replace transchoice by trans - transChoice is deprecated since SF4.2*…
Dec 14, 2020
b2fae09
Merge pull request #2 from samuelvi/replace_transchoice_by_trans
jmontoyaa Dec 15, 2020
2f64264
Update services.xml
kaamaa Mar 12, 2021
c8c7b04
Update services.xml
kaamaa Mar 12, 2021
efa31ac
Update Grid.php
kaamaa Mar 12, 2021
3f9227a
Update Configuration.php
kaamaa Mar 12, 2021
4848b68
Update README.md
kaamaa Mar 12, 2021
7a9fbb8
Update services.xml
kaamaa Mar 13, 2021
54b7b38
Update README.md
kaamaa Mar 14, 2021
6128364
Update blocks.html.twig
kaamaa Mar 14, 2021
9425cd1
spaceless in blocks.html.twig
FredDut Aug 12, 2021
56c62e1
Update GridManager.php
FredDut Aug 12, 2021
2722af4
Merge pull request #3 from kaamaa/master
jmontoyaa Aug 12, 2021
82402e0
Merge pull request #4 from FredDut/patch-4
jmontoyaa Aug 12, 2021
138764c
Merge pull request #5 from FredDut/patch-5
jmontoyaa Aug 12, 2021
630a1b5
Update Export.php
samuelvi Sep 7, 2021
d31e8b8
Merge pull request #6 from samuelvi/patch-1
jmontoyaa Sep 7, 2021
2e31115
Update README.md
jmontoyaa Sep 13, 2021
dd83d10
Update blocks.html.twig
FredDut Oct 21, 2021
a0c31b2
Merge pull request #7 from FredDut/patch-6
jmontoyaa Oct 21, 2021
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
22 changes: 8 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
language: php

php:
- 5.6
- 7.0
- 7.2
- 7.3

matrix:
include:
- php: 5.6
- php: 7.2
env: |
SYMFONY_VERSION=2.7.*
- php: 5.6
env: |
SYMFONY_VERSION=2.8.*
- php: 7.1
SYMFONY_VERSION=^3.0
- php: 7.2
env: |
SYMFONY_VERSION=^4.0

before_install:
- echo "extension = mongodb.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- |
if [ "${SYMFONY_VERSION}" != "" ]; then
packages="form dependency-injection config http-foundation http-kernel options-resolver security serializer"
packages="form dependency-injection config http-foundation http-kernel options-resolver security-guard serializer"
devpackages="framework-bundle browser-kit templating expression-language"
for package in $packages
do
Expand All @@ -31,10 +29,6 @@ before_install:
done
fi;


before_script:
- echo "extension=mongodb.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`

install:
- travis_retry composer self-update
- COMPOSER_MEMORY_LIMIT=-1 travis_retry composer update ${COMPOSER_FLAGS} --no-interaction
Expand All @@ -46,4 +40,4 @@ script:
- php vendor/bin/phpunit -c phpunit.xml.dist

after_success:
- php vendor/bin/coveralls
- php vendor/bin/php-coveralls
6 changes: 3 additions & 3 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class Configuration implements ConfigurationInterface
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('apy_data_grid');
$treeBuilder = new TreeBuilder('apy_data_grid');
$rootNode = $treeBuilder->getRootNode();

$rootNode
->children()
Expand All @@ -32,7 +32,7 @@ public function getConfigTreeBuilder()
->prototype('scalar')->end()
->end()
->booleanNode('persistence')->defaultFalse()->end()
->scalarNode('theme')->defaultValue('APYDataGridBundle::blocks.html.twig')->end()
->scalarNode('theme')->defaultValue('@APYDataGrid/blocks.html.twig')->end()
->scalarNode('no_data_message')->defaultValue('No data')->end()
->scalarNode('no_result_message')->defaultValue('No result')->end()
->scalarNode('actions_columns_size')->defaultValue(-1)->end()
Expand Down
2 changes: 1 addition & 1 deletion Grid/Column/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ public function getFilters($source)
{
$filters = [];

if ($this->hasOperator($this->data['operator'])) {
if (isset($this->data['operator']) && $this->hasOperator($this->data['operator'])) {
if ($this instanceof ArrayColumn && in_array($this->data['operator'], [self::OPERATOR_EQ, self::OPERATOR_NEQ])) {
$filters[] = new Filter($this->data['operator'], $this->data['from']);
} else {
Expand Down
4 changes: 2 additions & 2 deletions Grid/Export/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

abstract class Export implements ExportInterface, ContainerAwareInterface
{
const DEFAULT_TEMPLATE = 'APYDataGridBundle::blocks.html.twig';
const DEFAULT_TEMPLATE = '@APYDataGrid/blocks.html.twig';

protected $title;

Expand Down Expand Up @@ -459,7 +459,7 @@ protected function getTemplatesFromString($theme)
$templates = [];

$template = $this->twig->loadTemplate($theme);
while ($template instanceof \Twig_Template) {
while ($template instanceof TemplateWrapper) {
$templates[] = $template;
$template = $template->getParent([]);
}
Expand Down
14 changes: 8 additions & 6 deletions Grid/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Twig\TemplateWrapper;

class Grid implements GridInterface
{
Expand Down Expand Up @@ -359,8 +360,10 @@ public function initialize()
$this->setPersistence($config->isPersisted());

// Route parameters
$routeParameters = $config->getRouteParameters();
if (!empty($routeParameters)) {
$routeParameters = [];
$parameters = $config->getRouteParameters();
if (!empty($parameters)) {
$routeParameters = $parameters;
foreach ($routeParameters as $parameter => $value) {
$this->setRouteParameter($parameter, $value);
}
Expand Down Expand Up @@ -1135,7 +1138,7 @@ protected function set($key, $data)

protected function saveSession()
{
if (!empty($this->sessionData)) {
if (!empty($this->sessionData) && !empty($this->hash)) {
$this->session->set($this->hash, $this->sessionData);
}
}
Expand Down Expand Up @@ -1395,12 +1398,11 @@ public function getRowActions()
public function setTemplate($template)
{
if ($template !== null) {
if ($template instanceof \Twig_Template) {
if ($template instanceof TemplateWrapper) {
$template = '__SELF__' . $template->getTemplateName();
} elseif (!is_string($template)) {
throw new \Exception(self::TWIG_TEMPLATE_LOAD_EX_MSG);
}

$this->set(self::REQUEST_QUERY_TEMPLATE, $template);
$this->saveSession();
}
Expand Down Expand Up @@ -2147,7 +2149,7 @@ public function getGridResponse($param1 = null, $param2 = null, Response $respon
if ($view === null) {
return $parameters;
} else {
return $this->container->get('templating')->renderResponse($view, $parameters, $response);
return new Response($this->container->get('twig')->render($view, $parameters, $response));
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion Grid/GridManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,15 @@ public function getGridManagerResponse($param1 = null, $param2 = null, Response
return $parameters;
}

return $this->container->get('templating')->renderResponse($view, $parameters, $response);
$content = $this->container->get('twig')->render($view, $parameters);

if (null === $response) {
$response = new Response();
}

$response->setContent($content);

return $response;
}
}

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
New version for Symfony 5.2.3 an changes for PHP 7.4

Datagrid for Symfony inspired by Zfdatagrid and Magento Grid.
This bundle was initiated by Stanislav Turza (Sorien).

Expand Down
3 changes: 3 additions & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
<argument>%apy_data_grid.actions_columns_title%</argument>
</call>
</service>

<service id="%grid.class%" alias="grid" public="true">
</service>

<service id="grid.manager" class="%grid.manager.class%">
<argument type="service" id="service_container" />
Expand Down
58 changes: 35 additions & 23 deletions Resources/views/blocks.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
{% block grid_no_data %}<p class="no_data">{{ grid.noDataMessage|default('No data')|trans|raw }}</p>{% endblock grid_no_data %}
{# --------------------------------------------------- grid_no_result ------------------------------------------------- #}
{% block grid_no_result %}
{% spaceless %}
{% apply spaceless %}
{% set nbColumns = 0 %}
{% for column in grid.columns %}
{% if column.visible(grid.isReadyForExport) %}
Expand All @@ -53,7 +53,7 @@
<tr class="grid-row-cells">
<td class="last-column last-row" colspan="{{ nbColumns }}" style="text-align: center;">{{ grid.noResultMessage|default('No result')|trans|raw }}</td>
</tr>
{% endspaceless %}
{% endapply %}
{% endblock grid_no_result %}
{# --------------------------------------------------- grid_titles -------------------------------------------------- #}
{% block grid_titles %}
Expand All @@ -62,7 +62,7 @@
{% set translation_domain = column.translationDomain %}
{% if column.visible(grid.isReadyForExport) %}
<th class="{% if column.align != 'left'%}align-{{ column.align }}{% endif %}{% if column.class %} {{ column.class }}{% endif %}{% if loop.last %} last-column{% endif %}"{% if(column.size > -1) %} style="width:{{ column.size }}px;"{% endif %}>
{%- spaceless %}
{% apply spaceless %}
{% if column.type == 'massaction' %}
<input type="checkbox" class="grid-mass-selector" onclick="{{ grid.hash }}_markVisible(this.checked);"/>
{% else %}
Expand All @@ -88,7 +88,7 @@
{{ columnTitle }}
{% endif %}
{% endif %}
{% endspaceless -%}
{% endapply -%}
</th>
{% endif %}
{% endfor %}
Expand Down Expand Up @@ -128,7 +128,7 @@
{% block grid_rows %}
{% for row in grid.rows %}
{% set last_row = loop.last %}
{% spaceless %}
{% apply spaceless %}
{% set gridColumns %}
{% for column in grid.columns %}
{% if column.visible(grid.isReadyForExport) %}
Expand All @@ -138,7 +138,7 @@
{% endset %}
<tr{% if row.color != '' %} style="background-color:{{ row.color }};"{% endif %} class="grid-row-cells {{ cycle(['odd', 'even'], loop.index) }}{% if row.class != '' %} {{ row.class }}{% endif %}">
{{ gridColumns }}
{% endspaceless %}
{% endapply %}
</tr>
{% else %}
{{ grid_no_result(grid) }}
Expand All @@ -158,16 +158,16 @@
{% endblock grid_pager %}
{# ---------------------------------------------------- grid_pager_totalcount -------------------------------------------------- #}
{% block grid_pager_totalcount %}
{{ '%count% Results, ' | transchoice(grid.totalCount, {'%count%': grid.totalCount}) }}
{{ '%count% Results, ' | trans({'%count%': grid.totalCount}) }}
{% endblock grid_pager_totalcount %}
{# ---------------------------------------------------- grid_pager_selectpage -------------------------------------------------- #}
{% block grid_pager_selectpage %}
{{ 'Page'|trans }}
{% spaceless %}
{% apply spaceless %}
<input type="button" class="prev" {% if grid.page <= 0 %}disabled="disabled"{% endif %} value="<" onclick="return {{ grid.hash }}_previousPage();"/>
<input type="text" class="current" value="{{ grid.page + 1 }}" size="2" onkeypress="return {{ grid.hash }}_enterPage(event, parseInt(this.value)-1);"/>
<input type="button" value=">" class="next" {% if grid.page >= grid.pageCount-1 %}disabled="disabled"{% endif %} onclick="return {{ grid.hash }}_nextPage();"/> {{ 'of %count%'|trans({ '%count%' : grid.pageCount }) }}
{% endspaceless %}
{% endapply %}
{% endblock grid_pager_selectpage %}
{# ---------------------------------------------------- grid_pager_results_perpage -------------------------------------------------- #}
{% block grid_pager_results_perpage %}
Expand All @@ -188,7 +188,7 @@
<a href="#" onclick="return {{ grid.hash }}_markAll(false);">{{ 'Deselect all'|trans }}</a>
<span class="mass-actions-selected" id="{{ grid.hash }}_mass_action_selected"></span>
</span>
{% spaceless %}
{% apply spaceless %}
<div style="float:right;" class="grid_massactions">
{{ 'Action'|trans }}
<input type="hidden" id="{{ grid.hash }}_mass_action_all" name="{{ grid.hash }}[{{ constant('APY\\DataGridBundle\\Grid\\Grid::REQUEST_QUERY_MASS_ACTION_ALL_KEYS_SELECTED') }}]" value="0"/>
Expand All @@ -200,13 +200,13 @@
</select>
<input type="submit" value="{{ 'Submit Action'|trans }}"/>
</div>
{% endspaceless %}
{% endapply %}
</div>
{% endblock grid_actions %}
{# --------------------------------------------------- grid_exports ------------------------------------------------- #}
{% block grid_exports %}
<div class="exports" style="float:right">
{% spaceless %}
{% apply spaceless %}
{{ 'Export'|trans }}
<select name="{{grid.hash}}[{{ constant('APY\\DataGridBundle\\Grid\\Grid::REQUEST_QUERY_EXPORT') }}]">
<option value="-1"></option>
Expand All @@ -215,13 +215,13 @@
{% endfor %}
</select>
<input type="submit" value="{{ 'Export'|trans }}"/>
{% endspaceless %}
{% endapply %}
</div>
{% endblock grid_exports %}
{# --------------------------------------------------- grid_tweaks ------------------------------------------------- #}
{% block grid_tweaks %}
<div class="tweaks" style="float:right">
{% spaceless %}
{% apply spaceless %}
{{ 'Tweaks'|trans }}
<select name="{{grid.hash}}[{{ constant('APY\\DataGridBundle\\Grid\\Grid::REQUEST_QUERY_TWEAK') }}]">
<option value=""></option>
Expand All @@ -230,7 +230,7 @@
{% endfor %}
</select>
<input type="submit" value="{{ 'Tweak'|trans }}"/>
{% endspaceless %}
{% endapply %}
</div>
{% endblock grid_tweaks %}
{# ------------------------------------------------ grid_column_actions_cell --------------------------------------------- #}
Expand Down Expand Up @@ -299,7 +299,7 @@
{% endblock grid_column_type_simple_array_cell %}
{# ------------------------------------------- grid_column_cell ---------------------------------------- #}
{% block grid_column_cell %}
{%- spaceless %}
{% apply spaceless %}
{% if column.filterable and column.searchOnClick %}
{% set sourceValue = sourceValue is defined ? sourceValue : row.field(column.id) %}
<a href="?{{ grid.hash }}[{{ column.id }}][from]={{ sourceValue | url_encode() }}" class="searchOnClick">{{ value }}</a>
Expand All @@ -308,7 +308,7 @@
{% else %}
{{ value|escape(column.safe)|raw }}
{% endif %}
{% endspaceless -%}
{% endapply -%}
{% endblock grid_column_cell %}
{# -------------------------------------------- grid_column_operator --------------------------------------- #}
{% block grid_column_operator %}
Expand All @@ -328,9 +328,15 @@
{% set btweOperator = constant('APY\\DataGridBundle\\Grid\\Column\\Column::OPERATOR_BTWE') %}
{% set isNullOperator = constant('APY\\DataGridBundle\\Grid\\Column\\Column::OPERATOR_ISNULL') %}
{% set isNotNullOperator = constant('APY\\DataGridBundle\\Grid\\Column\\Column::OPERATOR_ISNOTNULL') %}
{% set op = column.data.operator is defined ? column.data.operator : column.defaultOperator %}
{% set from = column.data.from is defined ? column.data.from : null %}
{% set to = column.data.to is defined ? column.data.to : null %}
{% if column %}
{% set op = column.data.operator is defined ? column.data.operator : column.defaultOperator %}
{% set from = column.data.from is defined ? column.data.from : null %}
{% set to = column.data.to is defined ? column.data.to : null %}
{% else %}
{% set op = column.defaultOperator %}
{% set from = null %}
{% set to = null %}
{% endif %}
<span class="grid-filter-input">
{{ grid_column_operator(column, grid, op, submitOnChange) }}
<span class="grid-filter-input-query">
Expand All @@ -345,9 +351,15 @@
{% set btweOperator = constant('APY\\DataGridBundle\\Grid\\Column\\Column::OPERATOR_BTWE') %}
{% set isNullOperator = constant('APY\\DataGridBundle\\Grid\\Column\\Column::OPERATOR_ISNULL') %}
{% set isNotNullOperator = constant('APY\\DataGridBundle\\Grid\\Column\\Column::OPERATOR_ISNOTNULL') %}
{% set op = column.data.operator is defined ? column.data.operator : column.defaultOperator %}
{% set from = column.data.from is defined ? column.data.from : null %}
{% set to = column.data.to is defined ? column.data.to : null %}
{% if column %}
{% set op = column.data.operator is defined ? column.data.operator : column.defaultOperator %}
{% set from = column.data.from is defined ? column.data.from : null %}
{% set to = column.data.to is defined ? column.data.to : null %}
{% else %}
{% set op = column.defaultOperator %}
{% set from = null %}
{% set to = null %}
{% endif %}
{% set multiple = column.selectMulti %}
{% set expanded = column.selectExpanded %}
<span class="grid-filter-select">
Expand Down
4 changes: 2 additions & 2 deletions Tests/Grid/Column/TextColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
use APY\DataGridBundle\Grid\Column\Column;
use APY\DataGridBundle\Grid\Column\TextColumn;
use APY\DataGridBundle\Grid\Filter;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class TextColumnTest extends TestCase
class TextColumnTest extends WebTestCase
{
/** @var TextColumn */
private $column;
Expand Down
Loading