public function context_redirect_reaction::execute in Context Redirect 7
Same name and namespace in other branches
- 6 context_redirect_reaction.inc \context_redirect_reaction::execute()
Implements execute().
File
- ./
context_redirect_reaction.inc, line 74 - Context redirect reaction plugin for Context API.
Class
- context_redirect_reaction
- @file Context redirect reaction plugin for Context API.
Code
public function execute() {
$contexts = $this
->get_contexts();
// Check if we need to react to current Contexts.
foreach ($contexts as $context) {
if (!empty($context->reactions[$this->plugin])) {
if ($url = $context->reactions[$this->plugin]['redirect_path']) {
// Do nothing if this reaction is an invalid redirection.
if ($this
->context_redirect_validate_redirect($url, $context)) {
// Display a message if required.
if ($context->reactions[$this->plugin]['enable_message'] && !(url_is_external($url) && !context_redirect_external_url_is_local($url))) {
drupal_set_message(t('@message', array(
'@message' => check_plain($context->reactions[$this->plugin]['redirect_message']),
)));
}
// Start building an $options array for drupal_goto().
$options = array();
// Preserve the current query parameters if required.
if ($context->reactions[$this->plugin]['qsa']) {
$options['query'] = drupal_get_query_parameters();
}
// Log a watchdog notice.
watchdog('context_redirect', 'User was redirected with the @context context, from @from to @destination.', array(
'@context' => $context->name,
'@from' => current_path(),
'@destination' => $url,
), WATCHDOG_NOTICE, l("Configure {$context->name} context", "admin/structure/context/list/{$context->name}"));
// If the url is "external" according to url_is_external()
// && the url is a domain defined by the Domain Access module
// && the current url is not a registered path on this domain
// then the 'destination' is set to the current internal path,
// leading to an infinite redirect from drupal_goto().
// @see http://drupal.org/node/1883796
if (url_is_external($url) && isset($_GET['destination'])) {
unset($_GET['destination']);
}
// Perform the redirection.
$http_response_code = isset($context->reactions[$this->plugin]['redirect_type']) ? $context->reactions[$this->plugin]['redirect_type'] : 302;
drupal_goto($url, $options, $http_response_code);
}
}
}
}
}