ConfigurableLanguageManager language_switch_links alter use undefined path variable

Created on 10 October 2015, about 9 years ago
Updated 13 September 2023, about 1 year ago

Problem/Motivation

'path' variable in $this->moduleHandler->alter('language_switch_links', $result, $type, $path); line 427 is undefined.

Line 412

  /**
   * {@inheritdoc}
   */
  public function getLanguageSwitchLinks($type, Url $url) {
    $links = FALSE;

    if ($this->negotiator) {
      foreach ($this->negotiator->getNegotiationMethods($type) as $method_id => $method) {
        $reflector = new \ReflectionClass($method['class']);

        if ($reflector->implementsInterface('\Drupal\language\LanguageSwitcherInterface')) {
          $result = $this->negotiator->getNegotiationMethodInstance($method_id)->getLanguageSwitchLinks($this->requestStack->getCurrentRequest(), $type, $url);

          if (!empty($result)) {
            // Allow modules to provide translations for specific links.
            $this->moduleHandler->alter('language_switch_links', $result, $type, $path);
            $links = (object) array('links' => $result, 'method_id' => $method_id);
            break;
          }
        }
      }
    }

    return $links;
  }

Proposed resolution

Pass $url instead of $path to hook_language_switch_links_alter.

Remaining tasks

<!-- See https://drupal.org/core-mentoring/novice-tasks for tips on identifying novice tasks. Delete or add "Novice" from the Novice? column in the table below as appropriate. Uncomment tasks as the issue advances. Update the Complete? column to indicate when they are done, and maybe reference the comment number where they were done. -->

User interface changes

None.

API changes

hook_language_switch_links_alter third param is now a \Drupal\Core\Url object.

Data model changes

None.

🐛 Bug report
Status

Fixed

Version

8.3 ⚰️

Component
Language system 

Last updated 3 days ago

  • Maintained by
  • 🇩🇪Germany @sun
Created by

🇫🇷France goz

Live updates comments and jobs are added and updated live.
  • API change

    Changes an existing API or subsystem. Not backportable to earlier major versions, unless absolutely required to fix a critical bug.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024