1 filter.module | filter_entity_update(EntityInterface $entity) |
Implements hook_entity_update().
File
- core/
modules/ filter/ filter.module, line 1724 - Framework for handling the filtering of content.
Code
function filter_entity_update(EntityInterface $entity) {
// On new revisions, all files are considered to be a new usage and no
// deletion of previous file usages are necessary.
$entity_info = entity_get_info($entity->entityType());
$vid_key = isset($entity_info['entity keys']['revision']) ? $entity_info['entity keys']['revision'] : NULL;
if (!empty($entity->original)) {
if ($vid_key && $entity->$vid_key != $entity->original->$vid_key) {
$referenced_files_by_field = _filter_get_file_ids_by_field($entity);
foreach ($referenced_files_by_field as $field => $fids) {
_filter_record_file_usage($fids, $entity);
}
}
// On modified revisions, detect which file references have been added (and
// record their usage) and which ones have been removed (delete their usage).
// File references that existed both in the previous version of the revision
// and in the new one don't need their usage to be updated.
else {
$original_fids_by_field = _filter_get_file_ids_by_field($entity->original);
$fids_by_field = _filter_get_file_ids_by_field($entity);
// Detect file usages that should be incremented.
foreach ($fids_by_field as $field => $fids) {
$added_files = array_diff($fids_by_field[$field], $original_fids_by_field[$field]);
_filter_record_file_usage($added_files, $entity);
}
// Detect file usages that should be decremented.
foreach ($original_fids_by_field as $field => $fids) {
$removed_files = array_diff($original_fids_by_field[$field], $fids_by_field[$field]);
_filter_delete_file_usage($removed_files, $entity, 1);
}
}
}
}