update drupal

This commit is contained in:
Tessier
2020-10-15 11:59:37 +02:00
parent ebb5db14b5
commit d8b9162932
558 changed files with 5954 additions and 4475 deletions
+5 -4
View File
@@ -961,18 +961,19 @@ function file_save_upload($form_field_name, $validators = [], $destination = FAL
*/
function _file_save_upload_single(\SplFileInfo $file_info, $form_field_name, $validators = [], $destination = FALSE, $replace = FileSystemInterface::EXISTS_REPLACE) {
$user = \Drupal::currentUser();
$original_file_name = trim($file_info->getClientOriginalName(), '.');
// Check for file upload errors and return FALSE for this file if a lower
// level system error occurred. For a complete list of errors:
// See http://php.net/manual/features.file-upload.errors.php.
switch ($file_info->getError()) {
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
\Drupal::messenger()->addError(t('The file %file could not be saved because it exceeds %maxsize, the maximum allowed size for uploads.', ['%file' => $file_info->getFilename(), '%maxsize' => format_size(Environment::getUploadMaxSize())]));
\Drupal::messenger()->addError(t('The file %file could not be saved because it exceeds %maxsize, the maximum allowed size for uploads.', ['%file' => $original_file_name, '%maxsize' => format_size(Environment::getUploadMaxSize())]));
return FALSE;
case UPLOAD_ERR_PARTIAL:
case UPLOAD_ERR_NO_FILE:
\Drupal::messenger()->addError(t('The file %file could not be saved because the upload did not complete.', ['%file' => $file_info->getFilename()]));
\Drupal::messenger()->addError(t('The file %file could not be saved because the upload did not complete.', ['%file' => $original_file_name]));
return FALSE;
case UPLOAD_ERR_OK:
@@ -984,7 +985,7 @@ function _file_save_upload_single(\SplFileInfo $file_info, $form_field_name, $va
default:
// Unknown error
\Drupal::messenger()->addError(t('The file %file could not be saved. An unknown error has occurred.', ['%file' => $file_info->getFilename()]));
\Drupal::messenger()->addError(t('The file %file could not be saved. An unknown error has occurred.', ['%file' => $original_file_name]));
return FALSE;
}
@@ -992,7 +993,7 @@ function _file_save_upload_single(\SplFileInfo $file_info, $form_field_name, $va
$values = [
'uid' => $user->id(),
'status' => 0,
'filename' => trim($file_info->getClientOriginalName(), '.'),
'filename' => $original_file_name,
'uri' => $file_info->getRealPath(),
'filesize' => $file_info->getSize(),
];
@@ -96,6 +96,10 @@ class ManagedFile extends FormElement {
foreach ($input['fids'] as $fid) {
if ($file = File::load($fid)) {
$fids[] = $file->id();
if (!$file->access('download')) {
$force_default = TRUE;
break;
}
// Temporary files that belong to other users should never be
// allowed.
if ($file->isTemporary()) {
@@ -2,8 +2,6 @@
namespace Drupal\Tests\file\Functional;
use Drupal\Core\Entity\Plugin\Validation\Constraint\ReferenceAccessConstraint;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\file\Entity\File;
use Drupal\node\Entity\NodeType;
use Drupal\user\RoleInterface;
@@ -92,11 +90,10 @@ class FilePrivateTest extends FileFieldTestBase {
$this->drupalGet('node/' . $new_node->id() . '/edit');
$this->getSession()->getPage()->find('css', 'input[name="' . $field_name . '[0][fids]"]')->setValue($node_file->id());
$this->getSession()->getPage()->pressButton(t('Save'));
// Make sure the form submit failed - we stayed on the edit form.
$this->assertUrl('node/' . $new_node->id() . '/edit');
// Check that we got the expected constraint form error.
$constraint = new ReferenceAccessConstraint();
$this->assertRaw(new FormattableMarkup($constraint->message, ['%type' => 'file', '%id' => $node_file->id()]));
$this->assertUrl('node/' . $new_node->id());
// Make sure the submitted hidden file field is empty.
$new_node = \Drupal::entityTypeManager()->getStorage('node')->loadUnchanged($new_node->id());
$this->assertTrue($new_node->get($field_name)->isEmpty());
// Attempt to reuse the existing file when creating a new node, and confirm
// that access is still denied.
$edit = [];
@@ -107,9 +104,10 @@ class FilePrivateTest extends FileFieldTestBase {
$this->getSession()->getPage()->find('css', 'input[name="' . $field_name . '[0][fids]"]')->setValue($node_file->id());
$this->getSession()->getPage()->pressButton(t('Save'));
$new_node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
$this->assertTrue(empty($new_node), 'Node was not created.');
$this->assertUrl('node/add/' . $type_name);
$this->assertRaw(new FormattableMarkup($constraint->message, ['%type' => 'file', '%id' => $node_file->id()]));
$this->assertUrl('node/' . $new_node->id());
// Make sure the submitted hidden file field is empty.
$new_node = \Drupal::entityTypeManager()->getStorage('node')->loadUnchanged($new_node->id());
$this->assertTrue($new_node->get($field_name)->isEmpty());
// Now make file_test_file_download() return everything.
\Drupal::state()->set('file_test.allow_all', TRUE);
@@ -28,7 +28,7 @@ class FileModuleTest extends KernelTestBase {
$file_name = $this->randomMachineName();
$file_info = $this->createMock(UploadedFile::class);
$file_info->expects($this->once())->method('getError')->willReturn(UPLOAD_ERR_FORM_SIZE);
$file_info->expects($this->once())->method('getFileName')->willReturn($file_name);
$file_info->expects($this->once())->method('getClientOriginalName')->willReturn($file_name);
$this->assertFalse(\_file_save_upload_single($file_info, 'name'));
$expected_message = new TranslatableMarkup('The file %file could not be saved because it exceeds %maxsize, the maximum allowed size for uploads.', ['%file' => $file_name, '%maxsize' => format_size(Environment::getUploadMaxSize())]);
$this->assertEquals($expected_message, \Drupal::messenger()->all()['error'][0]);
@@ -117,6 +117,7 @@ class FileTest extends MigrateSqlSourceTestBase {
'filesize' => '3620',
'status' => '1',
'timestamp' => '1421727515',
'filepath' => 'sites/default/files/cube.jpeg',
],
];
// Do an automatic count.
@@ -143,6 +144,7 @@ class FileTest extends MigrateSqlSourceTestBase {
'filesize' => '3620',
'status' => '1',
'timestamp' => '1421727515',
'filepath' => 'sites/default/files/cube.jpeg',
],
];
// Do an automatic count.
@@ -31,7 +31,7 @@ class FieldFileTest extends UnitTestCase {
$options = [
'alt' => 'Foobaz',
'title' => 'Wambooli',
'title' => 'Bar',
];
$value = [
'fid' => 1,
@@ -45,7 +45,7 @@ class FieldFileTest extends UnitTestCase {
'display' => TRUE,
'description' => '',
'alt' => 'Foobaz',
'title' => 'Wambooli',
'title' => 'Bar',
];
$this->assertSame($expected, $transformed);
}