public function availability_calendar_handler_filter_availability::value_form in Availability Calendars 7.5
Same name and namespace in other branches
- 7.3 availability_calendar_handler_filter_availability.inc \availability_calendar_handler_filter_availability::value_form()
- 7.4 views/availability_calendar_handler_filter_availability.inc \availability_calendar_handler_filter_availability::value_form()
Add validation and date popup(s) to the value form.
_state
Parameters
array $form:
Overrides views_handler_filter::value_form
File
- views/
availability_calendar_handler_filter_availability.inc, line 98
Class
- availability_calendar_handler_filter_availability
- Views handler to filter on availability.
Code
public function value_form(&$form, &$form_state) {
$form['value']['#tree'] = TRUE;
if (empty($form_state['exposed'])) {
// We're in Views edit mode self. Add validator here. When we're in an
// exposed form, validation will go via exposed_validate().
$form['value']['#element_validate'][] = 'availability_calendar_handler_filter_availability_validate_value';
}
// Determine the operators to add.
$dependent_element = '';
$operators = $this
->operators();
if (!empty($form_state['exposed'])) {
if (empty($this->options['expose']['use_operator']) || empty($this->options['expose']['operator_id'])) {
// Exposed form with operator not exposed: only add values for the set
// operator.
$operators = array_intersect_key($operators, array(
$this->operator => 0,
));
}
else {
// Exposed form with operator exposed: add all values and dependencies.
$dependent_element = $this->options['expose']['operator_id'];
}
}
else {
// Views UI.
if (!empty($form['operator'])) {
$dependent_element = 'operator';
}
}
if ($dependent_element) {
$dependent_name = str_replace('_', '-', $dependent_element);
$dependency_source = $form[$dependent_element]['#type'] === 'radios' ? "radio:options[{$dependent_name}]" : "edit-{$dependent_name}";
}
else {
$dependency_source = NULL;
}
// Determine values to add and their dependencies.
// Add value fields. As the title is based on both the type of value and the
// operator, we add fields per operator, even if the type of value is the
// same.
$values = array();
foreach ($operators as $operator => $options) {
foreach ($options['values'] as $value) {
if (isset($values[$value])) {
$values[$value][] = $operator;
}
else {
$values[$value] = array(
$operator,
);
}
}
}
foreach ($values as $value => $operators) {
if ($value !== 'duration') {
$form['value'][$value] = $this
->value_form_date_field($values[$value], $value, $dependency_source);
}
else {
$form['value'][$value] = $this
->value_form_duration_field($values[$value], $value, $dependency_source);
}
}
if (module_exists('date_popup')) {
// If we have exactly 1 to field (to or to1) we turn the 2 date pickers
// into 1 date range picker.
if (!empty($form['value']['to'])) {
if (empty($form['value']['to1'])) {
$this
->change_elements_into_date_range_picker($form['value']['from'], 'to');
}
}
else {
if (!empty($form['value']['to1'])) {
$this
->change_elements_into_date_range_picker($form['value']['from'], 'to1');
}
}
}
}