function media_library_form_views_form_media_library_page_alter

Same name in other branches
  1. 9 core/modules/media_library/media_library.module \media_library_form_views_form_media_library_page_alter()
  2. 10 core/modules/media_library/media_library.module \media_library_form_views_form_media_library_page_alter()
  3. 11.x core/modules/media_library/media_library.module \media_library_form_views_form_media_library_page_alter()

Alter the bulk form to add a more accessible label.

@todo Remove in https://www.drupal.org/node/2983454

Parameters

array $form: An associative array containing the structure of the form.

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

File

core/modules/media_library/media_library.module, line 277

Code

function media_library_form_views_form_media_library_page_alter(array &$form, FormStateInterface $form_state) {
    if (isset($form['media_bulk_form']) && isset($form['output'])) {
        
        /** @var \Drupal\views\ViewExecutable $view */
        $view = $form['output'][0]['#view'];
        foreach (Element::getVisibleChildren($form['media_bulk_form']) as $key) {
            if (isset($view->result[$key])) {
                $media = $view->field['media_bulk_form']
                    ->getEntity($view->result[$key]);
                $form['media_bulk_form'][$key]['#title'] = t('Select @label', [
                    '@label' => $media->label(),
                ]);
            }
        }
    }
}

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