Unverified Commit cdf61eea authored by alexpott's avatar alexpott
Browse files

Issue #2992894 by mohit_aghera, adityasingh, adalbertov, raman.b,...

Issue #2992894 by mohit_aghera, adityasingh, adalbertov, raman.b, vsujeetkumar, mgifford, RenatoG, nishantghetiya, Kristen Pol, alexpott, penyaskito, andrewmacpherson, catch: Search results of multi-lingual pages fail Language of Parts

(cherry picked from commit bd882e9b)
parent 7bd7fee7
......@@ -30,9 +30,9 @@ function template_preprocess_search_result(&$variables) {
$result = $variables['result'];
$variables['url'] = UrlHelper::stripDangerousProtocols($result['link']);
$variables['title'] = $result['title'];
if (isset($result['language']) && $result['language'] != $language_interface->getId() && $result['language'] != LanguageInterface::LANGCODE_NOT_SPECIFIED) {
$variables['title_attributes']['lang'] = $result['language'];
$variables['content_attributes']['lang'] = $result['language'];
if (isset($result['langcode']) && $result['langcode'] != $language_interface->getId() && $result['langcode'] != LanguageInterface::LANGCODE_NOT_SPECIFIED) {
$variables['title_attributes']['lang'] = $result['langcode'];
$variables['content_attributes']['lang'] = $result['langcode'];
}
$info = [];
......
......@@ -148,4 +148,27 @@ public function testLanguages() {
$this->drupalPostForm('admin/config/regional/language/delete/en', [], 'Delete');
}
/**
* Test language attribute "lang" for the search results.
*/
public function testLanguageAttributes() {
$this->drupalGet('search/node');
$this->submitForm(['keys' => 'the Spanish title'], 'Search');
$node = $this->searchableNodes[1]->getTranslation('es');
$this->assertSession()->elementExists('xpath', '//div[@class="layout-content"]//ol/li/h3[contains(@lang, "es")]');
$result = $this->xpath('//div[@class="layout-content"]//ol/li/h3[contains(@lang, "es")]/a');
$this->assertEquals($node->getTitle(), $result[0]->getText());
$this->assertSession()->elementExists('xpath', '//div[@class="layout-content"]//ol/li/p[contains(@lang, "es")]');
// Visit the search form in Spanish language.
$this->drupalGet('es/search/node');
$this->submitForm(['keys' => 'First node'], 'Search');
$this->assertSession()->elementExists('xpath', '//div[@class="layout-content"]//ol/li/h3[contains(@lang, "en")]');
$node = $this->searchableNodes[0]->getTranslation('en');
$result = $this->xpath('//div[@class="layout-content"]//ol/li/h3[contains(@lang, "en")]/a');
$this->assertEquals($node->getTitle(), $result[0]->getText());
$this->assertSession()->elementExists('xpath', '//div[@class="layout-content"]//ol/li/p[contains(@lang, "en")]');
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment