I created a 'video' content type on my site, and used pathauto to make the paths for video nodes always /video/[nid]. Then, in my custom module's implementation of hook_admin_paths_alter(), I added the path video/*. (I've added a bunch of other paths for forms I wanted to open in the overlay, and they all work fine).

When I click a link to a video (using the video/[nid] path), the overlay begins to appear (the dark overlay covers the screen), but before the content is loaded in, the page redirects to the actual node itself, at video/[nid]. I'm presuming this might have something to do with the fact that node/%node/view is overriding something the overlay is doing... but I couldn't figure out how to get a node to appear (viewing, not just editing) inside the overlay.

As a workaround, I added the path video/popup/% to my module's hook_menu() implementation, and in the callback, I set the page title and body content appropriately. Then, inside hook_admin_paths_alter(), I add the appropriate path to the $paths array. This works for me, but it was annoying having to figure out that overlay won't display node contents correctly.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

David_Rothstein’s picture

So is the issue that hook_admin_paths() doesn't work with path aliases?

I think it may have only been designed to work with system paths, but (a) the documentation is unclear, (b) it sounds from the description above like it "almost" works (overlay starts to open and then closes again), and (c) it would definitely be useful to do what's described above (have the admin path status depend on the node type) and I don't think there's any reasonable way to achieve that without using path aliases.

geerlingguy’s picture

It looks like it doesn't work at all when I try using node/* paths... so the issue is still that it won't display node content.

To be clear, neither of the following paths will work in the Overlay (I added them via hook_admin_paths_alter():

  • 'node/*' => TRUE, - normal node path
  • 'video/*' => TRUE, - path alias to video nodes
David_Rothstein’s picture

Hm, I just tried 'node/*' => TRUE in hook_admin_paths_alter() and it worked fine for me.

Maybe you should post an example of the exact code you're using?

geerlingguy’s picture

Here's the entire code from that hook:

/**
 * Implements hook_admin_paths_alter().
 *
 * We alter paths in the custom module, once for all, because there are many
 * paths which we'd like to have open in the overlay. Adding them here is
 * conceptually more sound than adding them in all our different modules.
 */
function custom_admin_paths_alter(&$paths) {
  // Disable all admin paths from opening in overlay.
  foreach ($paths as &$path) {
    $path = FALSE;
  }
  // Add our own paths to the overlay here. (At least one path must be defined).
  $paths = array(
    'flag/confirm/*/subscription/*' => TRUE, // Add subscription forms - @see subscribe.module.
    'messages/new/*' => TRUE, // Add new Private Message path - @see privatemsg.module.
    'video/popup/*' => TRUE, // Videos popups.
    'node/*' => TRUE, // All nodes in popups - doesn't work.
  );
}

I only want to use Overlay for the paths I define. Perhaps the problem comes from disabling other admin paths?

David_Rothstein’s picture

Hm, I still can't reproduce that problem. I just tried creating a custom module, pasting the above code into it, and turning on the module. For node/* paths, everything worked as the code said it should - they all appeared inside the overlay for me.

Any chance you have some other module installed which is implementing hook_admin_paths_alter() and overriding this?

Perhaps the problem comes from disabling other admin paths?

I don't think it should. But it looks to me like the code you have for doing that disabling is unnecessary (since at the end you completely rewrite the $paths variable with a new value anyway).

geerlingguy’s picture

Status: Active » Closed (works as designed)

I'll mark it as works as designed, as you can get it to work... I'm not sure why I can't get it working on this particular site, but other sites do work. I removed the unsetting of all the $paths, and it's still working well, but I don't have any other module (contrib or custom) that implements hook_admin_paths_alter(), so it's simply a bit confusing.

Maybe someone else will have the problem at some point and find something helpful :)

rooby’s picture

I know this is an old issue but your code snippet has a problem in that you are setting all the existing values to false for no reason as then you replace the whole existing array with your new array.

You could get rid of your foreach loop.

Also, if your module doesn't run last other modules could add more overlay paths after you get rid of them all.

chertzog’s picture

