function olivero_preprocess_field_multiple_value_form

Same name and namespace in other branches
  1. 10 core/themes/olivero/olivero.theme \olivero_preprocess_field_multiple_value_form()
  2. 11.x core/themes/olivero/olivero.theme \olivero_preprocess_field_multiple_value_form()

Implements hook_preprocess_HOOK().

File

core/themes/olivero/olivero.theme, line 370

Code

function olivero_preprocess_field_multiple_value_form(&$variables) {
    // Make disabled available for the template.
    $variables['disabled'] = !empty($variables['element']['#disabled']);
    if (!empty($variables['multiple'])) {
        // Add an additional CSS class for the field label table cell.
        // This repeats the logic of template_preprocess_field_multiple_value_form()
        // without using '#prefix' and '#suffix' for the wrapper element.
        //
        // If the field is multiple, we don't have to check the existence of the
        // table header cell.
        //
        // @see template_preprocess_field_multiple_value_form().
        $header_attributes = [
            'class' => [
                'form-item__label',
                'form-item__label--multiple-value-form',
            ],
        ];
        if (!empty($variables['element']['#required'])) {
            $header_attributes['class'][] = 'js-form-required';
            $header_attributes['class'][] = 'form-required';
        }
        // Using array_key_first() for addressing the first header cell would be
        // more elegant here, but we can rely on the related theme.inc preprocess.
        // @todo change this after https://www.drupal.org/node/3099026 has landed.
        $variables['table']['#header'][0]['data'] = [
            '#type' => 'html_tag',
            '#tag' => 'h4',
            '#value' => $variables['element']['#title'],
            '#attributes' => $header_attributes,
        ];
        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',
                        ],
                    ];
                }
            }
        }
    }
}

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