Skip to content

Commit

Permalink
Add more conditions to avoid redirect.
Browse files Browse the repository at this point in the history
  • Loading branch information
amitaibu committed Nov 14, 2014
1 parent 1c3f9a7 commit c755f46
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion modules/zariz_ui/zariz_ui.install
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ function zariz_ui_install() {
*/
function zariz_ui_uninstall() {
variable_del('zariz_ui_deny_crud_on_master');
variable_del('zariz_ui_redirect_tom_master');
variable_del('zariz_ui_redirect_to_master');
}
38 changes: 29 additions & 9 deletions modules/zariz_ui/zariz_ui.module
Original file line number Diff line number Diff line change
Expand Up @@ -236,25 +236,34 @@ function zariz_ui_preprocess_html(&$variables) {
/**
* Implements hook_init().
*
* Redirect or set context.
*
* Redirect or set OG context.
*/
function zariz_ui_init() {
if (strpos($_GET['q'], 'batch') === 0) {
// Batch process.
return;
}

if (strpos($_GET['q'], 'admin/') === 0) {
if ($_GET['q'] == 'admin' || strpos($_GET['q'], 'admin/') === 0) {
// Admin pages.
return;
}

if (strpos($_GET['q'], 'admin_menu/') === 0) {
// Admin menu pages.
return;
}

if (strpos($_GET['q'], 'js/admin_menu/cache') === 0) {
// Admin menu JS cache.
return;
}

if (strpos($_GET['q'], 'system/ajax') === 0) {
// Admin menu JS cache.
return;
}

zariz_ui_purl_redirect_by_context();
}

Expand Down Expand Up @@ -291,6 +300,11 @@ function zariz_ui_page_build(&$page) {
$branch_id = $og_context['gid'];
$wrapper = entity_metadata_wrapper('node', $branch_id);

if ($wrapper->getBundle() != 'branch') {
// Not a branch.
return;
}

// Show a trail from the current branch, up to it's parents, e.g. live >> dev.
$branch_trail = array();
if ($branch_ids = zariz_get_branch_parents_ids($branch_id, FALSE)) {
Expand Down Expand Up @@ -389,11 +403,18 @@ function zariz_ui_toolbar_access() {
*/
function zariz_ui_purl_redirect_by_context() {
if (drupal_is_cli()) {
// Request is form the CLI.
return;
}

if (purl_disable()) {
// PURL is disabled for this request.
return;
}

if (!$og_context = og_context()) {
if (!$master_nid = variable_get('zariz_master_branch')) {
// No master branch defined.
return;
}
$id = $master_nid;
Expand All @@ -416,7 +437,7 @@ function zariz_ui_purl_redirect_by_context() {
return;
}

if (variable_get('zariz_ui_redirect_tom_master', TRUE)) {
if (variable_get('zariz_ui_redirect_to_master', TRUE)) {
// Redirect to the master branch.
$purl_params = array(
'query' => drupal_get_query_parameters($_GET, array('q')),
Expand All @@ -428,10 +449,9 @@ function zariz_ui_purl_redirect_by_context() {
unset($_GET['destination']);
purl_goto('<front>', $purl_params);
}
else {
// Set the context, without redirect.
$node = node_load($id);
og_context('node', $node);
}

// Set the context, without redirect.
$node = node_load($id);
og_context('node', $node);
}

0 comments on commit c755f46

Please sign in to comment.