function bartik_form_alter

Same name in other branches
  1. 9 core/themes/bartik/bartik.theme \bartik_form_alter()

Implements hook_form_alter() to add classes to the search form.

File

core/themes/bartik/bartik.theme, line 117

Code

function bartik_form_alter(&$form, FormStateInterface $form_state, $form_id) {
    if (in_array($form_id, [
        'search_block_form',
        'search_form',
    ])) {
        $key = $form_id == 'search_block_form' ? 'actions' : 'basic';
        if (!isset($form[$key]['submit']['#attributes'])) {
            $form[$key]['submit']['#attributes'] = new Attribute();
        }
        $form[$key]['submit']['#attributes']->addClass('search-form__submit');
    }
}

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