I have some fields that are "Date and time". I want to ignore the time portion and only solicit date portion from the user. However, since there is already have data in these fields, Drupal does not allow me to easily change the field to "Date". I feel like there must be a simple trick to hide the time portion from the form, but I can't figure out how to do this (without going the install script route of changing a data type). Any ideas? Maybe something in a form_alter? Drupal 9. Thank you
Adding: I am trying to use the hook element_info_alter to hide the time portion, which works well. However, I run into the problem where upon submit, it fails the verification for datetime, so I am trying to duplicate the datetime verification routine, except it will ignores the time portion. BUt I haven't got that working. There must be a Is there a simpler way to do this, or no?
function modulename_element_info_alter(array &$types) {
$types['datetime']['#process'][] = 'our_datetime_set_format';
}
function our_datetime_set_format($element) {
$fname = $element['#parents'][0]; //field name
if (want_dateonly($fname)) {
$element['time']['#access'] = FALSE; //hides the time portion
$element['#date_time_format'] = '';
$element['#date_time_element'] = 'none';
$element['#element_validate'][0] = 'validateDateSkipTime';
}
return $element;
}