I have a date field, birthday
, created with the Date module. By default, the selectable years are 1900-2050. This makes no sense for birthdays so I want to change it to only show years from 1900-(current year-18)
.
How can I do this?
There is a solution for Drupal 7 but that code does not work in Drupal 8 because form_process_date() does not exist in Drupal 8.
This is the full error:
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'form_process_date' not found or invalid function name in Drupal\Core\Form\FormBuilder->doBuildForm() (line 993 of core/lib/Drupal/Core/Form/FormBuilder.php).
Here is the code I'm using:
function mymodule_form_user_register_form_alter(&$form, &$form_state, $form_id) {
$form['account']['birthday']['#process'] = array('form_process_date', 'mymodule_fix_year_range');
drupal_map_assoc
is a really basic function that you could re-make in about a minute, but the link in your question actually contains an example of the replacement method (using the bog standardarray_combine()
). Is there a reason you can't use that?date
, Widget:Select list