Beginning to toy with impressive form api in 4.7.
I found I needed to do some validation against a date element. I used the nice automatic item, i.e.:
$form['details']['date'] = array(
'#type' => 'date',
'#title' => t('Start date')
);
Then I needed to do some validation. First I wanted to check if the user had set any date at all, but since the date #value automatically defaults to today's date there's no immediately obvious way to distinguish between "not set" and "set for today". Also, no way to doublecheck that a date in the past hasn't been chosen. Other scenarios too..
Anyway, to cut to the chase - I hacked form.inc to pass the timestamp of the default date along with the other info. In the form.inc function expand_date I replaced the first few lines at 788:
// Default to current date
if (!isset($element['#value'])) {
$element['#value'] = array('day' => format_date(time(), 'custom', 'j'),
'month' => format_date(time(), 'custom', 'n'),
'year' => format_date(time(), 'custom', 'Y'));
}
with the following. Note that I've moved generation of date element values outside the conditional because, in the event of a form_error on another form element, we would lose the "today" info if user has already set a date.
<?php
$this_day = format_date(time(), 'custom', 'j');
$this_month = format_date(time(), 'custom', 'n');