Unverified Commit 897f0e46 authored by alexpott's avatar alexpott

Issue #3018539 by phenaproxima, rodrigoaguilera, alexpott: Media types cannot...

Issue #3018539 by phenaproxima, rodrigoaguilera, alexpott: Media types cannot be created in the UI without JavaScript

(cherry picked from commit 3ba6bc11)
parent d89fc7e3
......@@ -304,6 +304,17 @@ function ($item) {
*/
protected function actions(array $form, FormStateInterface $form_state) {
$actions = parent::actions($form, $form_state);
// If the media source has not been chosen yet, turn the submit button into
// a button. This rebuilds the form with the media source's configuration
// form visible, instead of saving the media type. This allows users to
// create a media type without JavaScript enabled. With JavaScript enabled,
// this rebuild occurs during an AJAX request.
// @see \Drupal\media\MediaTypeForm::ajaxHandlerData()
if (empty($this->getEntity()->get('source'))) {
$actions['submit']['#type'] = 'button';
}
$actions['submit']['#value'] = $this->t('Save');
$actions['delete']['#value'] = $this->t('Delete');
$actions['delete']['#access'] = $this->entity->access('delete');
......
<?php
namespace Drupal\Tests\media\Functional;
use Drupal\media\Entity\MediaType;
/**
* Ensures that media UI works correctly without JavaScript.
*
* @group media
*/
class MediaTypeCreationTest extends MediaFunctionalTestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
'media_test_source',
];
/**
* Tests the media type creation form with only the mandatory options.
*/
public function testMediaTypeCreationForm() {
$machine_name = mb_strtolower($this->randomMachineName());
$this->drupalGet('/admin/structure/media/add');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->fieldExists('label')->setValue($this->randomString());
$this->assertSession()->fieldExists('id')->setValue($machine_name);
$this->assertSession()->selectExists('source')->selectOption('test');
$this->assertSession()->buttonExists('Save')->press();
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->fieldValueEquals('Test config value', 'This is default value.');
$this->assertSession()->buttonExists('Save')->press();
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->addressEquals('admin/structure/media');
$this->assertInstanceOf(MediaType::class, MediaType::load($machine_name));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment