You are here

function editor_test_file_presave in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/editor/tests/modules/editor_test.module \editor_test_file_presave()
  2. 9 core/modules/editor/tests/modules/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 88
Helper module for the Text Editor tests.

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);
}