@trigger_error(__FUNCTION__.'() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use the \'file.validator\' service instead. See https://www.drupal.org/node/3363700',E_USER_DEPRECATED);
@trigger_error(__FUNCTION__.'() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use the \'file.validator\' service instead. See https://www.drupal.org/node/3363700',E_USER_DEPRECATED);
$errors=[];
if(!$file->getFilename()){
$errors[]=t("The file's name is empty. Enter a name for the file.");
}
if(strlen($file->getFilename())>240){
$errors[]=t("The file's name exceeds the 240 characters limit. Rename the file and try again.");
}
return$errors;
}
/**
* Checks that the filename ends with an allowed extension.
*
* @param \Drupal\file\FileInterface $file
* A file entity.
* @param string $extensions
* A string with a space separated list of allowed extensions.
*
* @return array
* An empty array if the file extension is allowed or an array containing an
* error message if it's not.
*
* @deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use the
@trigger_error(__FUNCTION__.'() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use the \'file.validator\' service instead. See https://www.drupal.org/node/3363700',E_USER_DEPRECATED);
@trigger_error(__FUNCTION__.'() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use the \'file.validator\' service instead. See https://www.drupal.org/node/3363700',E_USER_DEPRECATED);
$user=\Drupal::currentUser();
$errors=[];
if($file_limit&&$file->getSize()>$file_limit){
$errors[]=t('The file is %filesize exceeding the maximum file size of %maxsize.',[
@trigger_error(__FUNCTION__.'() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use the \'file.validator\' service instead. See https://www.drupal.org/node/3363700',E_USER_DEPRECATED);
@trigger_error(__FUNCTION__.'() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use the \'file.validator\' service instead. See https://www.drupal.org/node/3363700',E_USER_DEPRECATED);
$errors=[];
// Check first that the file is an image.
$image_factory=\Drupal::service('image.factory');
$image=$image_factory->get($file->getFileUri());
if($image->isValid()){
$scaling=FALSE;
if($maximum_dimensions){
// Check that it is smaller than the given dimensions.
// Update the file size now that the image has been resized.
$file->setSize($image->getFileSize());
if(!empty($width)&&!empty($height)){
$message=t('The image was resized to fit within the maximum allowed dimensions of %dimensions pixels. The new dimensions of the resized image are %new_widthx%new_height pixels.',
[
'%dimensions'=>$maximum_dimensions,
'%new_width'=>$image->getWidth(),
'%new_height'=>$image->getHeight(),
]);
}
elseif(empty($width)){
$message=t('The image was resized to fit within the maximum allowed height of %height pixels. The new dimensions of the resized image are %new_widthx%new_height pixels.',
[
'%height'=>$height,
'%new_width'=>$image->getWidth(),
'%new_height'=>$image->getHeight(),
]);
}
elseif(empty($height)){
$message=t('The image was resized to fit within the maximum allowed width of %width pixels. The new dimensions of the resized image are %new_widthx%new_height pixels.',
[
'%width'=>$width,
'%new_width'=>$image->getWidth(),
'%new_height'=>$image->getHeight(),
]);
}
\Drupal::messenger()->addStatus($message);
}
else{
$errors[]=t('The image exceeds the maximum allowed dimensions and an attempt to resize it failed.');
}
}
}
if($minimum_dimensions){
// Check that it is larger than the given dimensions.
$errors[]=t('The resized image is too small. The minimum dimensions are %dimensions pixels and after resizing, the image size will be %widthx%height pixels.',
[
'%dimensions'=>$minimum_dimensions,
'%width'=>$image->getWidth(),
'%height'=>$image->getHeight(),
]);
}
else{
$errors[]=t('The image is too small. The minimum dimensions are %dimensions pixels and the image size is %widthx%height pixels.',
[
'%dimensions'=>$minimum_dimensions,
'%width'=>$image->getWidth(),
'%height'=>$image->getHeight(),
]);
}
}
}
}
return$errors;
}
/**
* Examines a file entity and returns appropriate content headers for download.
*
@@ -589,7 +306,7 @@ function _file_save_upload_from_form(array $element, FormStateInterface $form_st
* If the array is empty, it will be set up to call file_validate_extensions()
* with a safe list of extensions, as follows: "jpg jpeg gif png txt doc
* xls pdf ppt pps odt ods odp". To allow all extensions, you must explicitly
* set this array to ['file_validate_extensions' => '']. (Beware: this is not
* set this array to ['FileExtension' => []]. (Beware: this is not
* safe and should only be allowed for trusted users, if at all.)
* @param string|false $destination
* (optional) A string containing the URI that the file should be copied to.
* Determines the preferred upload progress implementation.
*
* @return string|false
* A string indicating which upload progress system is available. Either "apc"
* or "uploadprogress". If neither are available, returns FALSE.
*
* @deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use
* extension_loaded('uploadprogress') instead.
*
* @see https://www.drupal.org/node/3397577
*/
functionfile_progress_implementation(){
@trigger_error(__FUNCTION__.'() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use extension_loaded(\'uploadprogress\') instead. See https://www.drupal.org/node/3397577',E_USER_DEPRECATED);
static$implementation;
if(!isset($implementation)){
$implementation=FALSE;
// We prefer the PECL extension uploadprogress because it supports multiple
// simultaneous uploads. APCu only supports one at a time.
if(extension_loaded('uploadprogress')){
$implementation='uploadprogress';
}
}
return$implementation;
}
/**
* Implements hook_ENTITY_TYPE_predelete() for file entities.
*/
@@ -1239,32 +929,18 @@ function template_preprocess_file_upload_help(&$variables) {
@trigger_error('\'file_validate_size\' is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use the \'FileSizeLimit\' constraint instead. See https://www.drupal.org/node/3363700',E_USER_DEPRECATED);
@trigger_error('\'file_validate_extensions\' is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use the \'FileExtension\' constraint instead. See https://www.drupal.org/node/3363700',E_USER_DEPRECATED);
@trigger_error('\'file_validate_image_resolution\' is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use the \'FileImageDimensions\' constraint instead. See https://www.drupal.org/node/3363700',E_USER_DEPRECATED);
@trigger_error(__FUNCTION__.'() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use \Drupal\file\IconMimeTypes::getIconClass() instead. See https://www.drupal.org/node/3411269',E_USER_DEPRECATED);
returnIconMimeTypes::getIconClass($mime_type);
}
/**
* Determines the generic icon MIME package based on a file's MIME type.
*
* @param string $mime_type
* A MIME type.
*
* @return string|false
* The generic icon MIME package expected for this file.
*
* @deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use
@trigger_error(__FUNCTION__.'() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use \Drupal\file\IconMimeTypes::getGenericMimeType() instead. See https://www.drupal.org/node/3411269',E_USER_DEPRECATED);
@trigger_error('\'file_validate_extensions\' is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use the \'FileExtension\' constraint instead. See https://www.drupal.org/node/3363700',E_USER_DEPRECATED);