protected function EntityMenuLinkContentUrlGenerator::processDataSet in Simple XML sitemap 4.x
Same name and namespace in other branches
- 8.3 src/Plugin/simple_sitemap/UrlGenerator/EntityMenuLinkContentUrlGenerator.php \Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator\EntityMenuLinkContentUrlGenerator::processDataSet()
- 8.2 src/Plugin/simple_sitemap/UrlGenerator/EntityMenuLinkContentUrlGenerator.php \Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator\EntityMenuLinkContentUrlGenerator::processDataSet()
@inheritdoc
@todo Find a way to be able to check if a menu link still exists. This is difficult as we don't operate on MenuLinkContent entities, but on Link entities directly (as some menu links are not MenuLinkContent entities).
Overrides UrlGeneratorBase::processDataSet
File
- src/
Plugin/ simple_sitemap/ UrlGenerator/ EntityMenuLinkContentUrlGenerator.php, line 137
Class
- EntityMenuLinkContentUrlGenerator
- Class EntityMenuLinkContentUrlGenerator
Namespace
Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGeneratorCode
protected function processDataSet($data_set) : array {
/** @var MenuLinkBase $data_set */
if (!$data_set
->isEnabled()) {
throw new SkipElementException();
}
$url_object = $data_set
->getUrlObject()
->setAbsolute();
// Do not include external paths.
if ($url_object
->isExternal()) {
throw new SkipElementException();
}
// If not a menu_link_content link, use bundle settings.
$meta_data = $data_set
->getMetaData();
if (empty($meta_data['entity_id'])) {
$entity_settings = $this->entitiesManager
->setVariants($this->sitemapVariant
->id())
->getBundleSettings('menu_link_content', $data_set
->getMenuName());
}
else {
$entity_settings = $this->entitiesManager
->setVariants($this->sitemapVariant
->id())
->getEntityInstanceSettings('menu_link_content', $meta_data['entity_id']);
if (empty($entity_settings['index'])) {
throw new SkipElementException();
}
}
if ($url_object
->isRouted()) {
// Do not include paths that have no URL.
if (in_array($url_object
->getRouteName(), [
'<nolink>',
'<none>',
])) {
throw new SkipElementException();
}
$path = $url_object
->getInternalPath();
}
else {
// Handle base scheme.
if (strpos($uri = $url_object
->toUriString(), 'base:/') === 0) {
$path = $uri[6] === '/' ? substr($uri, 7) : substr($uri, 6);
}
else {
// Handle unforeseen schemes.
$path = $uri;
}
}
$entity = $this->entityHelper
->getEntityFromUrlObject($url_object);
$path_data = [
'url' => $url_object,
'lastmod' => !empty($entity) && method_exists($entity, 'getChangedTime') ? date('c', $entity
->getChangedTime()) : NULL,
'priority' => $entity_settings['priority'] ?? NULL,
'changefreq' => !empty($entity_settings['changefreq']) ? $entity_settings['changefreq'] : NULL,
'images' => !empty($entity_settings['include_images']) && !empty($entity) ? $this
->getEntityImageData($entity) : [],
// Additional info useful in hooks.
'meta' => [
'path' => $path,
],
];
if (!empty($entity)) {
$path_data['meta']['entity_info'] = [
'entity_type' => $entity
->getEntityTypeId(),
'id' => $entity
->id(),
];
}
return $path_data;
}