summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJennifer Hodgdon2012-11-27 07:35:31 -0800
committerJennifer Hodgdon2012-11-27 07:35:31 -0800
commitd6ada284da144566b37efd41276f30f3d2add296 (patch)
tree826ebdfb461c0ca3668baa0b5b3ebbb81ee9efa2
parentaf230648a1b98c8af5be75d2056cb0b79ac570e7 (diff)
Issue #1173322 by javier_: Add function bodies to file hook documentation
-rw-r--r--core/modules/file/file.api.php24
1 files changed, 23 insertions, 1 deletions
diff --git a/core/modules/file/file.api.php b/core/modules/file/file.api.php
index c0b0d52..fb59229 100644
--- a/core/modules/file/file.api.php
+++ b/core/modules/file/file.api.php
@@ -97,7 +97,15 @@ function hook_file_insert(Drupal\file\File $file) {
* The file that has just been updated.
*/
function hook_file_update(Drupal\file\File $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)));
+ }
}
/**
@@ -111,7 +119,14 @@ function hook_file_update(Drupal\file\File $file) {
* @see file_copy()
*/
function hook_file_copy(Drupal\file\File $file, Drupal\file\File $source) {
+ $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) {
+ $file->filename = $file_user->name . '_' . $file->filename;
+ $file->save();
+ watchdog('file', t('Copied file %source has been renamed to %destination', array('%source' => $source->filename, '%destination' => $file->filename)));
+ }
}
/**
@@ -125,7 +140,14 @@ function hook_file_copy(Drupal\file\File $file, Drupal\file\File $source) {
* @see file_move()
*/
function hook_file_move(Drupal\file\File $file, Drupal\file\File $source) {
+ $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) {
+ $file->filename = $file_user->name . '_' . $file->filename;
+ $file->save();
+ watchdog('file', t('Moved file %source has been renamed to %destination', array('%source' => $source->filename, '%destination' => $file->filename)));
+ }
}
/**