Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 299303

LanguageManager does not check against altered language_switch_links

$
0
0

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->alterhere. 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

  1. Steps to reproduce
  2. Install all of the core Multilingual modules
  3. Add another language
  4. Enable a content type for content translation (including its published field)
  5. Use URL -> Path for the language detection
  6. Place the Language switcher content block
  7. configure a 3rd party module (for example, language switcher extended) to hide block when no translation is expected.
  8. Select Alter the language switcher for untranslated content entities
  9. Select Hide the language switcher link for the untranslated handler
  10. Navigate to a page with no translations

Proposed resolution

Add an additional !empty() check after all modules have made alterations to the link list.


Viewing all articles
Browse latest Browse all 299303

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>