function editor_test_file_presave

Same name and namespace in other branches
  1. 9 core/modules/editor/tests/modules/editor_test/editor_test.module \editor_test_file_presave()
  2. 10 core/modules/editor/tests/modules/editor_test/editor_test.module \editor_test_file_presave()
  3. 11.x core/modules/editor/tests/modules/editor_test/editor_test.module \editor_test_file_presave()

Implements hook_ENTITY_TYPE_presave() for file entities.

File

core/modules/editor/tests/modules/editor_test.module, line 52

Code

function editor_test_file_presave(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.