class context_error_context_condition_error in Context error 7
Same name and namespace in other branches
- 6 plugins/context_error_context_conditions.inc \context_error_context_condition_error
Expose the 404 error page as the context condition.
Hierarchy
- class \context_condition
Expanded class hierarchy of context_error_context_condition_error
2 string references to 'context_error_context_condition_error'
- context_error_context_plugins in ./
context_error.module - Implements hook_context_plugins().
- context_error_context_registry in ./
context_error.module - Implements hook_context_registry().
File
- plugins/
context_error_context_conditions.inc, line 30 - Context condition plugin to provide a trigger for 404 and 403 error pages.
View source
class context_error_context_condition_error extends context_condition {
private $known_errors = array(
CONTEXT_ERROR_403 => '403 Forbidden',
CONTEXT_ERROR_404 => '404 Not Found',
);
function condition_values() {
$values = array();
$values[CONTEXT_ERROR_403] = t('403 only');
$values[CONTEXT_ERROR_404] = t('404 only');
$values[CONTEXT_ERROR_403_404] = t('404 or 403 pages');
$values[CONTEXT_ERROR_NOT_ERROR] = t('Not an error page');
return $values;
}
/**
* Condition form.
*/
function condition_form($context) {
return array(
'#title' => $this->title,
'#description' => t('Select which error case should this condition activate.'),
'#options' => $this
->condition_values(),
'#type' => 'radios',
'#default_value' => count($this
->fetch_from_context($context, 'values')) > 1 ? CONTEXT_ERROR_403_404 : key($this
->fetch_from_context($context, 'values')),
);
}
/**
* Condition form submit handler.
*
* Convert the values to an array, otherwise only string is submitted.
* Store the 403 AND 404 case as an array with both values stored.
*/
function condition_form_submit($values) {
if ($values == CONTEXT_ERROR_403_404) {
return array(
CONTEXT_ERROR_403 => CONTEXT_ERROR_403,
CONTEXT_ERROR_404 => CONTEXT_ERROR_404,
);
}
return array(
$values => $values,
);
}
/**
* Helper function to decide wether we are on a 404 or 403 page or not.
*/
function is_error($header_status) {
foreach ($this->known_errors as $error => $status) {
if ($status == $header_status) {
return TRUE;
}
}
return FALSE;
}
/**
* Execute.
*/
function execute() {
if ($this
->condition_used()) {
$headers = drupal_get_http_header();
foreach ($this
->get_contexts() as $context) {
$errors = $this
->fetch_from_context($context, 'values');
if (isset($headers['status']) && $this
->is_error($headers['status'])) {
foreach ($errors as $error) {
if (isset($this->known_errors[$error]) && $this->known_errors[$error] == $headers['status']) {
$this
->condition_met($context);
}
}
}
else {
if (array_key_exists(CONTEXT_ERROR_NOT_ERROR, $this
->fetch_from_context($context, 'values'))) {
$this
->condition_met($context);
}
}
}
}
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
context_condition:: |
property | |||
context_condition:: |
property | |||
context_condition:: |
property | |||
context_condition:: |
property | |||
context_condition:: |
function | Marks a context as having met this particular condition. | ||
context_condition:: |
function | Check whether this condition is used by any contexts. Can be used to prevent expensive condition checks from being triggered when no contexts use this condition. | ||
context_condition:: |
function | Context editor form for conditions. | 2 | |
context_condition:: |
function | Context editor form submit handler. | ||
context_condition:: |
function | Retrieve options from the context provided. | ||
context_condition:: |
function | Retrieve all contexts with the condition value provided. | 2 | |
context_condition:: |
function | Options form. Provide additional options for your condition. | 4 | |
context_condition:: |
function | Options form submit handler. | ||
context_condition:: |
function | Settings form. Provide variable settings for your condition. | ||
context_condition:: |
function | Clone our references when we're being cloned. | ||
context_condition:: |
function | Constructor. Do not override. | ||
context_error_context_condition_error:: |
private | property | ||
context_error_context_condition_error:: |
function |
Condition form. Overrides context_condition:: |
||
context_error_context_condition_error:: |
function |
Condition form submit handler. Overrides context_condition:: |
||
context_error_context_condition_error:: |
function |
Condition values. Overrides context_condition:: |
||
context_error_context_condition_error:: |
function | Execute. | ||
context_error_context_condition_error:: |
function | Helper function to decide wether we are on a 404 or 403 page or not. |