You are here

function content_sync_entity_delete in Content Synchronization 8.2

Same name and namespace in other branches
  1. 8 content_sync.module \content_sync_entity_delete()
  2. 3.0.x content_sync.module \content_sync_entity_delete()

Implements hook_entity_delete().

Keep the content snapshot table synced.

File

./content_sync.module, line 243
Allows site administrators to modify content.

Code

function content_sync_entity_delete(EntityInterface $entity) {

  // Get submitted values.
  $entity_type = $entity
    ->getEntityTypeId();
  $entity_bundle = $entity
    ->Bundle();
  $entity_uuid = $entity
    ->uuid();

  // Validate that it is a Content Entity.
  $entityTypeManager = \Drupal::entityTypeManager();
  $instances = $entityTypeManager
    ->getDefinitions();
  if (isset($instances[$entity_type]) && $instances[$entity_type] instanceof ContentEntityType) {

    // Update the data for diff.
    $name = $entity_type . "." . $entity_bundle . "." . $entity_uuid;

    // Delete Data.
    $activeStorage = new ContentDatabaseStorage(\Drupal::database(), 'cs_db_snapshot');
    $activeStorage
      ->cs_delete($name);

    // Invalidate the CS Cache of the entity.
    $cache = \Drupal::cache('content')
      ->invalidate($entity_type . "." . $entity_bundle . ":" . $name);
  }
}