Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. claro.theme

function claro_preprocess_input

Implements template_preprocess_HOOK() for input.

File

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

Code

function claro_preprocess_input(&$variables) : void {
    if (!empty($variables['element']['#title_display']) && $variables['element']['#title_display'] === 'attribute' && !empty((string) $variables['element']['#title'])) {
        $variables['attributes']['title'] = (string) $variables['element']['#title'];
    }
    $type_api = $variables['element']['#type'];
    $type_html = $variables['attributes']['type'];
    $text_types_html = [
        'text',
        'email',
        'tel',
        'number',
        'search',
        'password',
        'date',
        'time',
        'file',
        'color',
        'datetime-local',
        'url',
        'month',
        'week',
    ];
    if (in_array($type_html, $text_types_html)) {
        $variables['attributes']['class'][] = 'form-element';
        $variables['attributes']['class'][] = Html::getClass('form-element--type-' . $type_html);
        $variables['attributes']['class'][] = Html::getClass('form-element--api-' . $type_api);
        if (!empty($variables['element']['#autocomplete_route_name'])) {
            $variables['autocomplete_message'] = t('Loading…');
        }
    }
    if (in_array($type_html, [
        'checkbox',
        'radio',
    ])) {
        $variables['attributes']['class'][] = 'form-boolean';
        $variables['attributes']['class'][] = Html::getClass('form-boolean--type-' . $type_html);
    }
}
RSS feed
Powered by Drupal