You are here

function content_sync_entity_delete in Content Synchronization 8

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

hook_entity_delete Keep the content snapshot table synced

File

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

Code

function content_sync_entity_delete(Drupal\Core\Entity\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 Drupal\Core\Config\DatabaseStorage(\Drupal::database(), 'cs_db_snapshot');
    $activeStorage
      ->delete($name);
  }
}