diff --git a/src/TwigExtension.php b/src/TwigExtension.php index d13184e..66bc69f 100644 --- a/src/TwigExtension.php +++ b/src/TwigExtension.php @@ -509,8 +509,8 @@ class TwigExtension extends \Twig_Extension { */ public function drupalUrl($user_input, array $options = [], $check_access = FALSE) { if (isset($options['langcode'])) { - $lang_manager = \Drupal::languageManager(); - if ($language = $lang_manager->getLanguage($options['langcode'])) { + $language_manager = \Drupal::languageManager(); + if ($language = $language_manager->getLanguage($options['langcode'])) { $options['language'] = $language; } } diff --git a/tests/src/Functional/TwigTweakTest.php b/tests/src/Functional/TwigTweakTest.php index 0f2b9eb..bdcf145 100644 --- a/tests/src/Functional/TwigTweakTest.php +++ b/tests/src/Functional/TwigTweakTest.php @@ -5,6 +5,7 @@ namespace Drupal\Tests\twig_tweak\Functional; use Drupal\Core\Link; use Drupal\Core\Url; use Drupal\file\Entity\File; +use Drupal\language\Entity\ConfigurableLanguage; use Drupal\responsive_image\Entity\ResponsiveImageStyle; use Drupal\Core\Render\Markup; use Drupal\Tests\BrowserTestBase; @@ -28,6 +29,7 @@ class TwigTweakTest extends BrowserTestBase { 'block', 'image', 'responsive_image', + 'language', ]; /** @@ -55,6 +57,9 @@ class TwigTweakTest extends BrowserTestBase { 'breakpoint_group' => 'responsive_image', ])->save(); + + // Setup Russian. + ConfigurableLanguage::createFromLangcode('ru')->save(); } /** @@ -214,7 +219,12 @@ class TwigTweakTest extends BrowserTestBase { // Test URL. $url = Url::fromUserInput('/node/1', ['absolute' => TRUE])->toString(); - $xpath = sprintf('//div[@class = "tt-url" and text() = "%s"]', $url); + $xpath = sprintf('//div[@class = "tt-url"]/div[@data-case="default" and text() = "%s"]', $url); + $this->assertByXpath($xpath); + + // Test URL (with langcode). + $url = str_replace('node/1', 'ru/node/1', $url); + $xpath = sprintf('//div[@class = "tt-url"]/div[@data-case="with-langcode" and text() = "%s"]', $url); $this->assertByXpath($xpath); // Test link. diff --git a/tests/twig_tweak_test/templates/twig-tweak-test.html.twig b/tests/twig_tweak_test/templates/twig-tweak-test.html.twig index 654fa95..e825705 100644 --- a/tests/twig_tweak_test/templates/twig-tweak-test.html.twig +++ b/tests/twig_tweak_test/templates/twig-tweak-test.html.twig @@ -43,7 +43,10 @@