function AddFormBase::getSelectedMediaItemCount

Same name in other branches
  1. 11.x core/modules/media_library/src/Form/AddFormBase.php \Drupal\media_library\Form\AddFormBase::getSelectedMediaItemCount()

Get the number of selected media.

Parameters

array $media_ids: Array with the media IDs.

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

Return value

int The number of media currently selected.

2 calls to AddFormBase::getSelectedMediaItemCount()
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::updateWidget in core/modules/media_library/src/Form/AddFormBase.php
AJAX callback to send the new media item(s) to the calling code.

File

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

Class

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

Namespace

Drupal\media_library\Form

Code

private function getSelectedMediaItemCount(array $media_ids, FormStateInterface $form_state) : int {
    $selected_count = count($media_ids);
    if ($current_selection = $form_state->getValue('current_selection')) {
        $selected_count += count(explode(',', $current_selection));
    }
    return $selected_count;
}

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