X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fchi-teck%2Fdrupal-code-generator%2Ftemplates%2Fd8%2Fhook%2Ffile_copy.twig;fp=vendor%2Fchi-teck%2Fdrupal-code-generator%2Ftemplates%2Fd8%2Fhook%2Ffile_copy.twig;h=1fa6532b10a9a1177602fc4101bd43b64f3968ce;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/chi-teck/drupal-code-generator/templates/d8/hook/file_copy.twig b/vendor/chi-teck/drupal-code-generator/templates/d8/hook/file_copy.twig new file mode 100644 index 000000000..1fa6532b1 --- /dev/null +++ b/vendor/chi-teck/drupal-code-generator/templates/d8/hook/file_copy.twig @@ -0,0 +1,12 @@ +/** + * Implements hook_file_copy(). + */ +function {{ machine_name }}_file_copy(Drupal\file\FileInterface $file, Drupal\file\FileInterface $source) { + // Make sure that the file name starts with the owner's user name. + if (strpos($file->getFilename(), $file->getOwner()->name) !== 0) { + $file->setFilename($file->getOwner()->name . '_' . $file->getFilename()); + $file->save(); + + \Drupal::logger('file')->notice('Copied file %source has been renamed to %destination', ['%source' => $source->filename, '%destination' => $file->getFilename()]); + } +}