Commit e1906c77 authored by Pawel G's avatar Pawel G
Browse files

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
Loading
Loading
Loading
Loading
+10 −5
Original line number Original line Diff line number Diff line
@@ -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().
+17 −10
Original line number Original line Diff line number Diff line
@@ -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,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;
   }
   }


  /**
  /**