function content_sync_entity_update in Content Synchronization 8
Same name and namespace in other branches
- 8.2 content_sync.module \content_sync_entity_update()
- 3.0.x content_sync.module \content_sync_entity_update()
hook_entity_update Keep the content snapshot table synced
1 call to content_sync_entity_update()
- content_sync_entity_insert in ./
content_sync.module - hook_entity_insert Keep the content snapshot table synced
File
- ./
content_sync.module, line 203 - Allows site administrators to modify content.
Code
function content_sync_entity_update(Drupal\Core\Entity\EntityInterface $entity) {
// Get submitted values
$entity_type = $entity
->getEntityTypeId();
$entity_bundle = $entity
->Bundle();
$entity_id = $entity
->id();
//Validate that it is a Content Entity
$entityTypeManager = \Drupal::entityTypeManager();
$instances = $entityTypeManager
->getDefinitions();
if (isset($instances[$entity_type]) && $instances[$entity_type] instanceof ContentEntityType) {
// Store the data for diff
module_load_include('inc', 'content_sync', 'content_sync.batch');
$new_entity = _content_sync_db_to_entity($entity_type, $entity_bundle, $entity_id);
// Create the name
$name = $entity_type . "." . $entity_bundle . "." . $new_entity['values'][0]['uuid'][0]['value'];
//Insert/Update Data
$activeStorage = new Drupal\Core\Config\DatabaseStorage(\Drupal::database(), 'cs_db_snapshot');
$activeStorage
->write($name, $new_entity);
}
}