Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / hook / file_move.twig
1 /**
2  * Implements hook_file_move().
3  */
4 function {{ machine_name }}_file_move(Drupal\file\FileInterface $file, Drupal\file\FileInterface $source) {
5   // Make sure that the file name starts with the owner's user name.
6   if (strpos($file->getFilename(), $file->getOwner()->name) !== 0) {
7     $file->setFilename($file->getOwner()->name . '_' . $file->getFilename());
8     $file->save();
9
10     \Drupal::logger('file')->notice('Moved file %source has been renamed to %destination', ['%source' => $source->filename, '%destination' => $file->getFilename()]);
11   }
12 }