You are here

function shs_conditional_fields_states_handler_shs in Simple hierarchical select 7

States handler for simple hierarchical selects.

File

./shs.module, line 260
Provides an additional widget for term fields to create hierarchical selects.

Code

function shs_conditional_fields_states_handler_shs($field, $field_info, &$options, &$state) {
  switch ($options['values_set']) {
    case CONDITIONAL_FIELDS_DEPENDENCY_VALUES_WIDGET:
    case CONDITIONAL_FIELDS_DEPENDENCY_VALUES_AND:
      if (empty($state[$options['state']][$options['selector']])) {
        return;
      }
      $old_state = $state[$options['state']][$options['selector']];
      if (isset($old_state['value'][0]['tid'])) {

        // Completly remove old state.
        unset($state[$options['state']][$options['selector']]);
        $options['selector'] .= '-0-tid';
        $state[$options['state']][$options['selector']] = $old_state;
        $state[$options['state']][$options['selector']]['value'] = $old_state['value'][0]['tid'];
      }
      return;
    case CONDITIONAL_FIELDS_DEPENDENCY_VALUES_XOR:
      $select_states[$options['state']][] = 'xor';
    case CONDITIONAL_FIELDS_DEPENDENCY_VALUES_REGEX:
      $regex = TRUE;
    case CONDITIONAL_FIELDS_DEPENDENCY_VALUES_NOT:
    case CONDITIONAL_FIELDS_DEPENDENCY_VALUES_OR:
      foreach ($options['values'] as $value) {
        $select_states[$options['state']][] = array(
          $options['selector'] => array(
            $options['condition'] => empty($regex) ? array(
              $value,
            ) : $options['value'],
          ),
        );
      }
      break;
  }
  $state = $select_states;
}