Issue #2894270 by xjm, seanB, chr.fritsch, Wim Leers: Users unable to add an extension to the file upload field
parent
6002539d9a
commit
4b95aa76bf
|
|
@ -17,7 +17,7 @@ settings:
|
|||
display_field: false
|
||||
display_default: false
|
||||
module: file
|
||||
locked: true
|
||||
locked: false
|
||||
cardinality: 1
|
||||
translatable: true
|
||||
indexes: { }
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ settings:
|
|||
display_default: false
|
||||
uri_scheme: public
|
||||
module: image
|
||||
locked: true
|
||||
locked: false
|
||||
cardinality: 1
|
||||
translatable: true
|
||||
indexes: { }
|
||||
|
|
|
|||
|
|
@ -240,7 +240,6 @@ abstract class MediaSourceBase extends PluginBase implements MediaSourceInterfac
|
|||
'entity_type' => 'media',
|
||||
'field_name' => $this->getSourceFieldName(),
|
||||
'type' => reset($this->pluginDefinition['allowed_field_types']),
|
||||
'locked' => TRUE,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -318,8 +318,8 @@ class MediaTypeForm extends EntityForm {
|
|||
$source_field = $source->createSourceField($media_type);
|
||||
/** @var \Drupal\field\FieldStorageConfigInterface $storage */
|
||||
$storage = $source_field->getFieldStorageDefinition();
|
||||
if ($storage->isNew() || !$storage->isLocked()) {
|
||||
$storage->setLocked(TRUE)->save();
|
||||
if ($storage->isNew()) {
|
||||
$storage->save();
|
||||
}
|
||||
$source_field->save();
|
||||
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ trait MediaFunctionalTestCreateMediaTypeTrait {
|
|||
$source_field = $source->createSourceField($media_type);
|
||||
/** @var \Drupal\field\FieldStorageConfigInterface $storage */
|
||||
$storage = $source_field->getFieldStorageDefinition();
|
||||
$storage->setLocked(TRUE)->save();
|
||||
$storage->save();
|
||||
$source_field->save();
|
||||
|
||||
$media_type
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\media\Functional;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\media\Entity\MediaType;
|
||||
|
||||
/**
|
||||
* Tests the file media source.
|
||||
*
|
||||
* @group media
|
||||
*/
|
||||
class MediaSourceFileTest extends MediaFunctionalTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// We need to test without any default configuration in place.
|
||||
// @TODO: Remove this as part of https://www.drupal.org/node/2883813.
|
||||
MediaType::load('file')->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that it's possible to change the allowed file extensions.
|
||||
*/
|
||||
public function testSourceFieldSettingsEditing() {
|
||||
$session = $this->getSession();
|
||||
$page = $session->getPage();
|
||||
$assert_session = $this->assertSession();
|
||||
|
||||
$media_type = $this->createMediaType([], 'file');
|
||||
$media_type_id = $media_type->id();
|
||||
$this->assertSame('txt doc docx pdf', FieldConfig::load("media.$media_type_id.field_media_file")->get('settings')['file_extensions']);
|
||||
|
||||
$this->drupalGet("admin/structure/media/manage/$media_type_id/fields/media.$media_type_id.field_media_file");
|
||||
|
||||
// File extension field exists.
|
||||
$assert_session->fieldExists('Allowed file extensions');
|
||||
|
||||
// Add another extension.
|
||||
$page->fillField('settings[file_extensions]', 'txt, doc, docx, pdf, odt');
|
||||
|
||||
$page->pressButton('Save settings');
|
||||
$this->drupalGet("admin/structure/media/manage/$media_type_id/fields/media.$media_type_id.field_media_file");
|
||||
|
||||
// Verify that new extension is present.
|
||||
$assert_session->fieldValueEquals('settings[file_extensions]', 'txt, doc, docx, pdf, odt');
|
||||
$this->assertSame('txt doc docx pdf odt', FieldConfig::load("media.$media_type_id.field_media_file")->get('settings')['file_extensions']);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -90,7 +90,7 @@ class MediaUiJavascriptTest extends MediaJavascriptTestBase {
|
|||
/** @var \Drupal\field\FieldStorageConfigInterface $storage */
|
||||
$storage = $source_field->getFieldStorageDefinition();
|
||||
$this->assertFalse($storage->isNew(), 'Source field storage definition was saved.');
|
||||
$this->assertTrue($storage->isLocked(), 'Source field storage definition was locked.');
|
||||
$this->assertFalse($storage->isLocked(), 'Source field storage definition was not locked.');
|
||||
|
||||
/** @var \Drupal\media\MediaTypeInterface $media_type_storage */
|
||||
$media_type_storage = $this->container->get('entity_type.manager')->getStorage('media_type');
|
||||
|
|
|
|||
|
|
@ -352,7 +352,7 @@ class MediaSourceTest extends MediaKernelTestBase {
|
|||
|
||||
// Test field storage.
|
||||
$this->assertTrue($field_storage->isNew(), 'Field storage is saved automatically.');
|
||||
$this->assertTrue($field_storage->isLocked(), 'Field storage is not locked.');
|
||||
$this->assertFalse($field_storage->isLocked(), 'Field storage is not locked.');
|
||||
$this->assertEquals('string', $field_storage->getType(), 'Field is not of correct type.');
|
||||
$this->assertEquals('field_media_test_1', $field_storage->getName(), 'Incorrect field name is used.');
|
||||
$this->assertEquals('media', $field_storage->getTargetEntityTypeId(), 'Field is not targeting media entities.');
|
||||
|
|
@ -387,7 +387,7 @@ class MediaSourceTest extends MediaKernelTestBase {
|
|||
|
||||
// Test field storage.
|
||||
$this->assertTrue($field_storage->isNew(), 'Field storage is saved automatically.');
|
||||
$this->assertTrue($field_storage->isLocked(), 'Field storage is not locked.');
|
||||
$this->assertFalse($field_storage->isLocked(), 'Field storage is not locked.');
|
||||
$this->assertEquals('string_long', $field_storage->getType(), 'Field is of incorrect type.');
|
||||
$this->assertEquals('field_media_test_constraints_1', $field_storage->getName(), 'Incorrect field name is used.');
|
||||
$this->assertEquals('media', $field_storage->getTargetEntityTypeId(), 'Field is not targeting media entities.');
|
||||
|
|
|
|||
Loading…
Reference in New Issue