Skip to content

Commit b5506ac

Browse files
stonebuzzRom1-B
andauthored
Fix(fields): fix undefined option (#982)
* Fix(fields): fix undefined option * adapt CHANGELOG * add default * fix --------- Co-authored-by: Rom1-B <[email protected]>
1 parent 4da5fc7 commit b5506ac

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2020
### Fixed
2121
- Fix condition check logic for dropdown field values
2222
- Fix validation for mandatory multiple dropdown
23+
- Fix `twig` error about undefined `dropdown_options`
2324

2425
## [1.21.21] - 2025-03-21
2526

templates/fields.html.twig

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,13 @@
112112
{% set dropdown_itemtype = call("PluginFieldsDropdown::getClassname", [name]) %}
113113
{% endif %}
114114
{% set name_fk = call("getForeignKeyFieldForItemType", [dropdown_itemtype]) %}
115-
{{ macros.dropdownField(dropdown_itemtype, name_fk, value, label, field_options|merge(dropdown_options)) }}
115+
{{ macros.dropdownField(dropdown_itemtype, name_fk, value, label, field_options|merge(dropdown_options|default({}))) }}
116116

117117
{% elseif type matches '/^dropdown-.+/i' %}
118-
{% set dropdown_options = {'condition': field['dropdown_condition'], 'entity': item.getEntityID()} %}
118+
{% set dropdown_options = {'entity': item.getEntityID()} %}
119+
{% if field['dropdown_condition'] is defined and field['dropdown_condition']|length %}
120+
{% set dropdown_options = dropdown_options|merge({'condition': field['dropdown_condition']}) %}
121+
{% endif %}
119122
{% if field['dropdown_class'] == 'User' %}
120123
{% set dropdown_options = dropdown_options|merge({'entity': -1, 'right': 'all'}) %}
121124
{% elseif field['dropdown_class'] == 'Entity' or item.isRecursive() %}
@@ -124,7 +127,7 @@
124127
{% if field['multiple'] %}
125128
{% set dropdown_options = dropdown_options|merge({'multiple': true}) %}
126129
{% endif %}
127-
{{ macros.dropdownField(field['dropdown_class'], name, value, label, field_options|merge(dropdown_options)) }}
130+
{{ macros.dropdownField(field['dropdown_class'], name, value, label, field_options|merge(dropdown_options|default({}))) }}
128131

129132
{% elseif type == 'glpi_item' %}
130133
{% if not massiveaction %}

0 commit comments

Comments
 (0)