diff --git a/core/modules/media_library/src/Form/AddFormBase.php b/core/modules/media_library/src/Form/AddFormBase.php index 507c99e725..a4571d1d72 100644 --- a/core/modules/media_library/src/Form/AddFormBase.php +++ b/core/modules/media_library/src/Form/AddFormBase.php @@ -20,6 +20,7 @@ use Drupal\media\MediaInterface; use Drupal\media\MediaTypeInterface; use Drupal\media_library\Ajax\UpdateSelectionCommand; +use Drupal\media_library\MediaLibraryState; use Drupal\media_library\MediaLibraryUiBuilder; use Drupal\media_library\OpenerResolverInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -260,7 +261,7 @@ abstract protected function buildInputElement(array $form, FormStateInterface $f * @return array * The element containing the required fields sub-form. */ - protected function buildEntityFormElement(MediaInterface $media, array $form, FormStateInterface $form_state, int $delta, string $add_form_mode = 'media_library') { + protected function buildEntityFormElement(MediaInterface $media, array $form, FormStateInterface $form_state, int $delta, string $add_form_mode = MediaLibraryState::DEFAULT_FORM_MODE) { // We need to make sure each button has a unique name attribute. The default // name for button elements is 'op'. If the name is not unique, the // triggering element is not set correctly and the wrong media item is diff --git a/core/modules/media_library/tests/modules/media_library_test_widget/config/schema/media_library_test_widget.schema.yml b/core/modules/media_library/tests/modules/media_library_test_widget/config/schema/media_library_test_widget.schema.yml index 81186253e1..0e74387667 100644 --- a/core/modules/media_library/tests/modules/media_library_test_widget/config/schema/media_library_test_widget.schema.yml +++ b/core/modules/media_library/tests/modules/media_library_test_widget/config/schema/media_library_test_widget.schema.yml @@ -8,3 +8,6 @@ field.widget.settings.media_library_inception_widget: sequence: type: string label: 'Media type ID' + form_mode: + type: string + label: 'Form mode' diff --git a/core/modules/media_library/tests/src/Kernel/MediaLibraryAddFormTest.php b/core/modules/media_library/tests/src/Kernel/MediaLibraryAddFormTest.php index edea0e3e3a..b5a2734ad4 100644 --- a/core/modules/media_library/tests/src/Kernel/MediaLibraryAddFormTest.php +++ b/core/modules/media_library/tests/src/Kernel/MediaLibraryAddFormTest.php @@ -119,9 +119,7 @@ public function testMediaTypeAddForm() { * The render array for the media library. */ protected function buildLibraryUi($selected_type_id) { - // @todo where should this be pulled from? The field widget specifies. - $form_mode = 'media_library'; - $state = MediaLibraryState::create('test', ['image', 'remote_video'], $selected_type_id, -1, [], $form_mode); + $state = MediaLibraryState::create('test', ['image', 'remote_video'], $selected_type_id, -1, [], $this->form_mode); return \Drupal::service('media_library.ui_builder')->buildUi($state); } @@ -139,9 +137,7 @@ public function testFormStateValidation() { * Tests the validation of the selected type in the media library add form. */ public function testSelectedTypeValidation() { - // @todo where should this be pulled from? The field widget specifies. - $form_mode = 'media_library'; - $state = MediaLibraryState::create('test', ['image', 'remote_video', 'header_image'], 'header_image', -1, [], $form_mode); + $state = MediaLibraryState::create('test', ['image', 'remote_video', 'header_image'], 'header_image', -1, [], $this->form_mode); $form_state = new FormState(); $form_state->set('media_library_state', $state); $this->expectException(\InvalidArgumentException::class); diff --git a/core/modules/media_library/tests/src/Kernel/MediaLibraryStateTest.php b/core/modules/media_library/tests/src/Kernel/MediaLibraryStateTest.php index 6b315dbd5f..bce48dbea2 100644 --- a/core/modules/media_library/tests/src/Kernel/MediaLibraryStateTest.php +++ b/core/modules/media_library/tests/src/Kernel/MediaLibraryStateTest.php @@ -25,7 +25,7 @@ class MediaLibraryStateTest extends KernelTestBase { /** * @var \Drupal\media\MediaTypeInterface|string */ - protected static $form_mode = MediaLibraryState::DEFAULT_FORM_MODE; + protected $form_mode = MediaLibraryState::DEFAULT_FORM_MODE; /** * {@inheritdoc}