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
*/
function simple_sitemap_entity_delete(EntityInterface $entity) {
/** @var \Drupal\simple_sitemap\Simplesitemap $generator */
$generator = \Drupal::service('simple_sitemap.generator');
$generator->setVariants(TRUE)->removeEntityInstanceSettings(
$entity->getEntityTypeId(), $entity->id()
);
/** @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 */
$generator = \Drupal::service('simple_sitemap.generator');
$generator->setVariants(TRUE)->removeEntityInstanceSettings(
$entity->getEntityTypeId(), $entity->id()
);
}
}
/**
......
......@@ -5,6 +5,7 @@ namespace Drupal\simple_sitemap;
use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Database\Connection;
use Drupal\Core\Url;
......@@ -105,18 +106,24 @@ class EntityHelper {
* Objects of entity types that can be indexed by the sitemap.
*/
public function getSupportedEntityTypes() {
return array_filter($this->entityTypeManager->getDefinitions(), [$this, 'supports']);
}
/** @var \Drupal\Core\Entity\ContentEntityTypeInterface[] $entity_types */
$entity_types = $this->entityTypeManager->getDefinitions();
foreach ($entity_types as $entity_type_id => $entity_type) {
if (!$entity_type instanceof ContentEntityTypeInterface
|| !method_exists($entity_type, 'getBundleEntityType')
|| !$entity_type->hasLinkTemplate('canonical')) {
unset($entity_types[$entity_type_id]);
}
/**
* Determines if an entity type is supported or not.
*
* @return bool
* TRUE if entity type supported by Simple Sitemap, FALSE if not.
*/
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.
......
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