Commit fda31a65 authored by catch's avatar catch
Browse files

Revert "Issue #2521782 by paulmckibben, swentel: HTML head has alternate...

Revert "Issue #2521782 by paulmckibben, swentel: HTML head has alternate hreflang links to unpublished translations"

This reverts commit 5a25b3fb.
parent 6366760b
...@@ -566,11 +566,6 @@ function content_translation_page_attachments(&$page) { ...@@ -566,11 +566,6 @@ function content_translation_page_attachments(&$page) {
if ($entity instanceof ContentEntityInterface) { if ($entity instanceof ContentEntityInterface) {
// Current route represents a content entity. Build hreflang links. // Current route represents a content entity. Build hreflang links.
foreach ($entity->getTranslationLanguages() as $language) { foreach ($entity->getTranslationLanguages() as $language) {
// Skip any translation that cannot be viewed.
$translation = $entity->getTranslation($language->getId());
if (!$translation->access('view')) {
continue;
}
$url = $entity->urlInfo() $url = $entity->urlInfo()
->setOption('language', $language) ->setOption('language', $language)
->setAbsolute() ->setAbsolute()
......
...@@ -352,18 +352,8 @@ public function testTranslationRendering() { ...@@ -352,18 +352,8 @@ public function testTranslationRendering() {
// Test that the node page displays the correct translations. // Test that the node page displays the correct translations.
$this->doTestTranslations('node/' . $node->id(), $values); $this->doTestTranslations('node/' . $node->id(), $values);
// Unpublish one of the translations.
foreach ($node->getTranslationLanguages() as $lang) {
if ($lang->getId() != 'en') {
$translation = $node->getTranslation($lang->getId());
$translation->setPublished(NODE_NOT_PUBLISHED);
$translation->save();
break;
}
}
// Test that the node page has the correct alternate hreflang links. // Test that the node page has the correct alternate hreflang links.
$this->doTestAlternateHreflangLinks($node); $this->doTestAlternateHreflangLinks($node->urlInfo());
} }
/** /**
...@@ -383,39 +373,26 @@ protected function doTestTranslations($path, array $values) { ...@@ -383,39 +373,26 @@ protected function doTestTranslations($path, array $values) {
} }
/** /**
* Tests the given node's page view for correct alternate hreflang links. * Tests that the given path provides the correct alternate hreflang links.
* *
* @param \Drupal\node\Entity\Node $node * @param \Drupal\Core\Url $url
* The node to be tested. * The path to be tested.
*
* @throws \Drupal\Core\Entity\EntityMalformedException
*/ */
protected function doTestAlternateHreflangLinks(Node $node) { protected function doTestAlternateHreflangLinks(Url $url) {
$url = $node->urlInfo();
$languages = $this->container->get('language_manager')->getLanguages(); $languages = $this->container->get('language_manager')->getLanguages();
$url->setAbsolute(); $url->setAbsolute();
$urls = []; $urls = [];
$translations = [];
foreach ($this->langcodes as $langcode) { foreach ($this->langcodes as $langcode) {
$language_url = clone $url; $language_url = clone $url;
$urls[$langcode] = $language_url->setOption('language', $languages[$langcode]); $urls[$langcode] = $language_url->setOption('language', $languages[$langcode]);
$translations[$langcode] = $node->getTranslation($langcode);
} }
foreach ($this->langcodes as $langcode) { foreach ($this->langcodes as $langcode) {
// Skip unpublished translations. $this->drupalGet($urls[$langcode]);
if ($translations[$langcode]->isPublished()) { foreach ($urls as $alternate_langcode => $language_url) {
$this->drupalGet($urls[$langcode]); // Retrieve desired link elements from the HTML head.
foreach ($urls as $alternate_langcode => $language_url) { $links = $this->xpath('head/link[@rel = "alternate" and @href = :href and @hreflang = :hreflang]',
// Retrieve desired link elements from the HTML head. array(':href' => $language_url->toString(), ':hreflang' => $alternate_langcode));
$links = $this->xpath('head/link[@rel = "alternate" and @href = :href and @hreflang = :hreflang]', $this->assert(isset($links[0]), format_string('The %langcode node translation has the correct alternate hreflang link for %alternate_langcode: %link.', array('%langcode' => $langcode, '%alternate_langcode' => $alternate_langcode, '%link' => $url->toString())));
array(':href' => $language_url->toString(), ':hreflang' => $alternate_langcode));
if ($translations[$alternate_langcode]->isPublished()) {
$this->assert(isset($links[0]), format_string('The %langcode node translation has the correct alternate hreflang link for %alternate_langcode: %link.', array('%langcode' => $langcode, '%alternate_langcode' => $alternate_langcode, '%link' => $url->toString())));
}
else {
$this->assertFalse(isset($links[0]), format_string('The %langcode node translation has an hreflang link for unpublished %alternate_langcode translation: %link.', array('%langcode' => $langcode, '%alternate_langcode' => $alternate_langcode, '%link' => $url->toString())));
}
}
} }
} }
} }
......
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