editor_entity_update(EntityInterface $entity)
Implements hook_entity_update().
File
- core/modules/editor/editor.module, line 362
- Adds bindings for client-side "text editors" to text formats.
Code
function editor_entity_update(EntityInterface $entity) { // Only act on content entities. if (!($entity instanceof FieldableEntityInterface)) { return; } // On new revisions, all files are considered to be a new usage and no // deletion of previous file usages are necessary. if (!empty($entity->original) && $entity->getRevisionId() != $entity->original->getRevisionId()) { $referenced_files_by_field = _editor_get_file_uuids_by_field($entity); foreach ($referenced_files_by_field as $field => $uuids) { _editor_record_file_usage($uuids, $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_uuids_by_field = _editor_get_file_uuids_by_field($entity->original); $uuids_by_field = _editor_get_file_uuids_by_field($entity); // Detect file usages that should be incremented. foreach ($uuids_by_field as $field => $uuids) { $added_files = array_diff($uuids_by_field[$field], $original_uuids_by_field[$field]); _editor_record_file_usage($added_files, $entity); } // Detect file usages that should be decremented. foreach ($original_uuids_by_field as $field => $uuids) { $removed_files = array_diff($original_uuids_by_field[$field], $uuids_by_field[$field]); _editor_delete_file_usage($removed_files, $entity, 1); } } }
Please login to continue.