public function date_views_filter_handler_simple::date_parts_form in Date 7.2
Same name and namespace in other branches
- 8 date_views/includes/date_views_filter_handler_simple.inc \date_views_filter_handler_simple::date_parts_form()
- 7.3 date_views/includes/date_views_filter_handler_simple.inc \date_views_filter_handler_simple::date_parts_form()
A form element to select date part values.
Parameters
array $form_state: The data submitted through Form API for this element.
string $prefix: A prefix for the date values, 'value', 'min', or 'max' .
string $source: The operator for this element.
string $which: Which element to provide, 'all', 'value', or 'minmax' .
array $operator_values: An array of the allowed operators for this element.
string $identifier: Identifier of the exposed element.
string $relative_id: Form element ID to use for the relative date field.
Return value
The form date part element for this instance.
1 call to date_views_filter_handler_simple::date_parts_form()
- date_views_filter_handler_simple::value_form in date_views/
includes/ date_views_filter_handler_simple.inc - Add a type selector to the value form.
File
- date_views/
includes/ date_views_filter_handler_simple.inc, line 399 - A standard Views filter for a single date field.
Class
- date_views_filter_handler_simple
- A standard Views filter for a single date field.
Code
public function date_parts_form(array &$form_state, $prefix, $source, $which, array $operator_values, $identifier, $relative_id) {
module_load_include('inc', 'date_api', 'date_api_elements');
switch ($prefix) {
case 'min':
$label = t('Start date');
$relative_label = t('Relative start date');
break;
case 'max':
$label = t('End date');
$relative_label = t('Relative end date');
break;
default:
$label = '';
$relative_label = t('Relative date');
}
$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'], 'display');
$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.
$label = $this->options['expose']['label'];
$default_date = $this
->date_default_value($prefix);
$id = 'edit-' . str_replace('_', '-', $this->field) . '-' . $prefix;
$form[$prefix] = array(
'#title' => check_plain($label),
'#title_display' => 'invisible',
'#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 . '-inside-wrapper">',
'#suffix' => '</div></div>',
);
if ($which == 'all') {
$form[$prefix]['#pre_render'][] = 'ctools_dependent_pre_render';
$form[$prefix]['#dependency'] = array(
$source => $operator_values,
);
}
// Validate the input value; set form state input array.
$input = isset($form_state['input'][$identifier][$prefix]) ? $form_state['input'][$identifier][$prefix] : array();
$form_state['input'][$identifier][$prefix] = $this
->input_validate($form[$prefix], $input);
if (!isset($form_state['input'][$identifier][$prefix])) {
// Handle bogus input from the query string to prevent fatal errors.
if (isset($form_state['input'][$identifier]) && !is_array($form_state['input'][$identifier])) {
$form_state['input'][$identifier] = array();
}
// Ensure these exist.
foreach ($granularity as $key) {
$form_state['input'][$identifier][$prefix][$key] = NULL;
}
}
}
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 . '-inside-wrapper">',
'#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;
}