File tree Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -304,6 +304,17 @@ function ($item) {
304304 */
305305 protected function actions (array $ form , FormStateInterface $ form_state ) {
306306 $ actions = parent ::actions ($ form , $ form_state );
307+
308+ // If the media source has not been chosen yet, turn the submit button into
309+ // a button. This rebuilds the form with the media source's configuration
310+ // form visible, instead of saving the media type. This allows users to
311+ // create a media type without JavaScript enabled. With JavaScript enabled,
312+ // this rebuild occurs during an AJAX request.
313+ // @see \Drupal\media\MediaTypeForm::ajaxHandlerData()
314+ if (empty ($ this ->getEntity ()->get ('source ' ))) {
315+ $ actions ['submit ' ]['#type ' ] = 'button ' ;
316+ }
317+
307318 $ actions ['submit ' ]['#value ' ] = $ this ->t ('Save ' );
308319 $ actions ['delete ' ]['#value ' ] = $ this ->t ('Delete ' );
309320 $ actions ['delete ' ]['#access ' ] = $ this ->entity ->access ('delete ' );
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Drupal \Tests \media \Functional ;
4+
5+ use Drupal \media \Entity \MediaType ;
6+
7+ /**
8+ * Ensures that media UI works correctly without JavaScript.
9+ *
10+ * @group media
11+ */
12+ class MediaTypeCreationTest extends MediaFunctionalTestBase {
13+
14+ /**
15+ * {@inheritdoc}
16+ */
17+ public static $ modules = [
18+ 'media_test_source ' ,
19+ ];
20+
21+ /**
22+ * Tests the media type creation form with only the mandatory options.
23+ */
24+ public function testMediaTypeCreationForm () {
25+ $ machine_name = mb_strtolower ($ this ->randomMachineName ());
26+
27+ $ this ->drupalGet ('/admin/structure/media/add ' );
28+ $ this ->assertSession ()->statusCodeEquals (200 );
29+ $ this ->assertSession ()->fieldExists ('label ' )->setValue ($ this ->randomString ());
30+ $ this ->assertSession ()->fieldExists ('id ' )->setValue ($ machine_name );
31+ $ this ->assertSession ()->selectExists ('source ' )->selectOption ('test ' );
32+ $ this ->assertSession ()->buttonExists ('Save ' )->press ();
33+ $ this ->assertSession ()->statusCodeEquals (200 );
34+ $ this ->assertSession ()->fieldValueEquals ('Test config value ' , 'This is default value. ' );
35+ $ this ->assertSession ()->buttonExists ('Save ' )->press ();
36+ $ this ->assertSession ()->statusCodeEquals (200 );
37+ $ this ->assertSession ()->addressEquals ('admin/structure/media ' );
38+
39+ $ this ->assertInstanceOf (MediaType::class, MediaType::load ($ machine_name ));
40+ }
41+
42+ }
You can’t perform that action at this time.
0 commit comments