You are here

public static function MediaLibrary::openMediaLibrary in Media Library Form API Element 2.x

Same name and namespace in other branches
  1. 8 src/Element/MediaLibrary.php \Drupal\media_library_form_element\Element\MediaLibrary::openMediaLibrary()

AJAX callback to open the library modal.

Parameters

array $form: The form array.

\Drupal\Core\Form\FormStateInterface $form_state: The form state.

Return value

\Drupal\Core\Ajax\AjaxResponse An AJAX response to open the media library.

File

src/Element/MediaLibrary.php, line 545

Class

MediaLibrary
Provides a Media library form element.

Namespace

Drupal\media_library_form_element\Element

Code

public static function openMediaLibrary(array $form, FormStateInterface $form_state) {
  $triggering_element = $form_state
    ->getTriggeringElement();
  $library_ui = \Drupal::service('media_library.ui_builder')
    ->buildUi($triggering_element['#media_library_state']);
  $dialog_options = MediaLibraryUiBuilder::dialogOptions();
  return (new AjaxResponse())
    ->addCommand(new OpenModalDialogCommand($dialog_options['title'], $library_ui, $dialog_options, NULL, '#modal-media-library'));
}