You are here

function cf_is_not_form_state in Common Functionality 7

Same name and namespace in other branches
  1. 7.2 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.

Why: 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

array $function_history: An array of function names, ie: array('0' => 'my_function_name').

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.

File

./cf.module, line 406

Code

function cf_is_not_form_state($function_history, $argument_name, $variable, $severity = WATCHDOG_WARNING) {
  cf_error_append_history($function_history, __FUNCTION__);
  if ($argument_name == '') {
    cf_error_empty_string($function_history, 'argument_name');
  }
  if (!is_array($variable)) {
    cf_error_invalid_array($function_history, 'argument_name', $variable, $severity);
    return TRUE;
  }
  foreach (array_keys(form_state_defaults()) as $key) {
    if (!array_key_exists($key, $variable)) {
      cf_error_missing_array_key($function_history, $argument_name, $key, $severity);
      return TRUE;
    }
  }
  return FALSE;
}