Problem/Motivation
NULL results are being passed to array_filter function.
Issue 3348686 allows for modules to provide translations for specific links using an implementation of moduleHandler->alter
here. The problem is that this occurs after checking for empty results. Certain implementations of the moduleHandler->alter
may empty this results array (see issue 3358576 for language_switcher_extended module). This can result in an empty result array being passed to the array_filter function causing error.
if (!empty($result)) {
// Allow modules to provide translations for specific links.
$this->moduleHandler->alter('language_switch_links', $result, $type, $url);
$result = array_filter($result, function (array $link): bool {}
Although this issue is caused by the calling of moduleHandler->alter
and works assuming all defaults, it should safely handle cases where a NULL value is passed as result by other core or contrib alterations.
Steps to reproduce
- Steps to reproduce
- Install all of the core Multilingual modules
- Add another language
- Enable a content type for content translation (including its published field)
- Use URL -> Path for the language detection
- Place the Language switcher content block
- configure a 3rd party module (for example, language switcher extended) to hide block when no translation is expected.
- Select
Alter the language switcher for untranslated content entities
- Select
Hide the language switcher link
for the untranslated handler - Navigate to a page with no translations
Proposed resolution
Add an additional !empty()
check after all modules have made alterations to the link list.