public function ImportEntityManager::entityPresave in Acquia Content Hub 8
Act on the entity's presave action.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity that is being saved.
File
- src/
ImportEntityManager.php, line 277
Class
- ImportEntityManager
- Provides a service for managing imported entities' actions.
Namespace
Drupal\acquia_contenthubCode
public function entityPresave(EntityInterface $entity) {
// Early return, if the entity doesn't have an older version or if it is
// already sync'ing.
if (!isset($entity->original) || !empty($entity->__contenthub_entity_syncing)) {
return;
}
// Find the top-level host entity's import entity.
$imported_entity = $this
->findRootAncestorImportEntity($entity);
// Early return, if the entity is not an imported entity, or it is not
// "pending sync" or "has local change".
if (!$imported_entity || $imported_entity
->isPendingSync() || $imported_entity
->hasLocalChange()) {
return;
}
$has_local_change = $this
->compareRevisions($entity) || $this
->compareReferencedEntities($entity);
// Don't do anything else if there is no local change.
if (!$has_local_change) {
return;
}
// Set and store the imported entity as having local changes.
$imported_entity
->setLocalChange();
$imported_entity
->save();
}