May 20, 2019 in Drupal 8, Snippets

The typical 'from' 'to' datefields are not quite good for usability. With the following snippet you can change the labels in a drupal 8 website..

/**
 * @param $form
 * @param FormStateInterface $form_state
 * @param $form_id
 */
function MYMODULE_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  if($form_id == 'views_exposed_form' && $form['#id'] == 'views-exposed-form-VIEW_ID') {
    $form['date']['min']['#title'] = 'Date between';
    $form['date']['max']['#title'] = 'and';
  }
}