function hook_file_create

Act on a newly created file.

This hook runs after a new file object has just been instantiated. It can be used to set initial values, e.g. to provide defaults.

Parameters

\Drupal\file\Plugin\Core\Entity\File $file: The file object.

2 functions implement hook_file_create()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

entity_crud_hook_test_file_create in drupal/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module
Implements hook_file_create().
locale_translate_file_create in drupal/core/modules/locale/locale.bulk.inc
Creates a file object and populates the timestamp property.

File

drupal/core/modules/file/file.api.php, line 18
Hooks for file module.

Code

function hook_file_create(\Drupal\file\Plugin\Core\Entity\File $file) {
  if (!isset($file->foo)) {
    $file->foo = 'some_initial_value';
  }
}