Skip to content

Commit 856c678

Browse files
committed
Removed some of twig deprecations
1 parent d32a506 commit 856c678

16 files changed

Lines changed: 60 additions & 98 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"symfony/event-dispatcher" : "^4.4.30|^5.4|^6.0|^7.0",
1717
"symfony/property-access": "^4.4.30|^5.4|^6.0|^7.0",
1818
"symfony/options-resolver": "^5.4|^6.0|^7.0",
19-
"twig/twig": "^3.9"
19+
"twig/twig": "^3.12"
2020
},
2121
"require-dev": {
2222
"ext-dom": "*",

src/Bundle/DataGridBundle/Resources/views/datagrid.html.twig

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,27 @@
11
{% block datagrid_column_type_batch_header %}
2-
{% apply spaceless %}
3-
<th>
4-
<input type="checkbox" id="{{ header.dataGridName }}_{{ header.type }}"/>
5-
<script type="text/javascript">
6-
(function (w) {
7-
var header = w.document.getElementById('{{ header.dataGridName }}_{{ header.type }}');
8-
9-
header.onclick = function() {
10-
var elements = w.document.getElementsByClassName('{{ header.dataGridName }}_{{ header.type }}'),
11-
i = 0;
12-
13-
for (i; i < elements.length; i++) {
14-
elements[i].checked = this.checked;
15-
}
2+
<th>
3+
<input type="checkbox" id="{{ header.dataGridName }}_{{ header.type }}"/>
4+
<script type="text/javascript">
5+
(function (w) {
6+
var header = w.document.getElementById('{{ header.dataGridName }}_{{ header.type }}');
7+
8+
header.onclick = function() {
9+
var elements = w.document.getElementsByClassName('{{ header.dataGridName }}_{{ header.type }}'),
10+
i = 0;
11+
12+
for (i; i < elements.length; i++) {
13+
elements[i].checked = this.checked;
1614
}
17-
}(window));
18-
</script>
19-
</th>
20-
{% endapply %}
15+
}
16+
}(window));
17+
</script>
18+
</th>
2119
{% endblock %}
2220

2321
{% block datagrid_column_type_batch_cell %}
24-
{% apply spaceless %}
2522
<td>
2623
<input type="checkbox" name="{{ cell.dataGridName }}_{{ cell.type }}[]" value="{{ cell.getAttribute('index') }}" class="{{ cell.dataGridName }}_{{ cell.type }}" />
2724
</td>
28-
{% endapply %}
2925
{% endblock %}
3026

3127
{% block datagrid_column_type_action_cell_action %}
@@ -35,7 +31,6 @@
3531
{% endblock %}
3632

3733
{% block datagrid_column_type_action_cell %}
38-
{% apply spaceless %}
3934
<td>
4035
<div>
4136
{% for action_name, action in cell.value %}
@@ -49,11 +44,9 @@
4944
{% endfor %}
5045
</div>
5146
</td>
52-
{% endapply %}
5347
{% endblock %}
5448

5549
{% block datagrid_column_header %}
56-
{% apply spaceless %}
5750
{% if header.hasAttribute('label') %}
5851
{% set label = header.getAttribute('label')|trans({}, translation_domain) %}
5952
{% else %}
@@ -62,17 +55,14 @@
6255
<th{{ block('datagrid_header_attributes') }}>
6356
<span>{{ label }}</span>
6457
</th>
65-
{% endapply %}
6658
{% endblock %}
6759

6860
{% block datagrid_header %}
69-
{% apply spaceless %}
7061
<tr>
7162
{% for header in headers %}
7263
{{ datagrid_column_header_widget(header) }}
7364
{% endfor %}
7465
</tr>
75-
{% endapply %}
7666
{% endblock %}
7767

7868
{% block datagrid_column_cell_form %}
@@ -88,7 +78,6 @@
8878
{% endblock %}
8979

9080
{% block datagrid_column_cell %}
91-
{% apply spaceless %}
9281
<td{{ block('datagrid_cell_attributes') }}>
9382
<div{{ block('datagrid_container_attributes') }}>
9483
<span{{ block('datagrid_value_attributes') }}>
@@ -97,23 +86,19 @@
9786
</span>
9887
</div>
9988
</td>
100-
{% endapply %}
10189
{% endblock %}
10290

10391
{% block datagrid_rowset %}
104-
{% apply spaceless %}
10592
{% for index, row in datagrid %}
10693
<tr>
10794
{% for cell in row %}
10895
{{ datagrid_column_cell_widget(cell) }}
10996
{% endfor %}
11097
</tr>
11198
{% endfor %}
112-
{% endapply %}
11399
{% endblock %}
114100

115101
{% block datagrid %}
116-
{% apply spaceless %}
117102
<table>
118103
<thead>
119104
{{ datagrid_header_widget(datagrid) }}
@@ -122,7 +107,6 @@
122107
{{ datagrid_rowset_widget(datagrid) }}
123108
</tbody>
124109
</table>
125-
{% endapply %}
126110
{% endblock %}
127111

128112
{% block datagrid_container_class 'datagrid-cell-container' ~ ('action' == cell.type ? ' text-right actions' : '') %}
@@ -161,10 +145,8 @@
161145
{%- endblock datagrid_attributes -%}
162146

163147
{% block datagrid_column_type_web_file_cell %}
164-
{% apply spaceless %}
165148
<td{{ block('datagrid_cell_attributes') }}>
166149
<div>
167-
{% endapply %}
168150
{% for file in cell.value %}
169151
{% if is_web_file(file) %}
170152
{% if cell.getAttribute('resolve_file_url') %}
@@ -174,10 +156,8 @@
174156
{% endif %}
175157
{% endif %}
176158
{% endfor %}
177-
{% apply spaceless %}
178159
</div>
179160
</td>
180-
{% endapply %}
181161
{% endblock %}
182162

183163
{% block datagrid_column_type_web_image_cell %}

src/Bundle/DataGridBundle/Twig/Extension/DataGridRuntime.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ private function renderTheme(
327327
array $availableBlocks = []
328328
): string {
329329
$templates = $this->getTemplates($dataGridName);
330-
$contextVars = $this->environment->mergeGlobals($contextVars);
330+
$contextVars += $this->environment->getGlobals();
331331

332332
foreach ($availableBlocks as $blockName) {
333333
foreach ($templates as $template) {

src/Bundle/DataGridBundle/Twig/Node/DataGridThemeNode.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,18 @@
1212
namespace FSi\Bundle\DataGridBundle\Twig\Node;
1313

1414
use FSi\Bundle\DataGridBundle\Twig\Extension\DataGridRuntime;
15+
use Twig\Attribute\YieldReady;
1516
use Twig\Compiler;
17+
use Twig\Node\BodyNode;
1618
use Twig\Node\Expression\ArrayExpression;
1719
use Twig\Node\Node;
1820

19-
class DataGridThemeNode extends Node
21+
#[YieldReady]
22+
class DataGridThemeNode extends BodyNode
2023
{
21-
public function __construct(
22-
Node $dataGrid,
23-
Node $theme,
24-
ArrayExpression $vars,
25-
int $lineno,
26-
?string $tag = null
27-
) {
28-
parent::__construct(['datagrid' => $dataGrid, 'theme' => $theme, 'vars' => $vars], [], $lineno, $tag);
24+
public function __construct(Node $dataGrid, Node $theme, ArrayExpression $vars, int $lineno)
25+
{
26+
parent::__construct(['datagrid' => $dataGrid, 'theme' => $theme, 'vars' => $vars], [], $lineno);
2927
}
3028

3129
public function compile(Compiler $compiler): void

src/Bundle/DataGridBundle/Twig/TokenParser/DataGridThemeTokenParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function parse(Token $token): DataGridThemeNode
4040

4141
$stream->expect(Token::BLOCK_END_TYPE);
4242

43-
return new DataGridThemeNode($dataGrid, $theme, $vars, $token->getLine(), $this->getTag());
43+
return new DataGridThemeNode($dataGrid, $theme, $vars, $token->getLine());
4444
}
4545

4646
public function getTag(): string

src/Bundle/DataSourceBundle/Resources/views/datasource.html.twig

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
{% block datasource_filter %}
2-
{% apply spaceless %}
32
{% for field in datasource %}
43
{{ datasource_field_widget(field, vars) }}
54
{% endfor %}
6-
{% endapply %}
75
{% endblock %}
86

9-
{% block datasource_field %}{% apply spaceless %}
7+
{% block datasource_field %}
108
{% if field.hasAttribute('form') is not empty %}
119
<div{{ block('datasource_container_attributes') }}>
1210
{% for child in field.getAttribute('form').children %}
@@ -18,10 +16,9 @@
1816
{% endfor %}
1917
</div>
2018
{% endif %}
21-
{% endapply %}{% endblock %}
19+
{% endblock %}
2220

2321
{% block datasource_sort %}
24-
{% apply spaceless %}
2522
{% if (field.getAttribute('sorted_ascending')) %}
2623
<span>{{ ascending|raw }}</span>
2724
{% else %}
@@ -32,11 +29,9 @@
3229
{% else %}
3330
<a href="{{ descending_url }}">{{ descending|raw }}</a>
3431
{% endif %}
35-
{% endapply %}
3632
{% endblock %}
3733

3834
{% block datasource_pagination %}
39-
{% apply spaceless %}
4035
<ul>
4136
<li{% if current == first %} class="{{ disabled_class }}"{% endif %}>
4237
<a href="{% if current != first %}{{ first_url }}{% else %}#{% endif %}">{{ 'datasource.pagination.first'|trans({}, translation_domain) }}</a>
@@ -56,7 +51,6 @@
5651
<a href="{% if current != last %}{{ last_url }}{% else %}#{% endif %}">{{ 'datasource.pagination.last'|trans({}, translation_domain) }}</a>
5752
</li>
5853
</ul>
59-
{% endapply %}
6054
{% endblock %}
6155

6256
{% block datasource_max_results_widget %}

src/Bundle/DataSourceBundle/Twig/Extension/DataSourceRuntime.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ private function renderTheme(
487487
array $availableBlocks = []
488488
): string {
489489
$templates = $this->getTemplates($dataSourceName);
490-
$contextVars = $this->environment->mergeGlobals($contextVars);
490+
$contextVars += $this->environment->getGlobals();
491491

492492
foreach ($availableBlocks as $blockName) {
493493
foreach ($templates as $template) {

src/Bundle/DataSourceBundle/Twig/Node/DataSourceRouteNode.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,31 @@
1212
namespace FSi\Bundle\DataSourceBundle\Twig\Node;
1313

1414
use FSi\Bundle\DataSourceBundle\Twig\Extension\DataSourceRuntime;
15+
use Twig\Attribute\YieldReady;
1516
use Twig\Compiler;
17+
use Twig\Node\BodyNode;
1618
use Twig\Node\Expression\AbstractExpression;
1719
use Twig\Node\Node;
1820

19-
final class DataSourceRouteNode extends Node
21+
#[YieldReady]
22+
final class DataSourceRouteNode extends BodyNode
2023
{
2124
/**
2225
* @param Node<Node> $dataGrid
2326
* @param Node<Node> $route
2427
* @param AbstractExpression<AbstractExpression> $additionalParameters
2528
* @param int $lineno
26-
* @param string|null $tag
2729
*/
28-
public function __construct(
29-
Node $dataGrid,
30-
Node $route,
31-
AbstractExpression $additionalParameters,
32-
int $lineno,
33-
?string $tag = null
34-
) {
30+
public function __construct(Node $dataGrid, Node $route, AbstractExpression $additionalParameters, int $lineno)
31+
{
3532
parent::__construct(
3633
[
3734
'datasource' => $dataGrid,
3835
'route' => $route,
3936
'additional_parameters' => $additionalParameters
4037
],
4138
[],
42-
$lineno,
43-
$tag
39+
$lineno
4440
);
4541
}
4642

src/Bundle/DataSourceBundle/Twig/Node/DataSourceThemeNode.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,24 @@
1212
namespace FSi\Bundle\DataSourceBundle\Twig\Node;
1313

1414
use FSi\Bundle\DataSourceBundle\Twig\Extension\DataSourceRuntime;
15+
use Twig\Attribute\YieldReady;
1516
use Twig\Compiler;
17+
use Twig\Node\BodyNode;
1618
use Twig\Node\Expression\AbstractExpression;
1719
use Twig\Node\Node;
1820

19-
final class DataSourceThemeNode extends Node
21+
#[YieldReady]
22+
final class DataSourceThemeNode extends BodyNode
2023
{
2124
/**
2225
* @param Node<Node> $dataGrid
2326
* @param Node<Node> $theme
2427
* @param AbstractExpression<AbstractExpression> $vars
2528
* @param int $lineno
26-
* @param string|null $tag
2729
*/
28-
public function __construct(Node $dataGrid, Node $theme, AbstractExpression $vars, int $lineno, ?string $tag = null)
30+
public function __construct(Node $dataGrid, Node $theme, AbstractExpression $vars, int $lineno)
2931
{
30-
parent::__construct(['datasource' => $dataGrid, 'theme' => $theme, 'vars' => $vars], [], $lineno, $tag);
32+
parent::__construct(['datasource' => $dataGrid, 'theme' => $theme, 'vars' => $vars], [], $lineno);
3133
}
3234

3335
public function compile(Compiler $compiler): void

src/Bundle/DataSourceBundle/Twig/TokenParser/DataSourceRouteTokenParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function parse(Token $token): DataSourceRouteNode
4343

4444
$stream->expect(Token::BLOCK_END_TYPE);
4545

46-
return new DataSourceRouteNode($dataSource, $route, $vars, $token->getLine(), $this->getTag());
46+
return new DataSourceRouteNode($dataSource, $route, $vars, $token->getLine());
4747
}
4848

4949
public function getTag(): string

0 commit comments

Comments
 (0)