function cf_error_print_message in Common Functionality 7
Prints error messages to the screen.
This uses drupal_set_message() and watchdog() to print the messages.
Why: This facilitates printing the error messages without having each and every usage need to manually do so.
Parameters
string $message: A string to display.
array $variables_array: An array of string substitutions for anything in the $message string.
string $type: The category to which this message belongs. Can be any string, but the general practice is to use the name of the module calling watchdog().
int $severity: The severity of the message, as per RFC 3164. Possible values are WATCHDOG_ERROR, WATCHDOG_WARNING, etc.
array $function_history: (optional) An array of function names, ie: array('0' => 'my_function_name').
See also
watchdog()
2 calls to cf_error_print_message()
- cf_error_invalid_variable in modules/
cf_error/ cf_error.module - Reports variables as invalid to the watchdog system.
- cf_error_on_query_execution in modules/
cf_error/ cf_error.module - Reports query execution failures to the watchdog system.
File
- modules/
cf_error/ cf_error.module, line 95
Code
function cf_error_print_message($message, $variables_array, $type, $severity, array $function_history = array()) {
cf_error_append_history($function_history, __FUNCTION__);
if (!is_string($message)) {
cf_error_empty_string($function_history, 'message');
return;
}
if (!is_array($variables_array)) {
cf_error_invalid_array($function_history, 'variables_array');
return;
}
if (!is_string($type)) {
cf_error_empty_string($function_history, 'type');
return;
}
if (!is_numeric($severity)) {
cf_error_empty_string($function_history, 'severity');
return;
}
watchdog($type, $message . ", function history: %function_history", $variables_array, $severity);
switch ($severity) {
case WATCHDOG_EMERGENCY:
if (user_access('view cf emergency messages')) {
drupal_set_message(t($message, $variables_array), 'error', FALSE);
}
break;
case WATCHDOG_ALERT:
case WATCHDOG_CRITICAL:
case WATCHDOG_ERROR:
if (user_access('view cf error messages')) {
drupal_set_message(t($message, $variables_array), 'error', FALSE);
}
break;
case WATCHDOG_WARNING:
if (user_access('view cf warning messages')) {
drupal_set_message(t($message, $variables_array), 'warning', FALSE);
}
break;
case WATCHDOG_NOTICE:
case WATCHDOG_INFO:
if (user_access('view cf information messages')) {
drupal_set_message(t($message, $variables_array), 'status', FALSE);
}
break;
case WATCHDOG_DEBUG:
if (user_access('view cf debug messages')) {
drupal_set_message(t($message, $variables_array), 'status', FALSE);
}
break;
}
}