You can override the handler used by the Date module using code similar to the following one.
mymodule.module
function mymodule_views_api() {
return array(
'api' => 3,
'path' => drupal_get_path('module', 'mymodule') . '/includes',
);
}
function mymodule_module_implements_alter(&$implementations, $hook) {
if ($hook == 'views_field_views_data_alter') {
$group = $implementations['mymodule'];
unset($implementations['mymodule']);
$implementations['mymodule'] = $group;
}
}
function mymodule_views_field_views_data_alter(&$result, $field, $module) {
if ($module == 'date') {
foreach ($result as $table => $data) {
$additional = array();
$field_name = $field['field_name'];
foreach ($data as $column => $value) {
// For filters, arguments, and sorts, determine if this column is for
// the start date ('value') or the end date ('value2').
$this_column = NULL;
foreach (array_keys($field['columns']) as $candidate_column) {
if ($column == $field['field_name'] . '_' . $candidate_column) {
$this_column = $candidate_column;
break;
}
}
// Only alter the date fields, not timezone, rrule, offset, etc.
if ($this_column != 'value' && $this_column != 'value2') {
continue;
}
// Replace the handler used by the Date module.
if (array_key_exists('filter', $value)) {
$result[$table][$column]['filter']['handler'] = 'mymodule_filter_handler_simple';
}
}
}
}
}
includes/mymodule_filter_handler_simple.inc
class mymodule_filter_handler_simple extends date_views_filter_handler_simple {
function date_parts_form($form_state, $prefix, $source, $which, $operator_values, $identifier, $relative_id) {
module_load_include('inc', 'date_api', 'date_api_elements');
switch ($prefix) {
case 'min':
$label = t('From date');
$relative_label = t('Relative start date');
break;
case 'max':
$label = t('To date');
$relative_label = t('Relative end date');
break;
default:
$label = '';
$relative_label = t('Relative date');
break;
}
$type = $this->options['form_type'];
if ($type == 'date_popup' && !module_exists('date_popup')) {
$type = 'date_text';
}
$format = $this->date_handler->views_formats($this->options['granularity'], 'sql');
$granularity = array_keys($this->date_handler->date_parts($this->options['granularity']));
$relative_value = ($prefix == 'max' ? $this->options['default_to_date'] : $this->options['default_date']);
if (!empty($form_state['exposed'])) {
// UI when the date selector is exposed.
$default_date = $this->date_default_value($prefix);
$id = 'edit-' . str_replace('_', '-', $this->field) . '-' . $prefix;
$form[$prefix] = array(
'#title' => check_plain($label),
'#type' => $type,
'#size' => 20,
'#default_value' => !empty($this->value[$prefix]) ? $this->value[$prefix] : $default_date,
'#date_format' => date_limit_format($format, $granularity),
'#date_label_position' => 'within',
'#date_year_range' => $this->options['year_range'],
'#process' => array($type . '_element_process'),
'#prefix' => '<div id="' . $id . '-wrapper"><div id="' . $id . '">',
'#suffix' => '</div></div>',
);
if ($which == 'all') {
$form[$prefix]['#pre_render'][] = 'ctools_dependent_pre_render';
$form[$prefix]['#dependency'] = array($source => $operator_values);
}
if (!isset($form_state['input'][$identifier][$prefix])) {
$form_state['input'][$identifier][$prefix] = $this->value[$prefix];
}
}
else {
// UI when the date selector is on the views configuration screen.
$default_date = '';
$id = 'edit-options-value-' . $prefix;
$form[$prefix . '_group'] = array(
'#type' => 'fieldset',
'#attributes' => array('class' => array('date-views-filter-fieldset')),
);
$form[$prefix . '_group'][$prefix . '_choose_input_type'] = array(
'#title' => check_plain($label),
'#type' => 'select',
'#options' => array('date' => t('Select a date'), 'relative' => ('Enter a relative date')),
'#attributes' => array('class' => array($prefix . '-choose-input-type')),
'#default_value' => !empty($relative_value) ? 'relative' : 'date',
);
$form[$prefix . '_group'][$prefix] = array(
'#title' => t('Select a date'),
'#type' => $type,
'#size' => 20,
'#default_value' => !empty($this->value[$prefix]) ? $this->value[$prefix] : $default_date,
'#date_format' => date_limit_format($format, $granularity),
'#date_label_position' => 'within',
'#date_year_range' => $this->options['year_range'],
'#process' => array($type . '_element_process'),
'#prefix' => '<div id="' . $id . '-wrapper"><div id="' . $id . '">',
'#suffix' => '</div></div>',
'#states' => array(
'visible' => array(
":input.{$prefix}-choose-input-type" => array('value' => 'date'),
),
),
);
$form[$prefix . '_group'][$relative_id] = array(
'#type' => 'textfield',
'#title' => check_plain($relative_label),
'#default_value' => $relative_value,
'#description' => t("Relative dates are computed when the view is displayed. Examples: now, now +1 day, 12AM today, Monday next week. <a href=\"@relative_format\">More examples of relative date formats in the PHP documentation</a>.", array('@relative_format' => 'http://www.php.net/manual/en/datetime.formats.relative.php')),
'#states' => array(
'visible' => array(
":input.{$prefix}-choose-input-type" => array('value' => 'relative'),
),
),
);
if ($which == 'all') {
$form[$prefix . '_group']['#pre_render'][] = 'ctools_dependent_pre_render';
$form[$prefix . '_group']['#dependency'] = array($source => $operator_values);
}
}
return $form;
}
}