function FormHooks::formMediaLibraryAddFormAlter

Same name and namespace in other branches
  1. main core/themes/admin/src/Hook/FormHooks.php \Drupal\admin\Hook\FormHooks::formMediaLibraryAddFormAlter()

Implements hook_form_BASE_FORM_ID_alter().

Attributes

#[Hook('form_media_library_add_form_alter')]

File

core/themes/admin/src/Hook/FormHooks.php, line 195

Class

FormHooks
Provides form related hook implementations.

Namespace

Drupal\admin\Hook

Code

public function formMediaLibraryAddFormAlter(array &$form) : void {
  $form['#attributes']['class'][] = 'media-library-add-form';
  $form['#attached']['library'][] = 'admin/media_library.theme';
  // If there are unsaved media items, apply styling classes to various parts
  // of the form.
  if (isset($form['media'])) {
    $form['#attributes']['class'][] = 'media-library-add-form--with-input';
    // Put a wrapper around the informational message above the unsaved media
    // items.
    $form['description']['#template'] = '<p class="media-library-add-form__description">{{ text }}</p>';
  }
  else {
    $form['#attributes']['class'][] = 'media-library-add-form--without-input';
  }
}

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