You are here

public function LanguageTestController::typeLinkActiveClass in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/language/tests/language_test/src/Controller/LanguageTestController.php \Drupal\language_test\Controller\LanguageTestController::typeLinkActiveClass()

Returns links to the current page with different langcodes.

Using #type 'link' causes these links to be rendered with the link generator.

1 string reference to 'LanguageTestController::typeLinkActiveClass'
language_test.routing.yml in core/modules/language/tests/language_test/language_test.routing.yml
core/modules/language/tests/language_test/language_test.routing.yml

File

core/modules/language/tests/language_test/src/Controller/LanguageTestController.php, line 77
Contains \Drupal\language_test\Controller\LanguageTestController.

Class

LanguageTestController
Controller routines for language_test routes.

Namespace

Drupal\language_test\Controller

Code

public function typeLinkActiveClass() {

  // We assume that 'en' and 'fr' have been configured.
  $languages = $this->languageManager
    ->getLanguages();
  return array(
    'no_language' => array(
      '#type' => 'link',
      '#title' => t('Link to the current path with no langcode provided.'),
      '#url' => Url::fromRoute('<current>'),
      '#options' => array(
        'attributes' => array(
          'id' => 'no_lang_link',
        ),
        'set_active_class' => TRUE,
      ),
    ),
    'fr' => array(
      '#type' => 'link',
      '#title' => t('Link to a French version of the current path.'),
      '#url' => Url::fromRoute('<current>'),
      '#options' => array(
        'language' => $languages['fr'],
        'attributes' => array(
          'id' => 'fr_link',
        ),
        'set_active_class' => TRUE,
      ),
    ),
    'en' => array(
      '#type' => 'link',
      '#title' => t('Link to an English version of the current path.'),
      '#url' => Url::fromRoute('<current>'),
      '#options' => array(
        'language' => $languages['en'],
        'attributes' => array(
          'id' => 'en_link',
        ),
        'set_active_class' => TRUE,
      ),
    ),
  );
}