Skip to content
Snippets Groups Projects
Verified Commit b5b3949b authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #2928256 by marcoscano, seanB: Users shouldn't be able to change the...

Issue #2928256 by marcoscano, seanB: Users shouldn't be able to change the media source plugin after the media type is created
parent de9e2d70
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -118,14 +118,23 @@ public function form(array $form, FormStateInterface $form_state) {
'#attributes' => ['id' => 'source-dependent'],
];
if ($source) {
$source_description = $this->t('<em>The media source cannot be changed after the media type is created.</em>');
}
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) {
......
......@@ -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.');
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment