Commit e1906c77 authored by gbyte.co's avatar gbyte.co

Issue #3062747 by alexpott, daniel.bosen, gbyte.co: Concurrent update of media...

Issue #3062747 by alexpott, daniel.bosen, gbyte.co: Concurrent update of media module and simple_sitemap 2.x to 3.x fails
parent cfd5070d
...@@ -195,11 +195,16 @@ function simple_sitemap_configurable_language_delete(ConfigurableLanguageInterfa ...@@ -195,11 +195,16 @@ 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\Simplesitemap $generator */ /** @var \Drupal\simple_sitemap\EntityHelper $entity_helper */
$generator = \Drupal::service('simple_sitemap.generator'); $entity_helper = \Drupal::service('simple_sitemap.entity_helper');
$generator->setVariants(TRUE)->removeEntityInstanceSettings( if ($entity_helper->supports($entity->getEntityType())) {
$entity->getEntityTypeId(), $entity->id()
); /** @var \Drupal\simple_sitemap\Simplesitemap $generator */
$generator = \Drupal::service('simple_sitemap.generator');
$generator->setVariants(TRUE)->removeEntityInstanceSettings(
$entity->getEntityTypeId(), $entity->id()
);
}
} }
/** /**
......
...@@ -5,6 +5,7 @@ namespace Drupal\simple_sitemap; ...@@ -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;
...@@ -105,18 +106,24 @@ class EntityHelper { ...@@ -105,18 +106,24 @@ 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) { *
if (!$entity_type instanceof ContentEntityTypeInterface * @return bool
|| !method_exists($entity_type, 'getBundleEntityType') * TRUE if entity type supported by Simple Sitemap, FALSE if not.
|| !$entity_type->hasLinkTemplate('canonical')) { */
unset($entity_types[$entity_type_id]); public function supports(EntityTypeInterface $entity_type) {
} if (!$entity_type instanceof ContentEntityTypeInterface
|| !method_exists($entity_type, 'getBundleEntityType')
|| !$entity_type->hasLinkTemplate('canonical')) {
return FALSE;
} }
return $entity_types;
} return TRUE;
}
/** /**
* Checks whether an entity type does not provide bundles. * Checks whether an entity type does not provide bundles.
......
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