function EditorTestHooks::filePresave
Implements hook_ENTITY_TYPE_presave() for file entities.
File
-
core/
modules/ editor/ tests/ modules/ editor_test/ src/ Hook/ EditorTestHooks.php, line 91
Class
- EditorTestHooks
- Hook implementations for editor_test.
Namespace
Drupal\editor_test\HookCode
public function filePresave(FileInterface $file) {
// Use state to keep track of how many times a file is saved.
$file_save_count = \Drupal::state()->get('editor_test.file_save_count', []);
$file_save_count[$file->getFilename()] = isset($file_save_count[$file->getFilename()]) ? $file_save_count[$file->getFilename()] + 1 : 1;
\Drupal::state()->set('editor_test.file_save_count', $file_save_count);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.