Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi I'm trying to set a #default_value for a field which is not accessible ie: #access => FALSE
$form['date'] = array(
'#type' => 'date_popup',
'#title' => t('Date'),
'#access' => FALSE,
'#default_value' => '2009-06-18 04:31:00',
'#date_format' => 'Y-m-d H:i:s',
);
But the value ($node->date) I get on hook_insert or hook_update is something like '0009-06-18 04:31:00' or '1009-06-18 04:31:00', notice the first number changed. I ran it through a debugger and found out this, comment on the code
function _form_set_value(&$form_values, $form_item, $parents, $value) {
$parent = array_shift($parents);
if (empty($parents)) {
// here $form_values = '2009-06-18 04:31:00', $parent = 'date', $value = '18/06/2009'
// thus it's setting $form_values['date'] = '18/06/2009';
// i don't know where the bug is though
$form_values[$parent] = $value;
}
else {
if (!isset($form_values[$parent])) {
$form_values[$parent] = array();
}
_form_set_value($form_values[$parent], $form_item, $parents, $value);
}
}
Comment | File | Size | Author |
---|---|---|---|
#1 | date.patch | 775 bytes | ariflukito |
Comments
Comment #1
ariflukito CreditAttribution: ariflukito commentedtemporary fix
maybe the better fix is by unsetting the element value first on form process and reconstruct the element value from its sub element values.
Comment #2
rconstantine CreditAttribution: rconstantine commentedI'm having the same issue. I can't seem to figure out how to set the default value. I'll check out the patch.
Comment #3
DamienMcKennaUnfortunately the Drupal 6 version of the Date module is no longer supported. That said, we appreciate that you took time to work on this issue. Should this request still be relevant for Drupal 7 please feel free to reopen it. Thank you.