function claro_preprocess_field_multiple_value_form

Same name and namespace in other branches
  1. 9 core/themes/claro/claro.theme \claro_preprocess_field_multiple_value_form()
  2. 8.9.x core/themes/claro/claro.theme \claro_preprocess_field_multiple_value_form()
  3. 10 core/themes/claro/claro.theme \claro_preprocess_field_multiple_value_form()

Implements hook_preprocess_HOOK() for field_multiple_value_form.

File

core/themes/claro/claro.theme, line 1070

Code

function claro_preprocess_field_multiple_value_form(&$variables) {
    // Make disabled available for the template.
    $variables['disabled'] = !empty($variables['element']['#disabled']);
    if ($variables['multiple']) {
        // Add an additional CSS class to the field label table cell. The table
        // header cell should always exist unless removed by contrib.
        // @see template_preprocess_field_multiple_value_form().
        if (isset($variables['table']['#header'][0]['data']['#attributes'])) {
            $variables['table']['#header'][0]['data']['#attributes']->removeClass('label');
            $variables['table']['#header'][0]['data']['#attributes']->addClass('form-item__label', 'form-item__label--multiple-value-form');
        }
        if ($variables['disabled']) {
            $variables['table']['#attributes']['class'][] = 'tabledrag-disabled';
            $variables['table']['#attributes']['class'][] = 'js-tabledrag-disabled';
            // We will add the 'is-disabled' CSS class to the disabled table header
            // cells.
            $header_attributes['class'][] = 'is-disabled';
            foreach ($variables['table']['#header'] as &$cell) {
                if (is_array($cell) && isset($cell['data'])) {
                    $cell = $cell + [
                        'class' => [],
                    ];
                    $cell['class'][] = 'is-disabled';
                }
                else {
                    // We have to modify the structure of this header cell.
                    $cell = [
                        'data' => $cell,
                        'class' => [
                            'is-disabled',
                        ],
                    ];
                }
            }
        }
        // Make add-more button smaller.
        if (!empty($variables['button'])) {
            $variables['button']['#attributes']['class'][] = 'button--small';
        }
    }
}

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