Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d7 / hook / file_update.twig
diff --git a/vendor/chi-teck/drupal-code-generator/templates/d7/hook/file_update.twig b/vendor/chi-teck/drupal-code-generator/templates/d7/hook/file_update.twig
new file mode 100644 (file)
index 0000000..b8064d1
--- /dev/null
@@ -0,0 +1,14 @@
+/**
+ * Implements hook_file_update().
+ */
+function {{ machine_name }}_file_update($file) {
+  $file_user = user_load($file->uid);
+  // Make sure that the file name starts with the owner's user name.
+  if (strpos($file->filename, $file_user->name) !== 0) {
+    $old_filename = $file->filename;
+    $file->filename = $file_user->name . '_' . $file->filename;
+    $file->save();
+
+    watchdog('file', t('%source has been renamed to %destination', array('%source' => $old_filename, '%destination' => $file->filename)));
+  }
+}