Fix #34596 guard extralanguages access for PHP 8 (#38543)

ExtraLanguages::fetch_name_extralanguages() populates
$this->attributes only when the global
MAIN_USE_ALTERNATE_TRANSLATION_FOR constant lists the element type;
on a default install it stays empty. PHP 8 then raises
"Warning: Undefined array key 'societe'" when html.form.class.php
read $extralanguages->attributes['societe'][...] without checking
the parent key.

Two sites are affected: the early-return guard at line 440 (used by
field-level translation widgets) and the showRefNav helper at
line 10315 (used by the third-party card). Both already wrap their
real logic in empty() / is_array() but on the inner key only; add
an extra check on the parent so the array key access does not raise
on default installs.

Same code path on 21.0, 22.0, 23.0 and develop; PR targets 21.0.

Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
This commit is contained in:
w3houde 2026-06-02 04:35:28 +07:00 committed by GitHub
parent 1dfff1211c
commit dfabcddc97
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -437,7 +437,10 @@ class Form
}
$extralanguages->fetch_name_extralanguages('societe');
if (!is_array($extralanguages->attributes[$object->element]) || empty($extralanguages->attributes[$object->element][$fieldname])) {
// ExtraLanguages::fetch_name_extralanguages() leaves $this->attributes empty
// when MAIN_USE_ALTERNATE_TRANSLATION_FOR is not configured, so PHP 8 raises
// 'Undefined array key' on the read below if we do not guard it (issue #34596).
if (empty($extralanguages->attributes[$object->element]) || !is_array($extralanguages->attributes[$object->element]) || empty($extralanguages->attributes[$object->element][$fieldname])) {
return ''; // No extralang field to show
}
@ -10312,7 +10315,9 @@ class Form
}
$extralanguages->fetch_name_extralanguages('societe');
if (!empty($extralanguages->attributes['societe']['name'])) {
// Guard against PHP 8 'Undefined array key' when MAIN_USE_ALTERNATE_TRANSLATION_FOR
// is not configured and fetch_name_extralanguages() leaves attributes empty (issue #34596).
if (!empty($extralanguages->attributes['societe']) && !empty($extralanguages->attributes['societe']['name'])) {
$object->fetchValuesForExtraLanguages();
$htmltext = '';