core/modules/media_library/media_library.services.yml | 2 +- core/modules/media_library/src/Form/AddFormBase.php | 5 ++--- core/modules/media_library/src/MediaLibraryFieldWidgetOpener.php | 4 ++-- core/modules/media_library/src/MediaLibraryOpenerInterface.php | 2 ++ .../src/Plugin/Field/FieldWidget/MediaLibraryWidget.php | 2 +- .../media_library/src/Plugin/views/field/MediaLibrarySelectForm.php | 6 +++--- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/core/modules/media_library/media_library.services.yml b/core/modules/media_library/media_library.services.yml index 1cd3af98c5..9978efa79f 100644 --- a/core/modules/media_library/media_library.services.yml +++ b/core/modules/media_library/media_library.services.yml @@ -6,5 +6,5 @@ services: class: Drupal\media_library\Routing\RouteSubscriber tags: - { name: event_subscriber } - media_library.field_widget: + media_library.opener.field_widget: class: Drupal\media_library\MediaLibraryFieldWidgetOpener diff --git a/core/modules/media_library/src/Form/AddFormBase.php b/core/modules/media_library/src/Form/AddFormBase.php index 7ca7c49ef4..950f069919 100644 --- a/core/modules/media_library/src/Form/AddFormBase.php +++ b/core/modules/media_library/src/Form/AddFormBase.php @@ -749,11 +749,10 @@ public function updateWidget(array &$form, FormStateInterface $form_state) { // Allow the opener service to handle the selection. $media_library_state = $this->getMediaLibraryState($form_state); $service_id = $media_library_state->getOpenerId(); - $response = $this->classResolver->getInstanceFromDefinition($service_id)->respondToSelection( + return $this->classResolver->getInstanceFromDefinition($service_id)->respondToSelection( $current_media_ids, $media_library_state - ); - return $response->addCommand(new CloseDialogCommand()); + )->addCommand(new CloseDialogCommand()); } /** diff --git a/core/modules/media_library/src/MediaLibraryFieldWidgetOpener.php b/core/modules/media_library/src/MediaLibraryFieldWidgetOpener.php index a6422aa557..31c859ae90 100644 --- a/core/modules/media_library/src/MediaLibraryFieldWidgetOpener.php +++ b/core/modules/media_library/src/MediaLibraryFieldWidgetOpener.php @@ -15,7 +15,7 @@ class MediaLibraryFieldWidgetOpener implements MediaLibraryOpenerInterface { * {@inheritdoc} */ public function checkAccess(MediaLibraryState $state, AccountInterface $account) { - throw new \Exception('not yet implemented'); + throw new \Exception('Not yet implemented, see https://www.drupal.org/project/drupal/issues/3038254.'); } /** @@ -26,7 +26,7 @@ public function getSelectionResponse(array $selected_ids, MediaLibraryState $sta $widget_id = $state->get('field_widget_id'); if (!$widget_id) { - return new \UnexpectedValueException(); + return new \InvalidArgumentException('field_widget_id is missing.'); } // Create a comma-separated list of media IDs, insert them in the hidden diff --git a/core/modules/media_library/src/MediaLibraryOpenerInterface.php b/core/modules/media_library/src/MediaLibraryOpenerInterface.php index 6245534063..e749626240 100644 --- a/core/modules/media_library/src/MediaLibraryOpenerInterface.php +++ b/core/modules/media_library/src/MediaLibraryOpenerInterface.php @@ -26,6 +26,8 @@ interface MediaLibraryOpenerInterface { * * @return \Drupal\Core\Access\AccessResultInterface * The access result. + * + * @see https://www.drupal.org/project/drupal/issues/3038254 */ public function checkAccess(MediaLibraryState $state, AccountInterface $account); diff --git a/core/modules/media_library/src/Plugin/Field/FieldWidget/MediaLibraryWidget.php b/core/modules/media_library/src/Plugin/Field/FieldWidget/MediaLibraryWidget.php index 5d7c72477d..b011d75bab 100644 --- a/core/modules/media_library/src/Plugin/Field/FieldWidget/MediaLibraryWidget.php +++ b/core/modules/media_library/src/Plugin/Field/FieldWidget/MediaLibraryWidget.php @@ -473,7 +473,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen // Create a new media library URL with the correct state parameters. $selected_type_id = reset($allowed_media_type_ids); $remaining = $cardinality_unlimited ? FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED : $remaining; - $state = MediaLibraryState::create('media_library.field_widget', $allowed_media_type_ids, $selected_type_id, $remaining); + $state = MediaLibraryState::create('media_library.opener.field_widget', $allowed_media_type_ids, $selected_type_id, $remaining); // This particular media library opener needs some extra metadata for its // \Drupal\media_library\MediaLibraryOpenerInterface::getSelectionResponse() // to be able to target the element whose 'data-media-library-widget-value' diff --git a/core/modules/media_library/src/Plugin/views/field/MediaLibrarySelectForm.php b/core/modules/media_library/src/Plugin/views/field/MediaLibrarySelectForm.php index 689960827c..916768c11e 100644 --- a/core/modules/media_library/src/Plugin/views/field/MediaLibrarySelectForm.php +++ b/core/modules/media_library/src/Plugin/views/field/MediaLibrarySelectForm.php @@ -129,11 +129,11 @@ public static function updateWidget(array &$form, FormStateInterface $form_state // Allow the opener service to handle the selection. $media_library_state = MediaLibraryState::fromRequest($form_state->get('view')->getRequest()); $service_id = $media_library_state->getOpenerId(); - $response = \Drupal::service($service_id)->respondToSelection( + return \Drupal::service($service_id)->respondToSelection( $selected_ids, $media_library_state - ); - return $response->addCommand(new CloseDialogCommand()); + ) + ->addCommand(new CloseDialogCommand()); } /**