function AddFormBase::getMediaLibraryState

Same name in other branches
  1. 9 core/modules/media_library/src/Form/AddFormBase.php \Drupal\media_library\Form\AddFormBase::getMediaLibraryState()
  2. 8.9.x core/modules/media_library/src/Form/AddFormBase.php \Drupal\media_library\Form\AddFormBase::getMediaLibraryState()
  3. 11.x core/modules/media_library/src/Form/AddFormBase.php \Drupal\media_library\Form\AddFormBase::getMediaLibraryState()

Get the media library state from the form state.

Parameters

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

Return value

\Drupal\media_library\MediaLibraryState The media library state.

Throws

\InvalidArgumentException If the media library state is not present in the form state.

4 calls to AddFormBase::getMediaLibraryState()
AddFormBase::buildMediaLibraryUi in core/modules/media_library/src/Form/AddFormBase.php
Build the render array of the media library UI.
AddFormBase::getMediaType in core/modules/media_library/src/Form/AddFormBase.php
Get the media type from the form state.
AddFormBase::updateWidget in core/modules/media_library/src/Form/AddFormBase.php
AJAX callback to send the new media item(s) to the calling code.
FileUploadForm::buildInputElement in core/modules/media_library/src/Form/FileUploadForm.php
Builds the element for submitting source field value(s).

File

core/modules/media_library/src/Form/AddFormBase.php, line 815

Class

AddFormBase
Provides a base class for creating media items from within the media library.

Namespace

Drupal\media_library\Form

Code

protected function getMediaLibraryState(FormStateInterface $form_state) {
    $state = $form_state->get('media_library_state');
    if (!$state) {
        throw new \InvalidArgumentException('The media library state is not present in the form state.');
    }
    return $state;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.