function AddFormBase::buildSelectedItemElement

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

Returns a render array for a single pre-selected media item.

Parameters

\Drupal\media\MediaInterface $media: The media item.

array $form: The complete form.

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

Return value

array A render array of a pre-selected media item.

1 call to AddFormBase::buildSelectedItemElement()
AddFormBase::buildCurrentSelectionArea in core/modules/media_library/src/Form/AddFormBase.php
Returns a render array containing the current selection.

File

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

Class

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

Namespace

Drupal\media_library\Form

Code

protected function buildSelectedItemElement(MediaInterface $media, array $form, FormStateInterface $form_state) {
    return [
        '#theme' => 'media_library_item__small',
        '#attributes' => [
            'class' => [
                'js-media-library-item',
                'js-click-to-select',
            ],
        ],
        'select' => [
            '#type' => 'container',
            '#attributes' => [
                'class' => [
                    'js-click-to-select-checkbox',
                ],
            ],
            'select_checkbox' => [
                '#type' => 'checkbox',
                '#title' => $this->t('Select @name', [
                    '@name' => $media->label(),
                ]),
                '#title_display' => 'invisible',
                '#return_value' => $media->id(),
                // The checkbox's value is never processed by this form. It is present
                // for usability and accessibility reasons, and only used by
                // JavaScript to track whether or not this media item is selected. The
                // hidden 'current_selection' field is used to store the actual IDs of
                // selected media items.
'#value' => FALSE,
            ],
        ],
        'rendered_entity' => $this->viewBuilder
            ->view($media, 'media_library'),
    ];
}

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