Skip to content

Commit 0b30584

Browse files
Merge pull request #17029 from MauricioFauth/twig-strict-variables
Enable Twig's `strict_variables` option in dev env
2 parents ba98386 + 71493cb commit 0b30584

16 files changed

Lines changed: 89 additions & 72 deletions

File tree

libraries/classes/Template.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,14 @@ public static function getTwigEnvironment(string|null $cacheDir): Environment
6565

6666
if (($GLOBALS['cfg']['environment'] ?? '') === 'development') {
6767
$twig->enableDebug();
68+
$twig->enableStrictVariables();
6869
$twig->addExtension(new DebugExtension());
6970
// This will enable debug for the extension to print lines
7071
// It is used in po file lines re-mapping
7172
TransNode::$enableAddDebugInfo = true;
7273
} else {
7374
$twig->disableDebug();
75+
$twig->disableStrictVariables();
7476
TransNode::$enableAddDebugInfo = false;
7577
}
7678

templates/columns_definitions/column_attributes.twig

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
{% if char_editing == 'textarea' %}
5656
<textarea name="field_default_value[{{ column_number }}]" cols="15" class="textfield default_value">{{ default_value }}</textarea>
5757
{% else %}
58-
<input type="text" name="field_default_value[{{ column_number }}]" size="12" value="{{ default_value }}" class="textfield default_value">
58+
<input type="text" name="field_default_value[{{ column_number }}]" size="12" value="{{ default_value ?? '' }}" class="textfield default_value">
5959
{% endif %}
6060
{% set ci = ci + 1 %}
6161
</td>
@@ -67,7 +67,7 @@
6767
<optgroup label="{{ charset.name }}" title="{{ charset.description }}">
6868
{% for collation in charset.collations %}
6969
<option value="{{ collation.name }}" title="{{ collation.description }}"
70-
{{- collation.name == column_meta['Collation'] ? ' selected' }}>
70+
{{- column_meta['Collation'] is defined and collation.name == column_meta['Collation'] ? ' selected' }}>
7171
{{- collation.name -}}
7272
</option>
7373
{% endfor %}
@@ -91,7 +91,7 @@
9191
</td>
9292
<td class="text-center">
9393
<input name="field_null[{{ column_number }}]" id="field_{{ column_number }}_{{ ci - ci_offset }}" type="checkbox" value="YES" class="allow_null"
94-
{{- column_meta['Null'] is not empty and column_meta['Null'] != 'NO' and column_meta['Null'] != 'NOT NULL' ? ' checked' }}>
94+
{{- column_meta['Null'] is defined and column_meta['Null'] is not empty and column_meta['Null'] != 'NO' and column_meta['Null'] != 'NOT NULL' ? ' checked' }}>
9595
{% set ci = ci + 1 %}
9696
</td>
9797
{% if change_column is defined and change_column is not empty %}
@@ -170,11 +170,10 @@
170170
{# move column #}
171171
{% if fields_meta is defined %}
172172
{% set current_index = 0 %}
173-
{% set cols = move_columns|length - 1 %}
174173
{% set break = false %}
175-
{% for mi in 0..cols %}
176-
{% if move_columns[mi].name == column_meta['Field'] and not break %}
177-
{% set current_index = mi %}
174+
{% for move_column in move_columns %}
175+
{% if move_column.name == column_meta['Field'] and not break %}
176+
{% set current_index = loop.index0 %}
178177
{% set break = true %}
179178
{% endif %}
180179
{% endfor %}
@@ -185,10 +184,10 @@
185184
<option value="-first"{{ current_index == 0 ? ' disabled="disabled"' }}>
186185
{% trans 'first' %}
187186
</option>
188-
{% for mi in 0..move_columns|length - 1 %}
189-
<option value="{{ move_columns[mi].name }}"
190-
{{- current_index == mi or current_index == mi + 1 ? ' disabled' }}>
191-
{{ 'after %s'|trans|format(backquote(move_columns[mi].name|e)) }}
187+
{% for move_column in move_columns %}
188+
<option value="{{ move_column.name }}"
189+
{{- current_index == loop.index0 or current_index == loop.index0 + 1 ? ' disabled' }}>
190+
{{ 'after %s'|trans|format(backquote(move_column.name|e)) }}
192191
</option>
193192
{% endfor %}
194193
</select>

templates/database/routines/execute_form.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<td>{{ routine['item_param_type'][loop.index0] }}</td>
2626
{% if show_function_fields %}
2727
<td>
28-
{% if params[loop.index0]['generator'] is not null %}
28+
{% if (params[loop.index0]['generator'] ?? null) is not null %}
2929
<select name="funcs[{{ routine['item_param_name'][loop.index0] }}]">
3030
{{ params[loop.index0]['generator']|raw }}</select>
3131
{% else %}
@@ -42,7 +42,7 @@
4242
{% endfor %}
4343
{% elseif routine['item_param_type'][loop.index0]|lower in params['no_support_types'] %}
4444
{% else %}
45-
<input class="{{ params[loop.index0]['class'] }}" type="text" name="params[{{ routine['item_param_name'][loop.index0] }}]">
45+
<input class="{{ params[loop.index0]['class'] ?? '' }}" type="text" name="params[{{ routine['item_param_name'][loop.index0] }}]">
4646
{% endif %}
4747
</td>
4848
</tr>

templates/display/results/table.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@
309309
</table>
310310
</div>
311311

312-
{% if has_bulk_links %}
312+
{% if has_bulk_links is defined and has_bulk_links %}
313313
<div class="d-print-none">
314314
{{ get_image('select_all_arrow', 'With selected:'|trans, { 'dir': text_dir, 'width': '38', 'height': '22' }) }}
315315
<input type="checkbox" id="resultsForm_{{ unique_id }}_checkall" class="checkall_box" title="{% trans 'Check all' %}">

templates/indexes.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@
4343
<td rowspan="{{ columns_count }}" class="d-print-none">
4444
{% if index.getName() == 'PRIMARY' %}
4545
{% set index_params = {
46-
'sql_query': 'ALTER TABLE ' ~ backquote(table) ~ ' DROP PRIMARY KEY;',
46+
'sql_query': 'ALTER TABLE ' ~ backquote(url_params.table) ~ ' DROP PRIMARY KEY;',
4747
'message_to_show': 'The primary key has been dropped.'|trans
4848
} %}
4949
{% else %}
5050
{% set index_params = {
51-
'sql_query': 'ALTER TABLE ' ~ backquote(table) ~ ' DROP INDEX ' ~ backquote(index.getName()) ~ ';',
51+
'sql_query': 'ALTER TABLE ' ~ backquote(url_params.table) ~ ' DROP INDEX ' ~ backquote(index.getName()) ~ ';',
5252
'message_to_show': 'Index %s has been dropped.'|trans|format(index.getName())
5353
} %}
5454
{% endif %}

templates/login/footer.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
</div>
2-
{% if check_timeout == true %}
2+
{% if check_timeout is defined and check_timeout == true %}
33
</div>
44
{% endif %}

templates/menu/breadcrumbs.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
{% if table.comment is not empty %}
3737
<span class="breadcrumb-comment" draggable="false">“{{ table.comment }}”</span>
3838
{% endif %}
39-
{% elseif database.comment is not empty %}
39+
{% elseif database.comment is defined and database.comment is not empty %}
4040
<span class="breadcrumb-comment" draggable="false">“{{ database.comment }}”</span>
4141
{% endif %}
4242
{% endif %}

templates/navigation/item_unhide_dialog.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{{ get_hidden_inputs(database) }}
33

44
{% for type, label in types %}
5-
{% if hidden[type] is iterable %}
5+
{% if hidden[type] is defined and hidden[type] is iterable %}
66
{{ not loop.first ? '<br>' }}
77
<strong>{{ label }}</strong>
88
<table class="table w-100">

0 commit comments

Comments
 (0)