You are here

function cf_is_not_form_state in Common Functionality 7.2

Same name and namespace in other branches
  1. 7 cf.module \cf_is_not_form_state()

Checks if the argument is a valid drupal form state array.

A valid form state is defined by form_state_defaults(). This helps ensure that this argument is a valid form state. This handles reporting if the form state is invalid.

Justification: Checking if the form_state is valid on every function call can quickly clutter up the code, reducing readability. form state is common enough to have its own cf error checking function.

Parameters

string $argument_name: The variable name of the argument in question.

$variable: The argument that is to be validated.

int $severity: (optional) This is passed directly to watchdog and represents the severity of the report.

Return value

bool When the check passed returns TRUE, FALSE otherwise.

Related topics

1 call to cf_is_not_form_state()
cf_field_cardinality_validate in modules/cf_field_cardinality/cf_field_cardinality.module
When the cardinality was changed, the possible options had to be removed. This, however, allows for non-numeric values to be inserted and therefore additional validation is needed.

File

./cf.module, line 381
Common Functionality module.

Code

function cf_is_not_form_state($argument_name, $variable, $severity = WATCHDOG_WARNING) {
  if ($argument_name == '') {
    if (class_exists('cf_error')) {
      cf_error::empty_string('argument_name');
    }
  }
  if (!is_array($variable)) {
    if (class_exists('cf_error')) {
      cf_error::invalid_array('argument_name', $variable, $severity);
    }
    return TRUE;
  }
  foreach (array_keys(form_state_defaults()) as $key) {
    if (!array_key_exists($key, $variable)) {
      if (class_exists('cf_error')) {
        cf_error::missing_array_key($argument_name, $key, $severity);
      }
      return TRUE;
    }
  }
  return FALSE;
}