You are here

function olivero_form_alter in Drupal 10

Same name and namespace in other branches
  1. 9 core/themes/olivero/olivero.theme \olivero_form_alter()

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

File

core/themes/olivero/olivero.theme, line 195
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;
  }
}