Skip to content

Commit 25b0fce

Browse files
authored
Various Twig fixes (#19480)
* Use "config()" function call; "config" variable does not exists * Fix missing lang and title on redirect page * nullField do not have label, field name, id, ... * All users fields should be available to prevent issues
1 parent 82c29b5 commit 25b0fce

File tree

5 files changed

+17
-19
lines changed

5 files changed

+17
-19
lines changed

src/Glpi/Controller/IndexController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ public function __invoke(Request $request): Response
103103
if (count($errors) > 0) {
104104
return $this->render('pages/login_error.html.twig', [
105105
'errors' => $errors,
106+
'title' => __('Access denied'),
106107
'login_url' => $CFG_GLPI["root_doc"] . '/front/logout.php?noAUTO=1&redirect=' . \rawurlencode($redirect),
108+
'lang' => $CFG_GLPI["languages"][$_SESSION['glpilanguage']][3]
107109
]);
108110
}
109111

src/User.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,24 +1907,20 @@ protected function computeFriendlyName()
19071907
public function getInfoCard(): string
19081908
{
19091909
$user_params = [
1910-
'id' => $this->getID(),
19111910
'user_name' => $this->getName(),
1912-
'email' => UserEmail::getDefaultForUser($this->getID()),
1913-
'phone' => $this->fields["phone"],
1914-
'phone2' => $this->fields["phone2"],
1915-
'mobile' => $this->fields["mobile"],
1916-
'locations_id' => $this->fields['locations_id'],
1917-
'usertitles_id' => $this->fields['usertitles_id'],
1918-
'usercategories_id' => $this->fields['usercategories_id'],
1919-
'registration_number' => $this->fields['registration_number'],
1911+
'email' => UserEmail::getDefaultForUser($this->getID())
19201912
];
19211913

1914+
foreach ($this->fields as $key => $value) {
1915+
if (!isset($user_params[$key])) {
1916+
$user_params[$key] = $value;
1917+
}
1918+
}
1919+
19221920
if (Session::haveRight('user', READ)) {
19231921
$user_params['login'] = $this->fields['name'];
19241922
}
1925-
if (!empty($this->fields["groups_id"])) {
1926-
$user_params['groups_id'] = $this->fields["groups_id"];
1927-
}
1923+
19281924
return TemplateRenderer::getInstance()->render('components/user/info_card.html.twig', [
19291925
'user' => $user_params,
19301926
'enable_anonymization' => Session::getCurrentInterface() == 'helpdesk',

templates/components/form/fields_macros.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,9 +826,9 @@
826826
{% set options = {'is_horizontal': true}|merge(options) %}
827827

828828
{% if options.is_horizontal %}
829-
{{ _self.horizontalField(label, field, id, add_field_html, options) }}
829+
{{ _self.horizontalField(null, null, null, null, options) }}
830830
{% else %}
831-
{{ _self.verticalField(label, field, id, add_field_html, options) }}
831+
{{ _self.verticalField(null, null, null, null, options) }}
832832
{% endif %}
833833
{% endmacro %}
834834

templates/components/itilobject/timeline/simple_form.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
} %}
4545

4646
{% if show_form %}
47-
<form method="post" action="{{ target }}" {{ formoptions }} enctype="multipart/form-data" data-submit-once>
47+
<form method="post" action="{{ target }}" {{ formoptions ?? '' }} enctype="multipart/form-data" data-submit-once>
4848
{% endif %}
4949
<div class="row flex-column">
5050
{% if not item.isNewItem() %}

templates/pages/setup/notification/ajax_setting.html.twig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
{% import 'components/form/fields_macros.html.twig' as fields %}
3535

3636
{% block form_fields %}
37-
{{ fields.dropdownArrayField('notifications_ajax_sound', config['notifications_ajax_sound'], {
37+
{{ fields.dropdownArrayField('notifications_ajax_sound', config('notifications_ajax_sound'), {
3838
sound_a: __('Sound') ~ ' A',
3939
sound_b: __('Sound') ~ ' B',
4040
sound_c: __('Sound') ~ ' C',
@@ -44,19 +44,19 @@
4444
emptylabel: __('Disabled'),
4545
}) }}
4646

47-
{{ fields.dropdownNumberField('notifications_ajax_check_interval', config['notifications_ajax_check_interval'], __('Time to check for new notifications (in seconds)'), {
47+
{{ fields.dropdownNumberField('notifications_ajax_check_interval', config('notifications_ajax_check_interval'), __('Time to check for new notifications (in seconds)'), {
4848
min: 5,
4949
max: 120,
5050
step: 5
5151
}) }}
5252

53-
{{ fields.textField('notifications_ajax_icon_url', config['notifications_ajax_icon_url'], __('URL of the icon'), {
53+
{{ fields.textField('notifications_ajax_icon_url', config('notifications_ajax_icon_url'), __('URL of the icon'), {
5454
additional_attributes: {
5555
placeholder: path('pics/glpi.png')
5656
}
5757
}) }}
5858

59-
{{ fields.dropdownNumberField('notifications_ajax_expiration_delay', config['notifications_ajax_expiration_delay'], __('Validity period of notifications (in days)'), {
59+
{{ fields.dropdownNumberField('notifications_ajax_expiration_delay', config('notifications_ajax_expiration_delay'), __('Validity period of notifications (in days)'), {
6060
helper: __('Notifications older than the selected value will not be displayed. Expired notifications will be deleted by the %s crontask.')|format(stale_crontask_name),
6161
toadd: {
6262
0: __('Unlimited')

0 commit comments

Comments
 (0)