diff --git a/core/modules/media/src/MediaTypeForm.php b/core/modules/media/src/MediaTypeForm.php index 04ac4ba88ccfa9a1fe9f4dfcbd3f422bc3b1d891..170a34fa5c2e71fd709e4c6010199d6efad5a0ae 100644 --- a/core/modules/media/src/MediaTypeForm.php +++ b/core/modules/media/src/MediaTypeForm.php @@ -118,14 +118,23 @@ public function form(array $form, FormStateInterface $form_state) { '#attributes' => ['id' => 'source-dependent'], ]; + if ($source) { + $source_description = $this->t('The media source cannot be changed after the media type is created.'); + } + else { + $source_description = $this->t('Media source that is responsible for additional logic related to this media type.'); + } $form['source_dependent']['source'] = [ '#type' => 'select', '#title' => $this->t('Media source'), '#default_value' => $source ? $source->getPluginId() : NULL, '#options' => $options, - '#description' => $this->t('Media source that is responsible for additional logic related to this media type.'), + '#description' => $source_description, '#ajax' => ['callback' => '::ajaxHandlerData'], '#required' => TRUE, + // Once the media type is created, its source plugin cannot be changed + // anymore. + '#disabled' => !empty($source), ]; if (!$source) { diff --git a/core/modules/media/tests/src/FunctionalJavascript/MediaTypeCreationTest.php b/core/modules/media/tests/src/FunctionalJavascript/MediaTypeCreationTest.php index efbe28849b19b308e28ee736f4f22e4145cc103f..652aca8c6be17c732feccf4c509751e5429bb138 100644 --- a/core/modules/media/tests/src/FunctionalJavascript/MediaTypeCreationTest.php +++ b/core/modules/media/tests/src/FunctionalJavascript/MediaTypeCreationTest.php @@ -49,6 +49,10 @@ public function testMediaTypeCreationFormWithDefaultField() { $this->drupalGet("admin/structure/media/manage/{$mediaTypeMachineName}"); $assert_session->pageTextContains('Test source field is used to store the essential information about the media item.'); + + // Check that the plugin cannot be changed after it is set on type creation. + $assert_session->fieldDisabled('Media source'); + $assert_session->pageTextContains('The media source cannot be changed after the media type is created.'); } /**