Loading simple_sitemap.module +10 −5 Original line number Original line Diff line number Diff line Loading @@ -195,12 +195,17 @@ function simple_sitemap_configurable_language_delete(ConfigurableLanguageInterfa */ */ function simple_sitemap_entity_delete(EntityInterface $entity) { function simple_sitemap_entity_delete(EntityInterface $entity) { /** @var \Drupal\simple_sitemap\EntityHelper $entity_helper */ $entity_helper = \Drupal::service('simple_sitemap.entity_helper'); if ($entity_helper->supports($entity->getEntityType())) { /** @var \Drupal\simple_sitemap\Simplesitemap $generator */ /** @var \Drupal\simple_sitemap\Simplesitemap $generator */ $generator = \Drupal::service('simple_sitemap.generator'); $generator = \Drupal::service('simple_sitemap.generator'); $generator->setVariants(TRUE)->removeEntityInstanceSettings( $generator->setVariants(TRUE)->removeEntityInstanceSettings( $entity->getEntityTypeId(), $entity->id() $entity->getEntityTypeId(), $entity->id() ); ); } } } /** /** * Implements hook_entity_bundle_delete(). * Implements hook_entity_bundle_delete(). Loading src/EntityHelper.php +17 −10 Original line number Original line Diff line number Diff line Loading @@ -5,6 +5,7 @@ namespace Drupal\simple_sitemap; use Drupal\Core\Entity\ContentEntityTypeInterface; use Drupal\Core\Entity\ContentEntityTypeInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Database\Connection; use Drupal\Core\Database\Connection; use Drupal\Core\Url; use Drupal\Core\Url; Loading Loading @@ -105,17 +106,23 @@ class EntityHelper { * Objects of entity types that can be indexed by the sitemap. * Objects of entity types that can be indexed by the sitemap. */ */ public function getSupportedEntityTypes() { public function getSupportedEntityTypes() { return array_filter($this->entityTypeManager->getDefinitions(), [$this, 'supports']); } /** @var \Drupal\Core\Entity\ContentEntityTypeInterface[] $entity_types */ /** $entity_types = $this->entityTypeManager->getDefinitions(); * Determines if an entity type is supported or not. foreach ($entity_types as $entity_type_id => $entity_type) { * * @return bool * TRUE if entity type supported by Simple Sitemap, FALSE if not. */ public function supports(EntityTypeInterface $entity_type) { if (!$entity_type instanceof ContentEntityTypeInterface if (!$entity_type instanceof ContentEntityTypeInterface || !method_exists($entity_type, 'getBundleEntityType') || !method_exists($entity_type, 'getBundleEntityType') || !$entity_type->hasLinkTemplate('canonical')) { || !$entity_type->hasLinkTemplate('canonical')) { unset($entity_types[$entity_type_id]); return FALSE; } } } return $entity_types; return TRUE; } } /** /** Loading Loading
simple_sitemap.module +10 −5 Original line number Original line Diff line number Diff line Loading @@ -195,12 +195,17 @@ function simple_sitemap_configurable_language_delete(ConfigurableLanguageInterfa */ */ function simple_sitemap_entity_delete(EntityInterface $entity) { function simple_sitemap_entity_delete(EntityInterface $entity) { /** @var \Drupal\simple_sitemap\EntityHelper $entity_helper */ $entity_helper = \Drupal::service('simple_sitemap.entity_helper'); if ($entity_helper->supports($entity->getEntityType())) { /** @var \Drupal\simple_sitemap\Simplesitemap $generator */ /** @var \Drupal\simple_sitemap\Simplesitemap $generator */ $generator = \Drupal::service('simple_sitemap.generator'); $generator = \Drupal::service('simple_sitemap.generator'); $generator->setVariants(TRUE)->removeEntityInstanceSettings( $generator->setVariants(TRUE)->removeEntityInstanceSettings( $entity->getEntityTypeId(), $entity->id() $entity->getEntityTypeId(), $entity->id() ); ); } } } /** /** * Implements hook_entity_bundle_delete(). * Implements hook_entity_bundle_delete(). Loading
src/EntityHelper.php +17 −10 Original line number Original line Diff line number Diff line Loading @@ -5,6 +5,7 @@ namespace Drupal\simple_sitemap; use Drupal\Core\Entity\ContentEntityTypeInterface; use Drupal\Core\Entity\ContentEntityTypeInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Database\Connection; use Drupal\Core\Database\Connection; use Drupal\Core\Url; use Drupal\Core\Url; Loading Loading @@ -105,17 +106,23 @@ class EntityHelper { * Objects of entity types that can be indexed by the sitemap. * Objects of entity types that can be indexed by the sitemap. */ */ public function getSupportedEntityTypes() { public function getSupportedEntityTypes() { return array_filter($this->entityTypeManager->getDefinitions(), [$this, 'supports']); } /** @var \Drupal\Core\Entity\ContentEntityTypeInterface[] $entity_types */ /** $entity_types = $this->entityTypeManager->getDefinitions(); * Determines if an entity type is supported or not. foreach ($entity_types as $entity_type_id => $entity_type) { * * @return bool * TRUE if entity type supported by Simple Sitemap, FALSE if not. */ public function supports(EntityTypeInterface $entity_type) { if (!$entity_type instanceof ContentEntityTypeInterface if (!$entity_type instanceof ContentEntityTypeInterface || !method_exists($entity_type, 'getBundleEntityType') || !method_exists($entity_type, 'getBundleEntityType') || !$entity_type->hasLinkTemplate('canonical')) { || !$entity_type->hasLinkTemplate('canonical')) { unset($entity_types[$entity_type_id]); return FALSE; } } } return $entity_types; return TRUE; } } /** /** Loading