You are here

function olivero_form_alter in Drupal 9

Implements hook_form_alter() for adding classes and placeholder text to the search forms.

File

core/themes/olivero/olivero.theme, line 189
Functions to support theming in the Olivero theme.

Code

function olivero_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  if (isset($form['actions']['submit']) && count($form['actions']) <= 2) {
    $form['actions']['submit']['#attributes']['class'][] = 'button--primary';
  }
  switch ($form_id) {
    case 'search_block_form':

      // Add placeholder text to keys input.
      $form['keys']['#attributes']['placeholder'] = t('Search by keyword or phrase.');

      // Add classes to the search form submit input.
      $form['actions']['submit']['#attributes']['class'][] = 'search-form__submit';
      break;
    case 'search_form':
      $form['basic']['keys']['#attributes']['placeholder'] = t('Search by keyword or phrase.');
      $form['basic']['submit']['#attributes']['class'][] = 'button--primary';
      $form['advanced']['submit']['#attributes']['class'][] = 'button--primary';
      break;
  }
}