diff -u b/core/includes/common.inc b/core/includes/common.inc --- b/core/includes/common.inc +++ b/core/includes/common.inc @@ -1317,7 +1317,7 @@ // Add a hreflang attribute if we know the language of this link's url and // hreflang has not already been set. if (!empty($variables['options']['language']) && !isset($variables['options']['attributes']['hreflang'])) { - $variables['options']['attributes']['hreflang'] = $variables['options']['language']; + $variables['options']['attributes']['hreflang'] = $variables['options']['language']->id; } // Because l() is called very often we statically cache values that require an diff -u b/core/modules/system/lib/Drupal/system/Tests/Common/UrlTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/UrlTest.php --- b/core/modules/system/lib/Drupal/system/Tests/Common/UrlTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/UrlTest.php @@ -7,6 +7,7 @@ namespace Drupal\system\Tests\Common; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; use Symfony\Component\HttpFoundation\Request; @@ -55,15 +56,16 @@ */ function testLinkAttributes() { // Test that hreflang is added when a link has a known language. - $langcode = 'fr'; + $language = new Language(array('id' => 'fr', 'name' => 'French')); $hreflang_link = array( '#type' => 'link', '#options' => array( - 'language' => $langcode, + 'language' => $language, ), '#href' => 'http://drupal.org', '#title' => 'bar', ); + $langcode = $language->id; // Test that the default hreflang handling for links does not override a // hreflang attribute explicitly set in the render array.