Environment
- VHS Version: 7.2.1
- TYPO3 Version: 11.5.41
- PHP Version: 8.1.33
Problem 1 – LanguageMenuViewHelper::getLanguageFlag() – null label causes TypeError
Error message
FluidTYPO3\Vhs\ViewHelpers\Page\LanguageMenuViewHelper::getLanguageFlag():
Argument #2 ($label) must be of type string, null given,
called in .../vhs/Classes/ViewHelpers/Page/LanguageMenuViewHelper.php on line 364
Root cause
In parseLanguageMenu(), the labelOverwrite argument is applied positionally to the language array. If the labelOverwrite list has fewer entries than languages configured in the TYPO3 site configuration, the remaining languages receive null as their label:
// Classes/ViewHelpers/Page/LanguageMenuViewHelper.php ~line 333
if (!empty($labelOverwrite)) {
$i = 0;
foreach ($languageMenu as $key => $value) {
$languageMenu[$key]['label'] = $labelOverwrite[$i]; // null if $i >= count($labelOverwrite)
$i++;
}
}
This null label is then passed to getLanguageFlag() at line 364 which has a strict string type hint:
$languageMenu[$key]['flagSrc'] = $this->getLanguageFlag($value['flag'] ?? $value['iso'], $value['label']); // $value['label'] can be null
The hideNotTranslated filter at line 377 runs after getLanguageFlag() is called – so even hideNotTranslated="true" does not prevent the crash.
Fix
Cast $value['label'] to string with a null fallback:
// line 364
$languageMenu[$key]['flagSrc'] = $this->getLanguageFlag($value['flag'] ?? $value['iso'], (string)($value['label'] ?? ''));
// line 372–374
$languageMenu[$key]['flagCode'] = $this->getLanguageFlag(
$value['flag'] ?? $value['iso'],
(string)($value['label'] ?? '')
);
Problem 2 – AbstractMenuViewHelper::getItemTitle() – null title causes TypeError
Error message
FluidTYPO3\Vhs\ViewHelpers\Menu\AbstractMenuViewHelper::getItemTitle():
Return value must be of type string, null returned
Root cause
When a page in the TYPO3 page tree has no translation in the currently active language, the overlay mechanism returns a stub page record with uid => null and title => null. This stub is included in the menu pages array passed to parseMenu().
getItemTitle() is declared with return type string, but $page['title'] is null for these stub entries:
// Classes/ViewHelpers/Menu/AbstractMenuViewHelper.php ~line 475
protected function getItemTitle(array $page): string
{
$titleFieldList = GeneralUtility::trimExplode(',', $this->arguments['titleFields']);
foreach ($titleFieldList as $titleFieldName) {
if (!empty($page[$titleFieldName])) {
return $page[$titleFieldName];
}
}
return $page['title']; // null if page has no translation → PHP 8 TypeError
}
Fix
Cast the return value to string with a null fallback:
return (string)($page['title'] ?? '');
Notes
Both issues are PHP 8 strict type incompatibilities that do not occur in PHP 7 (where null is silently coerced to string). They were introduced or became visible after VHS added return type declarations and argument type hints without ensuring all code paths return non-null values.
Environment
Problem 1 –
LanguageMenuViewHelper::getLanguageFlag()– null label causes TypeErrorError message
Root cause
In
parseLanguageMenu(), thelabelOverwriteargument is applied positionally to the language array. If thelabelOverwritelist has fewer entries than languages configured in the TYPO3 site configuration, the remaining languages receivenullas their label:This
nulllabel is then passed togetLanguageFlag()at line 364 which has a strictstringtype hint:The
hideNotTranslatedfilter at line 377 runs aftergetLanguageFlag()is called – so evenhideNotTranslated="true"does not prevent the crash.Fix
Cast
$value['label']to string with a null fallback:Problem 2 –
AbstractMenuViewHelper::getItemTitle()– null title causes TypeErrorError message
Root cause
When a page in the TYPO3 page tree has no translation in the currently active language, the overlay mechanism returns a stub page record with
uid => nullandtitle => null. This stub is included in the menu pages array passed toparseMenu().getItemTitle()is declared with return typestring, but$page['title']isnullfor these stub entries:Fix
Cast the return value to string with a null fallback:
Notes
Both issues are PHP 8 strict type incompatibilities that do not occur in PHP 7 (where null is silently coerced to string). They were introduced or became visible after VHS added return type declarations and argument type hints without ensuring all code paths return non-null values.