You are here

function conditional_fields_states_handler_date_combo in Conditional Fields 7.3

States handler for date combos.

File

./conditional_fields.module, line 1839
Define dependencies between fields based on their states and values.

Code

function conditional_fields_states_handler_date_combo($field, $field_info, $options, &$state) {

  // Date text.
  if ($field_info['instance']['widget']['type'] == 'date_text') {
    if ($options['values_set'] == CONDITIONAL_FIELDS_DEPENDENCY_VALUES_WIDGET) {
      $state[$options['state']][$options['selector']]['value'] = $state[$options['state']][$options['selector']]['value'][0]['value']['date'];
    }
    return;
  }

  // Add a condition for each date part.
  $date_selectors = array();
  $regex = $options['values_set'] == CONDITIONAL_FIELDS_DEPENDENCY_VALUES_REGEX;

  // Date popup.
  if ($field_info['instance']['widget']['type'] == 'date_popup') {
    $date_selectors[conditional_fields_field_selector($field['value']['date'])] = array(
      'value' => $regex ? $options['value'] : $options['value_form'][0]['value']['date'],
    );
    if ($field_info['field']['settings']['granularity']['hour'] || $field_info['field']['settings']['granularity']['minute'] || $field_info['field']['settings']['granularity']['second']) {
      $date_selectors[conditional_fields_field_selector($field['value']['time'])] = array(
        'value' => $regex ? $options['value'] : $options['value_form'][0]['value']['time'],
      );
    }
  }
  else {
    foreach ($field_info['field']['settings']['granularity'] as $date_part) {
      if ($date_part) {
        $date_selectors[conditional_fields_field_selector($field['value'][$date_part])] = array(
          'value' => $regex ? $options['value'] : $options['value_form'][0]['value'][$date_part],
        );
      }
    }
  }
  $state = array(
    $options['state'] => $date_selectors,
  );
}