function ClaroHooks::preprocessItemListMediaLibraryAddFormMediaList

Implements hook_preprocess_HOOK() for item_list__media_library_add_form_media_list.

This targets each new, unsaved media item added to the media library, before they are saved.

Attributes

#[Hook('preprocess_item_list__media_library_add_form_media_list')]

File

core/themes/claro/src/Hook/ClaroHooks.php, line 1247

Class

ClaroHooks
Hook implementations for claro.

Namespace

Drupal\claro\Hook

Code

public function preprocessItemListMediaLibraryAddFormMediaList(array &$variables) : void {
  foreach ($variables['items'] as &$item) {
    $item['value']['preview']['#attributes']['class'][] = 'media-library-add-form__preview';
    $item['value']['fields']['#attributes']['class'][] = 'media-library-add-form__fields';
    $item['value']['remove_button']['#attributes']['class'][] = 'media-library-add-form__remove-button';
    $item['value']['remove_button']['#attributes']['class'][] = 'button--extrasmall';
    // #source_field_name is set by AddFormBase::buildEntityFormElement()
    // to help themes and form_alter hooks identify the source field.
    $fields =& $item['value']['fields'];
    $source_field_name = $fields['#source_field_name'];
    // Set this flag so we can remove the details element.
    $fields[$source_field_name]['widget'][0]['#do_not_wrap_in_details'] = TRUE;
    if (isset($fields[$source_field_name])) {
      $fields[$source_field_name]['#attributes']['class'][] = 'media-library-add-form__source-field';
    }
  }
}

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