You are here

function rules_forms_condition_attribute_value in Rules Forms Support 7.2

Condition: Form element attribute has value.

1 string reference to 'rules_forms_condition_attribute_value'
rules_forms_rules_condition_info in ./rules_forms.rules.inc
Implements hook_rules_condition_info().

File

includes/rules_forms.eval.inc, line 59
Evaluation functions for Rules Forms module.

Code

function rules_forms_condition_attribute_value($wrapper, $value, $regex, $settings, $state, $element) {
  if ($wrapper instanceof RulesFormsAttributeWrapper) {
    $attribute_value = $wrapper
      ->value();

    // Perform the comparison with a regular expression if necessary.
    if ($wrapper
      ->type() == 'text' && $regex) {

      // Allow multiple regular expressions to be run, one on each line.
      // Return FALSE immediately if an expression fails.
      $lines = explode("\r\n", $value);
      foreach ($lines as $line) {
        $result = preg_match($line, $attribute_value) == 1;
        if ($result === FALSE) {
          return FALSE;
        }
      }
      return TRUE;
    }

    // Multiple values come in as array.
    if (is_array($attribute_value)) {
      $lines = explode("\r\n", $value);
      return rules_forms_equal_array_values($lines, $attribute_value);
    }
    return $attribute_value === $value;
  }
  else {
    return $wrapper === $value;
  }
}