function editor_entity_update
Same name in other branches
- 8.9.x core/modules/editor/editor.module \editor_entity_update()
- 10 core/modules/editor/editor.module \editor_entity_update()
Implements hook_entity_update().
File
-
core/
modules/ editor/ editor.module, line 369
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 $uuids) {
_editor_record_file_usage($uuids, $entity);
}
}
else {
$original_uuids_by_field = empty($entity->original) ? [] : _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) {
$original_uuids = $original_uuids_by_field[$field] ?? [];
if ($added_files = array_diff($uuids_by_field[$field], $original_uuids)) {
_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);
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.