You are here

public function field_validation_oneofseveral_validator::validate in Field Validation 7.2

Validate field.

Overrides field_validation_validator::validate

File

plugins/validator/field_validation_oneofseveral_validator.inc, line 21

Class

field_validation_oneofseveral_validator

Code

public function validate() {
  $flag = FALSE;
  $group_name = $this->rule->settings['data'];
  $field_values = $this
    ->get_field_column_value($this->items, $this->rule->col);
  $field_values = array_flip($field_values);
  if (count($field_values) > 0) {
    $flag = TRUE;
  }
  if (!$flag) {
    ctools_include('export');
    $other_group_rules = ctools_export_load_object('field_validation_rule', 'conditions', array(
      'entity_type' => $this->rule->entity_type,
      'bundle' => $this->rule->bundle,
      'validator' => $this->rule->validator,
    ));
    foreach ($other_group_rules as $other_group_rule) {

      // Skip when do not have the same group name, rule is disabled, equal to current rule.
      if ($other_group_rule->settings['data'] != $group_name || !empty($other_group_rule->disabled) || $other_group_rule->name == $this->rule->name) {
        continue;
      }
      $other_items = isset($this->entity->{$other_group_rule->field_name}[$this->langcode]) ? $this->entity->{$other_group_rule->field_name}[$this->langcode] : array();
      $other_field_values = $this
        ->get_field_column_value($other_items, $other_group_rule->col);
      $other_field_values = array_flip($other_field_values);
      if (count($other_field_values) > 0) {
        $flag = TRUE;
        break;
      }
    }
  }
  if (!$flag) {
    $this
      ->set_error();
  }
  $break = TRUE;
  return $break;
}