Skip to content

Commit dc2aeef

Browse files
authored
Twig templates fix
* Few Twig templates fix * Fix extra closing element * Fix existing parameter, use it everywhere * Fix Twig warning The macro "dropdownDashboard" (./templates/pages/setup/general/preferences_setup.html.twig:397) uses an undeclared variable named "context". * Copy/Paste should not be allowed :p * There were no condition on those fields * Missing Twig variables
1 parent 7afc632 commit dc2aeef

18 files changed

+50
-40
lines changed

src/KnowbaseItem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1774,7 +1774,7 @@ public static function showRecentPopular(string $type = "", bool $display = true
17741774
<table class="table table-sm">
17751775
<tr><th>{{ title }}</th></tr>
17761776
{% for data in iterator %}
1777-
{% set name = data['transname'] is not empty ? data['transname'] : data['name'] %}
1777+
{% set name = (data['transname'] ?? '') is not empty ? data['transname'] : data['name'] %}
17781778
<tr>
17791779
<td class="text-start">
17801780
<div class="kb">

src/Rule.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3000,6 +3000,8 @@ public function showAndAddRuleForm($item)
30003000
'name' => $name,
30013001
'description' => $rule->fields["description"],
30023002
'is_active' => Dropdown::getYesNo($rule->fields["is_active"]),
3003+
'itemtype' => $rule::class,
3004+
'id' => $rule->fields["id"],
30033005
];
30043006
}
30053007

templates/components/dashboard/widget_form.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
) }}
9797
</div>
9898

99-
{% set palette_displayed = edit and widget_def['haspalette'] %}
99+
{% set palette_displayed = edit and (widget_def['haspalette'] ?? false) %}
100100
{% set palette_disabled = use_gradient %}
101101
{% set palettes = call("Glpi\\Dashboard\\Palette::getAllPalettes") %}
102102
<div class="palette_field" {% if not palette_displayed %}style="display: none;"{% endif %}>

templates/components/form/basic_inputs_macros.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152

153153
{% macro color(name, value, options = {}) %}
154154
{% set options = {
155-
id: name ~ '_' ~ options.rand
155+
id: name ~ '_' ~ (options.rand ?? random()),
156156
}|merge(options) %}
157157

158158
{{ _self.input(name, value, options|merge({

templates/components/form/fields_macros.html.twig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
}) %}
8585
{% endif %}
8686
{% if item.fields[name] is defined and item.fields[name] is not null %}
87-
{% set value = call('autoName', [item.fields[name], name, (withtemplate == 2), item.getType(), item.fields['entities_id']]) %}
87+
{% set value = call('autoName', [item.fields[name], name, (withtemplate == 2), item.getType(), item.fields['entities_id'] ?? null]) %}
8888
{% else %}
8989
{% set value = null %}
9090
{% endif %}
@@ -625,6 +625,7 @@
625625
{% set options = {
626626
'rand': random(),
627627
'width': '100%',
628+
'disabled': false,
628629
}|merge(options) %}
629630
{% if options.fields_template.isMandatoryField(name)|default(false) %}
630631
{% set options = {'required': true}|merge(options) %}
@@ -648,7 +649,10 @@
648649
{% endmacro %}
649650

650651
{% macro dropdownFrequency(name, value, label = '', options = {}) %}
651-
{% set options = {'rand': random()}|merge(options) %}
652+
{% set options = {
653+
'rand': random(),
654+
'disabled': false,
655+
}|merge(options) %}
652656
{% if options.fields_template.isMandatoryField(name)|default(false) %}
653657
{% set options = {'required': true}|merge(options) %}
654658
{% endif %}

templates/components/printer_graph_buttons.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
'rand': random()
3737
} %}
3838

39-
{% if not timerange_presets %}
39+
{% if timerange_presets is not defined %}
4040
{% set timerange_presets = {
4141
'P1D': __('Last day'),
4242
'P1W': __('Last 7 days'),
@@ -47,7 +47,7 @@
4747
} %}
4848
{% endif %}
4949

