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.
Comment | File | Size | Author |
---|---|---|---|
#14 | admin-path-alias-124074-8-d8.patch | 752 bytes | chertzog |
#8 | admin-path-alias-124074-8-d8.patch | 752 bytes | chertzog |
Comments
Comment #1
David_Rothstein CreditAttribution: David_Rothstein commentedSo 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.
Comment #2
geerlingguy CreditAttribution: geerlingguy commentedIt 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 nodesComment #3
David_Rothstein CreditAttribution: David_Rothstein commentedHm, 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?
Comment #4
geerlingguy CreditAttribution: geerlingguy commentedHere's the entire code from that hook:
I only want to use Overlay for the paths I define. Perhaps the problem comes from disabling other admin paths?
Comment #5
David_Rothstein CreditAttribution: David_Rothstein commentedHm, 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?
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).
Comment #6
geerlingguy CreditAttribution: geerlingguy commentedI'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 :)
Comment #7
rooby CreditAttribution: rooby commentedI 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.
Comment #8
chertzogI'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.
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:
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:
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.
Comment #9
ohthehugemanatee CreditAttribution: ohthehugemanatee commentedThis patch applies cleanly to D7 current stable as well. Solved my problem.
Comment #10
enricotersi CreditAttribution: enricotersi commentedThe patch in #8 works for me. Thanks!
Comment #11
SocialNicheGuru CreditAttribution: SocialNicheGuru commentedI 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
Comment #12
chertzogThe patch was for D8. You should be able to just remove the /core and it should be good for D7.
Comment #13
swentel CreditAttribution: swentel commentedThere'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.
Comment #14
chertzogThis 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?
Comment #15
milos.kroulik CreditAttribution: milos.kroulik commentedI confirm, that this works well for me in D7. Do you think, that it can be commited?
Comment #16
ñull CreditAttribution: ñull commentedThe number of followers can influence the priority? Would like to see a back-port for D7 too!
Comment #17
nod_Overlay doesn't exist in D8.
Comment #18
David_Rothstein CreditAttribution: David_Rothstein commentedBetter title.
Patch still applies to Drupal 8 - doesn't even need a reroll, amazingly :)
Comment #19
David_Rothstein CreditAttribution: David_Rothstein commentedOops.
Comment #20
dawehnerNote: #1316692: Convert hook_admin_paths() into declarative properties on routes would fix this bug automatically as paths are not longer important.
Comment #26
dunot CreditAttribution: dunot commentedI can't see /core/includes/path.inc
Comment #30
catchhook_admin_paths() doesn't exist in Drupal 8/9.