Chris@0: getFilename()) { Chris@0: $errors[] = t("The file's name is empty. Please give a name to the file."); Chris@0: } Chris@0: if (strlen($file->getFilename()) > 255) { Chris@0: $errors[] = t("The file's name exceeds the 255 characters limit. Please rename the file and try again."); Chris@0: } Chris@0: Chris@0: return $errors; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Respond to a file that has been copied. Chris@0: * Chris@0: * @param \Drupal\file\FileInterface $file Chris@0: * The newly copied file entity. Chris@0: * @param \Drupal\file\FileInterface $source Chris@0: * The original file before the copy. Chris@0: * Chris@0: * @see file_copy() Chris@0: */ Chris@0: function hook_file_copy(Drupal\file\FileInterface $file, Drupal\file\FileInterface $source) { Chris@0: // Make sure that the file name starts with the owner's user name. Chris@0: if (strpos($file->getFilename(), $file->getOwner()->name) !== 0) { Chris@0: $file->setFilename($file->getOwner()->name . '_' . $file->getFilename()); Chris@0: $file->save(); Chris@0: Chris@0: \Drupal::logger('file')->notice('Copied file %source has been renamed to %destination', ['%source' => $source->filename, '%destination' => $file->getFilename()]); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Respond to a file that has been moved. Chris@0: * Chris@0: * @param \Drupal\file\FileInterface $file Chris@0: * The updated file entity after the move. Chris@0: * @param \Drupal\file\FileInterface $source Chris@0: * The original file entity before the move. Chris@0: * Chris@0: * @see file_move() Chris@0: */ Chris@0: function hook_file_move(Drupal\file\FileInterface $file, Drupal\file\FileInterface $source) { Chris@0: // Make sure that the file name starts with the owner's user name. Chris@0: if (strpos($file->getFilename(), $file->getOwner()->name) !== 0) { Chris@0: $file->setFilename($file->getOwner()->name . '_' . $file->getFilename()); Chris@0: $file->save(); Chris@0: Chris@0: \Drupal::logger('file')->notice('Moved file %source has been renamed to %destination', ['%source' => $source->filename, '%destination' => $file->getFilename()]); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * @} End of "addtogroup hooks". Chris@0: */