Component: overlay.module » path.module
Status: Closed (works as designed) » Needs review
FileSize
752 bytes

I'm getting this problem in a similar way. Say we have 2 content types tasks and projects. We use pathauto to set the alias to 'projects/[node:title]' and 'tasks/[node:title]'.

We want to show projects in the default theme, but show tasks in the overlay. So we implement hook_admin_paths_alter.

function mymodule_admin_paths_alter(&$paths){
  $paths['tasks/*'] = TRUE;
}

This causes the overlay to start to render (url shows: "/...#overlay=tasks/taskname"), but then it redirects to the actual node (url shows: "/tasks/taskname").

However, if we change our hook implementation:

function mymodule_admin_paths_alter(&$paths){
  $paths['tasks/*'] = TRUE;
  $paths['node/*'] = TRUE;
}

This causes the desired result. The task node is rendered in the overlay. But then if we go over and take a look at a project node, the node is not rendered in the overlay, but instead is rendered in the administrative theme. So i thought lets do something like this:

function mymodule_admin_paths_alter(&$paths){
  $paths['tasks/*'] = TRUE;
  $paths['node/*'] = TRUE;
  $paths['projects/*'] = FALSE;
}

But this doesnt do anything.

So i traced to problem back and it seems to be a problem in path_is_admin($path). The $path when viewing a node is always "node/*".

Attached is a patch which check the path for an alias then proceeds to set that path as admin.

ohthehugemanatee’s picture

This patch applies cleanly to D7 current stable as well. Solved my problem.

enricotersi’s picture

The patch in #8 works for me. Thanks!

SocialNicheGuru’s picture

I am using D7.14 and it doesn't apply for me:

git apply admin-path-alias-124074-8-d8.patch
admin-path-alias-124074-8-d8.patch:14: trailing whitespace.
$path_map['non_admin'][$path] = drupal_match_path($alias, $patterns['non_admin']);
error: core/includes/path.inc: No such file or directory

doens't apply because of /a/core

but with patch it does:
patch -p1 < *patch
can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/core/includes/path.inc b/core/includes/path.inc
|index 223ab04..6bca12b 100644
|--- a/core/includes/path.inc
|+++ b/core/includes/path.inc
--------------------------
File to patch: ./includes/path.inc
patching file ./includes/path.inc

chertzog’s picture

The patch was for D8. You should be able to just remove the /core and it should be good for D7.

swentel’s picture

Status: Needs review » Needs work
+++ b/core/includes/path.incundefined
@@ -499,6 +499,13 @@ function path_is_admin($path) {
+    $path_map['non_admin'][$path] = drupal_match_path($alias, $patterns['non_admin']);	

There's whitespace at the end.

Also, I think you can move this code into the if statement. Than you can drop the second call to path_get_admin_paths() as well.

chertzog’s picture

This patch fixes the whitespace and another small coding style. As for moving the code into the if statement, which if statement? the one i introduced, or the previous one?

milos.kroulik’s picture

I confirm, that this works well for me in D7. Do you think, that it can be commited?

ñull’s picture

Issue summary: View changes

The number of followers can influence the priority? Would like to see a back-port for D7 too!

nod_’s picture

Version: 8.x-dev » 7.x-dev

Overlay doesn't exist in D8.

David_Rothstein’s picture

Title: Overlay won't display node content » hook_admin_paths() doesn't work with path aliases?
Version: 7.x-dev » 8.x-dev
Issue tags: +Needs backport to D7

Better title.

Patch still applies to Drupal 8 - doesn't even need a reroll, amazingly :)

David_Rothstein’s picture

Title: hook_admin_paths() doesn't work with path aliases? » hook_admin_paths() doesn't work with path aliases

Oops.

dawehner’s picture

Note: #1316692: Convert hook_admin_paths() into declarative properties on routes would fix this bug automatically as paths are not longer important.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dunot’s picture

I can't see /core/includes/path.inc

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

catch’s picture

Version: 8.9.x-dev » 7.x-dev
Issue tags: -Needs backport to D7 +Bug Smash Initiative

hook_admin_paths() doesn't exist in Drupal 8/9.