Unverified Commit 36bb1cb2 authored by Dave Reid's avatar Dave Reid Committed by Dave Reid

Issue #2852713 by Dave Reid, jorgegc: Fixed menu link processing did not work.

parent 64cbadb8
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Drupal\xmlsitemap; namespace Drupal\xmlsitemap;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Database\Connection; use Drupal\Core\Database\Connection;
use Drupal\Core\Database\Query\Merge; use Drupal\Core\Database\Query\Merge;
use Drupal\Core\Entity\EntityChangedInterface; use Drupal\Core\Entity\EntityChangedInterface;
...@@ -10,6 +11,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface; ...@@ -10,6 +11,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Session\AnonymousUserSession; use Drupal\Core\Session\AnonymousUserSession;
use Drupal\Core\State\StateInterface; use Drupal\Core\State\StateInterface;
use Drupal\menu_link_content\MenuLinkContentInterface;
use Symfony\Component\Routing\Exception\RouteNotFoundException; use Symfony\Component\Routing\Exception\RouteNotFoundException;
/** /**
...@@ -93,13 +95,38 @@ class XmlSitemapLinkStorage implements XmlSitemapLinkStorageInterface { ...@@ -93,13 +95,38 @@ class XmlSitemapLinkStorage implements XmlSitemapLinkStorageInterface {
// The following values must always be checked because they are volatile. // The following values must always be checked because they are volatile.
try { try {
$loc = ($entity->id() !== NULL && $entity->hasLinkTemplate('canonical')) ? '/' . $entity->toUrl()->getInternalPath() : ''; // @todo Could we move this logic to some kind of handler on the menu link entity class?
if ($entity instanceof MenuLinkContentInterface) {
$url = $entity->getUrlObject();
if ($url->isRouted()) {
if ($url->getRouteName() === '<nolink>') {
$loc = '';
}
else {
$loc = $url->getInternalPath();
}
}
else {
// Attempt to transform this to a relative URL.
$loc = file_url_transform_relative($url->toString());
// If it could not be transformed into a relative path, disregard it
// since we cannot store external URLs in the sitemap.
if (UrlHelper::isExternal($loc)) {
$loc = '';
}
}
$access = $url->access($this->anonymousUser);
}
else {
$loc = ($entity->id() && $entity->hasLinkTemplate('canonical')) ? $entity->toUrl()->getInternalPath() : '';
$access = $entity->access('view', $this->anonymousUser);
}
} }
catch (RouteNotFoundException $e) { catch (RouteNotFoundException $e) {
$loc = ''; $loc = '';
} }
$entity->xmlsitemap['loc'] = $loc; $entity->xmlsitemap['loc'] = '/' . ltrim($loc, '/');
$entity->xmlsitemap['access'] = $loc && $entity->access('view', $this->anonymousUser); $entity->xmlsitemap['access'] = $loc && $access;
$language = $entity->language(); $language = $entity->language();
$entity->xmlsitemap['language'] = !empty($language) ? $language->getId() : LanguageInterface::LANGCODE_NOT_SPECIFIED; $entity->xmlsitemap['language'] = !empty($language) ? $language->getId() : LanguageInterface::LANGCODE_NOT_SPECIFIED;
......
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