Unverified Commit bd882e9b authored by Alex Pott's avatar Alex Pott
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
parent 4f29fd7f
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -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 = [];
+23 −0
Original line number Diff line number Diff line
@@ -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")]');
  }

}