ConfigurableLanguageManager::getLanguageSwitchLinks

public ConfigurableLanguageManager::getLanguageSwitchLinks($type, Url $url)

Returns the language switch links for the given language type.

Parameters

string $type: The language type.

\Drupal\Core\Url $url: The URL the switch links will be relative to.

Return value

array A keyed array of links ready to be themed.

Overrides LanguageManager::getLanguageSwitchLinks

File

core/modules/language/src/ConfigurableLanguageManager.php, line 405

Class

ConfigurableLanguageManager
Overrides default LanguageManager to provide configured languages.

Namespace

Drupal\language

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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;
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.