X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fentity_browser%2Fsrc%2FPlugin%2FField%2FFieldWidget%2FFileBrowserWidget.php;fp=web%2Fmodules%2Fcontrib%2Fentity_browser%2Fsrc%2FPlugin%2FField%2FFieldWidget%2FFileBrowserWidget.php;h=ecb07fa4584826cd5a43a40ddc345ec2c2d44d1e;hb=eba34333e3c89f208d2f72fa91351ad019a71583;hp=7d8764576f2ea56108d1780192b82d5e0243c955;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/modules/contrib/entity_browser/src/Plugin/Field/FieldWidget/FileBrowserWidget.php b/web/modules/contrib/entity_browser/src/Plugin/Field/FieldWidget/FileBrowserWidget.php index 7d8764576..ecb07fa45 100644 --- a/web/modules/contrib/entity_browser/src/Plugin/Field/FieldWidget/FileBrowserWidget.php +++ b/web/modules/contrib/entity_browser/src/Plugin/Field/FieldWidget/FileBrowserWidget.php @@ -433,23 +433,27 @@ class FileBrowserWidget extends EntityReferenceBrowserWidget { * * This is a combination of logic shared between the File and Image widgets. * + * @param bool $upload + * Whether or not upload-specific validators should be returned. + * * @return array * An array suitable for passing to file_save_upload() or the file field * element's '#upload_validators' property. */ - public function getFileValidators() { + public function getFileValidators($upload = FALSE) { $validators = []; $settings = $this->fieldDefinition->getSettings(); - // Cap the upload size according to the PHP limit. - $max_filesize = Bytes::toInt(file_upload_max_size()); - if (!empty($settings['max_filesize'])) { - $max_filesize = min($max_filesize, Bytes::toInt($settings['max_filesize'])); + if ($upload) { + // Cap the upload size according to the PHP limit. + $max_filesize = Bytes::toInt(file_upload_max_size()); + if (!empty($settings['max_filesize'])) { + $max_filesize = min($max_filesize, Bytes::toInt($settings['max_filesize'])); + } + // There is always a file size limit due to the PHP server limit. + $validators['file_validate_size'] = [$max_filesize]; } - // There is always a file size limit due to the PHP server limit. - $validators['file_validate_size'] = [$max_filesize]; - // Images have expected defaults for file extensions. // See \Drupal\image\Plugin\Field\FieldWidget::formElement() for details. if ($this->fieldDefinition->getType() == 'image') { @@ -463,7 +467,7 @@ class FileBrowserWidget extends EntityReferenceBrowserWidget { $validators['file_validate_extensions'] = [$settings['file_extensions']]; } - // Add upload resolution validation. + // Add resolution validation. if ($settings['max_resolution'] || $settings['min_resolution']) { $validators['entity_browser_file_validate_image_resolution'] = [$settings['max_resolution'], $settings['min_resolution']]; } @@ -479,9 +483,9 @@ class FileBrowserWidget extends EntityReferenceBrowserWidget { $settings = $this->fieldDefinition->getSettings(); // Add validators based on our current settings. $data['validators']['file'] = ['validators' => $this->getFileValidators()]; - // Provide context for widgets to enhance their configuration. Currently - // we only know that "upload_location" is used. + // Provide context for widgets to enhance their configuration. $data['widget_context']['upload_location'] = $settings['uri_scheme'] . '://' . $settings['file_directory']; + $data['widget_context']['upload_validators'] = $this->getFileValidators(TRUE); return $data; }