summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabor Hojtsy2017-07-19 16:27:56 +0200
committerGabor Hojtsy2017-07-19 16:27:56 +0200
commit4b95aa76bf1e1c499a271ad9cdc03ef3d5004207 (patch)
tree52202d77a100d20533f16c0c08ac670fa220cf56
parent6002539d9a85783500dbd943a86053dd8d043fea (diff)
Issue #2894270 by xjm, seanB, chr.fritsch, Wim Leers: Users unable to add an extension to the file upload field
-rw-r--r--core/modules/media/config/install/field.storage.media.field_media_file.yml2
-rw-r--r--core/modules/media/config/install/field.storage.media.field_media_image.yml2
-rw-r--r--core/modules/media/src/MediaSourceBase.php1
-rw-r--r--core/modules/media/src/MediaTypeForm.php4
-rw-r--r--core/modules/media/tests/src/Functional/MediaFunctionalTestCreateMediaTypeTrait.php2
-rw-r--r--core/modules/media/tests/src/Functional/MediaSourceFileTest.php54
-rw-r--r--core/modules/media/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php2
-rw-r--r--core/modules/media/tests/src/Kernel/MediaSourceTest.php4
8 files changed, 62 insertions, 9 deletions
diff --git a/core/modules/media/config/install/field.storage.media.field_media_file.yml b/core/modules/media/config/install/field.storage.media.field_media_file.yml
index 344abd1..1fa8af9 100644
--- a/core/modules/media/config/install/field.storage.media.field_media_file.yml
+++ b/core/modules/media/config/install/field.storage.media.field_media_file.yml
@@ -17,7 +17,7 @@ settings:
display_field: false
display_default: false
module: file
-locked: true
+locked: false
cardinality: 1
translatable: true
indexes: { }
diff --git a/core/modules/media/config/install/field.storage.media.field_media_image.yml b/core/modules/media/config/install/field.storage.media.field_media_image.yml
index 155db11..231200d 100644
--- a/core/modules/media/config/install/field.storage.media.field_media_image.yml
+++ b/core/modules/media/config/install/field.storage.media.field_media_image.yml
@@ -24,7 +24,7 @@ settings:
display_default: false
uri_scheme: public
module: image
-locked: true
+locked: false
cardinality: 1
translatable: true
indexes: { }
diff --git a/core/modules/media/src/MediaSourceBase.php b/core/modules/media/src/MediaSourceBase.php
index d22d86c..dea0140 100644
--- a/core/modules/media/src/MediaSourceBase.php
+++ b/core/modules/media/src/MediaSourceBase.php
@@ -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,
]);
}
diff --git a/core/modules/media/src/MediaTypeForm.php b/core/modules/media/src/MediaTypeForm.php
index 3a96291..80f7d21 100644
--- a/core/modules/media/src/MediaTypeForm.php
+++ b/core/modules/media/src/MediaTypeForm.php
@@ -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();
diff --git a/core/modules/media/tests/src/Functional/MediaFunctionalTestCreateMediaTypeTrait.php b/core/modules/media/tests/src/Functional/MediaFunctionalTestCreateMediaTypeTrait.php
index 2d60c9b..4197caa 100644
--- a/core/modules/media/tests/src/Functional/MediaFunctionalTestCreateMediaTypeTrait.php
+++ b/core/modules/media/tests/src/Functional/MediaFunctionalTestCreateMediaTypeTrait.php
@@ -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
diff --git a/core/modules/media/tests/src/Functional/MediaSourceFileTest.php b/core/modules/media/tests/src/Functional/MediaSourceFileTest.php
new file mode 100644
index 0000000..caa0f79
--- /dev/null
+++ b/core/modules/media/tests/src/Functional/MediaSourceFileTest.php
@@ -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']);
+ }
+
+}
diff --git a/core/modules/media/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php b/core/modules/media/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php
index b150f89..80fa633 100644
--- a/core/modules/media/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php
+++ b/core/modules/media/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php
@@ -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');
diff --git a/core/modules/media/tests/src/Kernel/MediaSourceTest.php b/core/modules/media/tests/src/Kernel/MediaSourceTest.php
index c236914..90f6f2b 100644
--- a/core/modules/media/tests/src/Kernel/MediaSourceTest.php
+++ b/core/modules/media/tests/src/Kernel/MediaSourceTest.php
@@ -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.');