Issue #2928256 by marcoscano, seanB: Users shouldn't be able to change the media source plugin after the media type is created
parent
de9e2d7061
commit
b5b3949b14
|
@ -118,14 +118,23 @@ class MediaTypeForm extends EntityForm {
|
||||||
'#attributes' => ['id' => 'source-dependent'],
|
'#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'] = [
|
$form['source_dependent']['source'] = [
|
||||||
'#type' => 'select',
|
'#type' => 'select',
|
||||||
'#title' => $this->t('Media source'),
|
'#title' => $this->t('Media source'),
|
||||||
'#default_value' => $source ? $source->getPluginId() : NULL,
|
'#default_value' => $source ? $source->getPluginId() : NULL,
|
||||||
'#options' => $options,
|
'#options' => $options,
|
||||||
'#description' => $this->t('Media source that is responsible for additional logic related to this media type.'),
|
'#description' => $source_description,
|
||||||
'#ajax' => ['callback' => '::ajaxHandlerData'],
|
'#ajax' => ['callback' => '::ajaxHandlerData'],
|
||||||
'#required' => TRUE,
|
'#required' => TRUE,
|
||||||
|
// Once the media type is created, its source plugin cannot be changed
|
||||||
|
// anymore.
|
||||||
|
'#disabled' => !empty($source),
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!$source) {
|
if (!$source) {
|
||||||
|
|
|
@ -49,6 +49,10 @@ class MediaTypeCreationTest extends MediaJavascriptTestBase {
|
||||||
$this->drupalGet("admin/structure/media/manage/{$mediaTypeMachineName}");
|
$this->drupalGet("admin/structure/media/manage/{$mediaTypeMachineName}");
|
||||||
|
|
||||||
$assert_session->pageTextContains('Test source field is used to store the essential information about the media item.');
|
$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.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue