Commit 3b64c574 authored by gbyte.co's avatar gbyte.co

Do not allow indexing entity types which do not have the canonical link template

parent 9cf1c1f1
......@@ -219,3 +219,28 @@ function simple_sitemap_update_8203() {
\Drupal::service('config.factory')->getEditable("simple_sitemap.settings")
->setData($settings)->save();
}
/**
* Remove entity type settings for entity types which do not have the canonical
* link template.
*/
function simple_sitemap_update_8204() {
$sitemap_entity_types = \Drupal::service('entity_type.manager')->getDefinitions();
$entity_types = \Drupal::config('simple_sitemap.entity_types')->get();
unset($entity_types['_core']);
foreach($entity_types as $entity_type_id => $entity_type) {
if (!isset($sitemap_entity_types[$entity_type_id])
|| !$sitemap_entity_types[$entity_type_id]->hasLinkTemplate('canonical')) {
// Delete entity overrides.
\Drupal::database()->delete('simple_sitemap_entity_overrides')
->condition('entity_type', $entity_type_id)
->execute();
// Delete entity type settings.
unset($entity_types[$entity_type_id]);
}
}
\Drupal::service('config.factory')->getEditable("simple_sitemap.entity_types")
->setData($entity_types)->save();
}
......@@ -122,7 +122,6 @@ class BatchUrlGenerator {
// Loading url object for other entities.
default:
// todo: file entity type does not have a canonical url and breaks generation, hopefully fixed in https://www.drupal.org/node/2402533
$url_object = $entity->toUrl();
}
......
......@@ -543,7 +543,9 @@ class Simplesitemap {
$entity_types = $this->entityTypeManager->getDefinitions();
foreach ($entity_types as $entity_type_id => $entity_type) {
if (!$entity_type instanceof ContentEntityTypeInterface || !method_exists($entity_type, 'getBundleEntityType')) {
if (!$entity_type instanceof ContentEntityTypeInterface
|| !method_exists($entity_type, 'getBundleEntityType')
|| !$entity_type->hasLinkTemplate('canonical')) {
unset($entity_types[$entity_type_id]);
}
}
......
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