function AddFormBase::getAddedMediaItems

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

Get all added media items from the form state.

Parameters

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

Return value

\Drupal\media\MediaInterface[] An array containing the added media items keyed by delta. The media items won't have an ID until they are saved in ::submitForm().

5 calls to AddFormBase::getAddedMediaItems()
AddFormBase::buildForm in core/modules/media_library/src/Form/AddFormBase.php
Form constructor.
AddFormBase::getCurrentMediaItems in core/modules/media_library/src/Form/AddFormBase.php
Get all pre-selected and added media items from the form state.
AddFormBase::submitForm in core/modules/media_library/src/Form/AddFormBase.php
Form submission handler.
AddFormBase::updateLibrary in core/modules/media_library/src/Form/AddFormBase.php
AJAX callback to send the new media item(s) to the media library.
AddFormBase::validateForm in core/modules/media_library/src/Form/AddFormBase.php
Form validation handler.

File

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

Class

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

Namespace

Drupal\media_library\Form

Code

protected function getAddedMediaItems(FormStateInterface $form_state) {
    return $form_state->get('media') ?: [];
}

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