Problem/Motivation

On multilingual sites using Facets + hreflang, a recurring PHP warning is
logged during language switcher link generation:
Warning: Undefined array key "fr" in
Drupal\facets\LanguageSwitcherLinksAlterer->alter()
(line 110 of .../facets/src/LanguageSwitcherLinksAlterer.php)
The call stack is:
facets_language_switch_links_alter()
ConfigurableLanguageManager->getLanguageSwitchLinks()
hreflang_page_attachments()
## Root cause
`initializeData()` builds and permanently caches `$data` tagged only with
facet entity cache tags. If a new language is enabled after the cache was
populated (without any facet config changing), the new language key is
absent from the cached `$url_aliases` array.
On the next request in that language, lines 110–111 perform a direct array
access on a non-existent key:
$untranslated_alias = $url_aliases[$this->languageManager->getCurrentLanguage()->getId()];
$translated_alias = $url_aliases[$link['language']->getId()];
This triggers `Undefined array key "fr"` (or any other language ID).
The NULL-handling that follows (lines 115–122) already covers the NULL case
correctly by falling back to the original language alias, but it is never
reached because the array access crashes first.

Steps to reproduce

1. Enable Facets on a multilingual site.
2. Let the `facets_language_switcher_links` cache populate (any page load).
3. Add a new site language (e.g. French) without modifying any facet config.
4. Visit a page with active facets using the new language as interface language.
5. Observe the PHP warning in logs.

Proposed resolution

Two changes to `LanguageSwitcherLinksAlterer.php`:
**1. Defensive null-coalescing at lines 110–111** (prevents the warning)
$untranslated_alias = $url_aliases[$this->languageManager->getCurrentLanguage()->getId()] ?? NULL;
$translated_alias = $url_aliases[$link['language']->getId()] ?? NULL;
**2. Add `configurable_language_list` cache tag** (prevents stale cache
when languages are added/removed)
$cache_tags = Cache::mergeTags($cache_tags, ['configurable_language_list']);
$this->cacheBackend->set('facets_language_switcher_links', $data, Cache::PERMANENT, $cache_tags);
See attached patch.

Comments

nasreddine123 created an issue.