function EditorHooks::entityUpdate
Same name and namespace in other branches
- 11.x core/modules/editor/src/Hook/EditorHooks.php \Drupal\editor\Hook\EditorHooks::entityUpdate()
Implements hook_entity_update().
Attributes
#[Hook('entity_update')]
File
-
core/
modules/ editor/ src/ Hook/ EditorHooks.php, line 210
Class
- EditorHooks
- Hook implementations for editor.
Namespace
Drupal\editor\HookCode
public function entityUpdate(EntityInterface $entity) : void {
// 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 ($entity->getOriginal() && $entity->getRevisionId() != $entity->getOriginal()
->getRevisionId()) {
$referenced_files_by_field = $this->getFileUuidsByField($entity);
foreach ($referenced_files_by_field as $uuids) {
$this->recordFileUsage($uuids, $entity);
}
}
else {
$original_uuids_by_field = !$entity->getOriginal() ? [] : $this->getFileUuidsByField($entity->getOriginal());
$uuids_by_field = $this->getFileUuidsByField($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)) {
$this->recordFileUsage($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]);
$this->deleteFileUsage($removed_files, $entity, 1);
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.