function MediaLibraryHooks::formViewsFormMediaLibraryPageAlter

Implements hook_form_FORM_ID_alter().

Alter the bulk form to add a more accessible label.

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

Attributes

#[Hook('form_views_form_media_library_page_alter')]

File

core/modules/media_library/src/Hook/MediaLibraryHooks.php, line 223

Class

MediaLibraryHooks
Hook implementations for media_library.

Namespace

Drupal\media_library\Hook

Code

public function formViewsFormMediaLibraryPageAlter(array &$form, FormStateInterface $form_state, $form_id) : void {
  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'] = $media ? $this->t('Select @label', [
          '@label' => $media->label(),
        ]) : '';
      }
    }
  }
}

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