1 date.module | date_field_widget_properties_alter(&$widget, $context) |
Implements hook_field_widget_properties_alter().
Alters the widget properties of a field instance before it gets displayed. Used here to flag new entities so we can later tell if they need default values.
File
- core/
modules/ date/ date.module, line 629 - Defines date/time field types.
Code
function date_field_widget_properties_alter(&$widget, $context) {
if (in_array($widget['type'], array('date_select', 'date_text', 'date_popup'))) {
$entity_type = $context['entity_type'];
$entity = $context['entity'];
$info = entity_get_info($entity_type);
$id = $info['entity keys']['id'];
$widget['is_new'] = FALSE;
if (empty($entity->$id)) {
$widget['is_new'] = TRUE;
}
}
}