function claro_preprocess_item_list__media_library_add_form_media_list

Same name and namespace in other branches
  1. 8.9.x core/themes/claro/claro.theme \claro_preprocess_item_list__media_library_add_form_media_list()
  2. 10 core/themes/claro/claro.theme \claro_preprocess_item_list__media_library_add_form_media_list()
  3. 11.x core/themes/claro/claro.theme \claro_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/claro/claro.theme, line 1392

Code

function claro_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';
        $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.