getNativeLanguages example

return $path;
  }

  /** * {@inheritdoc} */
  public function getLanguageSwitchLinks(Request $request$type, Url $url) {
    $links = [];
    $query = [];
    parse_str($request->getQueryString() ?? '', $query);

    foreach ($this->languageManager->getNativeLanguages() as $language) {
      $links[$language->getId()] = [
        // We need to clone the $url object to avoid using the same one for all         // links. When the links are rendered, options are set on the $url         // object, so if we use the same one, they would be set for all links.         'url' => clone $url,
        'title' => $language->getName(),
        'language' => $language,
        'attributes' => ['class' => ['language-link']],
        'query' => $query,
      ];
    }

    
return $path;
  }

  /** * {@inheritdoc} */
  public function getLanguageSwitchLinks(Request $request$type, Url $url) {
    $links = [];
    $query = [];
    parse_str($request->getQueryString() ?? '', $query);

    foreach ($this->languageManager->getNativeLanguages() as $language) {
      $langcode = $language->getId();
      $query[static::QUERY_PARAMETER] = $langcode;
      $links[$langcode] = [
        'url' => $url,
        'title' => $language->getName(),
        'attributes' => ['class' => ['language-link']],
        'query' => $query,
      ];
    }

    return $links;
  }
return $summary;
  }

  /** * {@inheritdoc} */
  protected function viewValue(FieldItemInterface $item) {
    // The 'languages' cache context is not necessary because the language is     // either displayed in its configured form (loaded directly from config     // storage by LanguageManager::getLanguages()) or in its native language     // name. That only depends on formatter settings and no language condition.     $languages = $this->getSetting('native_language') ? $this->languageManager->getNativeLanguages(LanguageInterface::STATE_ALL) : $this->languageManager->getLanguages(LanguageInterface::STATE_ALL);
    return [
      '#plain_text' => $item->language && isset($languages[$item->language->getId()]) ? $languages[$item->language->getId()]->getName() : '',
    ];
  }

}
$this->assertSession()->statusCodeEquals($status);
    $this->assertSession()->pageTextContains($marker);
    if ($found) {
      $this->assertSession()->responseContains($restricted);
    }
    else {
      $this->assertSession()->responseNotContains($restricted);
    }

    // Assert that all languages had a link passed to     // hook_language_switch_links_alter() to allow alternatives to be provided.     $languages = \Drupal::languageManager()->getNativeLanguages();
    $links_for_alter = \Drupal::state()->get('language_test.language_switch_link_ids');
    $this->assertSame(array_keys($languages)$links_for_alter);
  }

  /** * Saves the native name of a language entity in configuration as a label. * * @param string $langcode * The language code of the language. * @param string $label * The native name of the language. */
'#title' => $this->t('Display in native language'),
      '#type' => 'checkbox',
      '#default_value' => $this->options['native_language'],
    ];
  }

  /** * {@inheritdoc} */
  public function render(ResultRow $values) {
    $value = $this->getValue($values);
    $languages = $this->options['native_language'] ? \Drupal::languageManager()->getNativeLanguages() : \Drupal::languageManager()->getLanguages();
    return isset($languages[$value]) ? $languages[$value]->getName() : '';
  }

}
/** * {@inheritdoc} */
  public function getLanguageSwitchLinks(Request $request$type, Url $url) {
    $links = [];
    $query = [];
    parse_str($request->getQueryString() ?? '', $query);
    $config = $this->config->get('language.negotiation')->get('session');
    $param = $config['parameter'];
    $language_query = $_SESSION[$param] ?? $this->languageManager->getCurrentLanguage($type)->getId();

    foreach ($this->languageManager->getNativeLanguages() as $language) {
      $langcode = $language->getId();
      $links[$langcode] = [
        // We need to clone the $url object to avoid using the same one for all         // links. When the links are rendered, options are set on the $url         // object, so if we use the same one, they would be set for all links.         'url' => clone $url,
        'title' => $language->getName(),
        'attributes' => ['class' => ['language-link']],
        'query' => $query,
      ];
      if ($language_query != $langcode) {
        
Home | Imprint | This part of the site doesn't use cookies.