function seven_preprocess_item_list__media_library_add_form_media_list

Same name and namespace in other branches
  1. 8.9.x core/themes/seven/seven.theme \seven_preprocess_item_list__media_library_add_form_media_list()

Implements hook_preprocess_item_list__media_library_add_form_media_list().

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

File

core/themes/seven/seven.theme, line 288

Code

function seven_preprocess_item_list__media_library_add_form_media_list(array &$variables) {
    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';
        // #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'];
        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.