function LanguageTestController::typeLinkActiveClass

Same name and namespace in other branches
  1. 9 core/modules/language/tests/language_test/src/Controller/LanguageTestController.php \Drupal\language_test\Controller\LanguageTestController::typeLinkActiveClass()
  2. 8.9.x core/modules/language/tests/language_test/src/Controller/LanguageTestController.php \Drupal\language_test\Controller\LanguageTestController::typeLinkActiveClass()
  3. 10 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 74

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 [
        'no_language' => [
            '#type' => 'link',
            '#title' => t('Link to the current path with no langcode provided.'),
            '#url' => Url::fromRoute('<current>'),
            '#options' => [
                'attributes' => [
                    'id' => 'no_lang_link',
                ],
                'set_active_class' => TRUE,
            ],
        ],
        'fr' => [
            '#type' => 'link',
            '#title' => t('Link to a French version of the current path.'),
            '#url' => Url::fromRoute('<current>'),
            '#options' => [
                'language' => $languages['fr'],
                'attributes' => [
                    'id' => 'fr_link',
                ],
                'set_active_class' => TRUE,
            ],
        ],
        'en' => [
            '#type' => 'link',
            '#title' => t('Link to an English version of the current path.'),
            '#url' => Url::fromRoute('<current>'),
            '#options' => [
                'language' => $languages['en'],
                'attributes' => [
                    'id' => 'en_link',
                ],
                'set_active_class' => TRUE,
            ],
        ],
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.