You are here

class context_error_context_condition_error in Context error 6

Same name and namespace in other branches
  1. 7 plugins/context_error_context_conditions.inc \context_error_context_condition_error

Expose the 404 error page as the context condition.

Hierarchy

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 6

View source
class context_error_context_condition_error extends context_condition {
  function condition_values() {
    $values = array();
    $values['403'] = t('403 error');
    $values['404'] = t('404 error');
    return $values;
  }

  /**
   * Execute.
   */
  function execute() {
    if ($this
      ->condition_used()) {

      // Include both the path alias and normal path for matching.
      $current_path = array(
        drupal_get_path_alias($_GET['q']),
      );
      if ($current_path != $_GET['q']) {
        $current_path[] = $_GET['q'];
      }
      foreach ($this
        ->get_contexts() as $context) {
        $errors = $this
          ->fetch_from_context($context, 'values');
        foreach ($errors as $error) {

          // If the site_403 or site_404 variable is set we can match it against
          // the current path.
          if (in_array(variable_get("site_{$error}", ''), $current_path)) {
            $this
              ->condition_met($context);
            continue;
          }

          // If the response headers have already been set, we can match those.
          $current_response = context_error_get_response_from_headers();
          if ((int) $current_response === (int) $error) {
            $this
              ->condition_met($context);
            continue;
          }

          // If logintoboggan is handling the 403 page and we're currently
          // attempting to detect 403 errors, we can check the global variable.
          if ((int) $error === 403) {
            global $logintoboggan_denied;
            $logintoboggan_is_handling_403 = variable_get('site_403', '') === 'toboggan/denied';
            if ($logintoboggan_is_handling_403 && !empty($logintoboggan_denied)) {
              $this
                ->condition_met($context);
            }
          }
        }
      }
    }
  }

}

Members