50-
{% if not format_presets %}
50+
{% if format_presets is not defined %}
5151
{% set format_presets = {
5252
'dynamic': __('Dynamic distribution'),
5353
'daily': __('Daily'),

templates/components/search/criteria_filter_actions.html.twig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,10 @@
100100
contentType: false, // Needed when using FormData object
101101
}).done(function() {
102102
glpi_toast_info("{{ __("Filter saved") }}");
103-
103+
{% if delete_action_id is defined %}
104104
// Show delete button if it wasn't already enabled
105105
$("#{{ delete_action_id }}").removeClass('d-none');
106+
{% endif %}
106107
107108
// Add badge to menu to hint that a filter have been set
108109
const tab = $("a.nav-link[href*='CriteriaFilter']");

templates/components/search/display_data.html.twig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
{# Remove namespace separators for use in HTML attributes #}
4343
{% set normalized_itemtype = itemtype|replace({'\\': ''}) %}
44-
{% set as_map = data['search']['as_map'] == 1 %}
44+
{% set as_map = (data['search']['as_map'] ?? false) == 1 %}
4545

4646
<div
4747
class="card search-card"
@@ -70,18 +70,18 @@
7070
data-start="{{ start }}" data-count="{{ count }}" data-limit="{{ limit }}" data-submit-once
7171
class="masssearchform">
7272

73-
{% if data['search']['as_map'] == 0 %}
73+
{% if not as_map %}
7474
{{ include('components/search/table.html.twig') }}
7575
{% elseif count > 0 %}
7676
{{ include('components/search/map.html.twig') }}
7777
{% endif %}
7878
{% if count > 0 %}
79-
{% if data['display_type'] != constant('Search::GLOBAL_SEARCH') and data['search']['as_map'] == 0 %}
79+
{% if data['display_type'] != constant('Search::GLOBAL_SEARCH') and not as_map %}
8080
<div class="card-footer search-footer {{ not user_pref('search_pagination_on_top') ? "d-block" : "d-block d-xxl-none" }}">
8181
{{ include('components/pager.html.twig') }}
8282
</div>
8383
{% endif %}
84-
{% elseif data['search']['as_map'] == 1 %}
84+
{% elseif as_map %}
8585
{% if search_error %}
8686
{{ alerts.alert_danger(__('An error occured during the search'), __('Consider changing the search criteria or adjusting the displayed columns.')) }}
8787
{% else %}
@@ -93,7 +93,7 @@
9393
{% if not is_ajax %}
9494
</div>
9595

96-
{% if data['search']['as_map'] == 0 %}
96+
{% if not as_map %}
9797
<script>
9898
window.initFluidSearch{{ rand }} = () => {
9999
const allowed_forced_params = ['hide_controls', 'usesession', 'forcetoview', 'criteria'];

templates/components/search/displaypreference_config.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@
9292
{% endif %}
9393
</div>
9494
<ul class="list-group">
95-
{% for opt in entries|filter(v => v['fixed'] == true) %}
95+
{% for opt in entries|filter(v => (v['fixed'] ?? false) == true) %}
9696
<li data-opt-id="{{ opt['id'] }}" data-fixed="true" class="list-group-item py-2 disabled px-2">
9797
<i class="ti ti-grip-vertical bs-invisible"></i>
9898
<span>{{ opt['name'] }}</span>
9999
</li>
100100
{% endfor %}
101-
{% for opt in entries|filter(v => v['fixed'] != true) %}
101+
{% for opt in entries|filter(v => (v['fixed'] ?? false) != true) %}
102102
{% set name_prefix = opt['group'] is not empty ? (opt['group']) : '' %}
103103
<li data-opt-id="{{ opt['id'] }}" class="cursor-grab list-group-item py-2 d-flex px-2 align-items-center">
104104
<i class="ti ti-grip-vertical"></i>

templates/components/search/table.html.twig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
{% endif %}
5656

5757
{% set sorts = data['search']['sort'] %}
58-
58+
{% if search_was_executed %}
5959
{% for col in data['data']['cols'] %}
6060
{# construct header link (for sorting) #}
6161
{% set linkto = '' %}
@@ -94,6 +94,7 @@
9494
{% endif %}
9595
</th>
9696
{% endfor %}
97+
{% endif %}
9798

9899
{# display itemtype in AllAssets #}
99100
{% if union_search_type[itemtype] is defined %}

0 commit comments

Comments
 (0)