summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2018-07-06 11:33:11 (GMT)
committerAlex Pott2018-07-06 11:33:11 (GMT)
commit1a8b7f162570de9a013d4aa6dd3ead96d26596ae (patch)
tree8c3bbdba6d3b5c5f6bb9d96585c6d6553c82f4c8
parent3c5bf74b8b080f890278f68fdb4db8649917a0a4 (diff)
Issue #2928851 by chr.fritsch, daniel.bosen, yogeshmpawar, jefuri, dagomar, seanB, marcoscano, phenaproxima, alexpott, borisson_: Allow the media source of a media type to be changed when creating a new media type
-rw-r--r--core/modules/media/src/MediaTypeForm.php4
-rw-r--r--core/modules/media/tests/src/FunctionalJavascript/MediaTypeCreationTest.php39
2 files changed, 41 insertions, 2 deletions
diff --git a/core/modules/media/src/MediaTypeForm.php b/core/modules/media/src/MediaTypeForm.php
index d696556..93fed85 100644
--- a/core/modules/media/src/MediaTypeForm.php
+++ b/core/modules/media/src/MediaTypeForm.php
@@ -118,7 +118,7 @@ class MediaTypeForm extends EntityForm {
'#attributes' => ['id' => 'source-dependent'],
];
- if ($source) {
+ if (!$this->entity->isNew()) {
$source_description = $this->t('<em>The media source cannot be changed after the media type is created.</em>');
}
else {
@@ -134,7 +134,7 @@ class MediaTypeForm extends EntityForm {
'#required' => TRUE,
// Once the media type is created, its source plugin cannot be changed
// anymore.
- '#disabled' => !empty($source),
+ '#disabled' => !$this->entity->isNew(),
];
if ($source) {
diff --git a/core/modules/media/tests/src/FunctionalJavascript/MediaTypeCreationTest.php b/core/modules/media/tests/src/FunctionalJavascript/MediaTypeCreationTest.php
index 207b542..42e3511 100644
--- a/core/modules/media/tests/src/FunctionalJavascript/MediaTypeCreationTest.php
+++ b/core/modules/media/tests/src/FunctionalJavascript/MediaTypeCreationTest.php
@@ -12,6 +12,45 @@ use Drupal\Component\Utility\Html;
class MediaTypeCreationTest extends MediaJavascriptTestBase {
/**
+ * Tests the source field behavior on the add media type form.
+ */
+ public function testSourceChangeOnMediaTypeCreationForm() {
+ $session = $this->getSession();
+ $page = $session->getPage();
+ $assert_session = $this->assertSession();
+
+ $label = 'Type with Default Field';
+ $mediaTypeMachineName = str_replace(' ', '_', strtolower($label));
+
+ $this->drupalGet('admin/structure/media/add');
+
+ // Fill in a label to the media type.
+ $page->fillField('label', $label);
+ $this->assertNotEmpty(
+ $assert_session->waitForElementVisible('css', '.machine-name-value')
+ );
+
+ // Select the media source used by our media type.
+ $assert_session->selectExists('Media source')->selectOption('test_different_displays');
+ $this->assertNotEmpty(
+ $assert_session->waitForElementVisible('css', 'fieldset[data-drupal-selector="edit-source-configuration"]')
+ );
+
+ // Change the media source.
+ $assert_session->selectExists('Media source')->selectOption('test');
+ $this->assertNotEmpty(
+ $assert_session->waitForElement('css', 'fieldset[data-drupal-selector="edit-source-configuration"] .fieldset-wrapper .placeholder:contains("Text (plain)")')
+ );
+
+ $page->pressButton('Save');
+
+ // Check that source can not be changed anymore.
+ $this->drupalGet("admin/structure/media/manage/{$mediaTypeMachineName}");
+ $assert_session->pageTextContains('The media source cannot be changed after the media type is created');
+ $assert_session->fieldDisabled('Media source');
+ }
+
+ /**
* Tests the media type creation form.
*/
public function testMediaTypeCreationFormWithDefaultField() {