I'm trying to get a Panels page with a path working as a breadcrumb parent to no avail.
For example: Home > [PANELS PAGE] > News item node title
What I've found odd in my configuration is that if I create a node with a path and set that path as the return value of findParent__node_x(), that the node's title is added into the breadcrumb trail as above.
However, if I remove the node and its path from the system and use a path from a Page created via Page Manager (panels), the breadcrumb does not generate (instead I get Home > News item node title).
Here is the code I'm using:
class mymodule_CrumbsMonoPlugin_nodeTypesTitle implements crumbs_MonoPlugin {
/**
* Information for the configuration form
*/
function describe($api) {
return t("Custom breadcrumb for panel page.");
}
/**
* Target the node/% router path.
*/
function findParent__node_x($path, $item) {
$node = $item['map'][1];
switch ($node->type) {
case 'group':
return 'dashboard/student'; // path
}
}
/**
* Target the node/% router path.
*/
function findTitle__node_x($path, $item) {
return 'Student dashboard'; // title, if not set defaults to node title
}
}
The above code lives in a mymodule.crumbs.inc file, with the following in mymodule.module:
/**
* Implements hook_crumbs_plugins().
*/
function mymodule_crumbs_plugins($api) {
$api->monoPlugin('nodeTypesTitle');
}
The code above is listed under the 'inherit' portion of the textarea and is enabled.
Is it possible to create parent items that aren't explicit nodes with paths or actual menu items? Am i missing something?
Comments
Comment #1
donquixote commentedYou say the node has a path. I suppose you mean the path alias..
Now if you return that same path in findParent(), this means that the node becomes its own breadcrumb parent. This is probably not what you want.
Could you clarify a bit on:
- the path alias of the node
- The path of the panels page.
- The title of the panels page
Thanks!
Comment #2
bsuttis commentedYes, I meant path alias. Path alias is 'hockey'.
For example:
The above outputs the node's title at path alias 'hockey' in the breadcrumb for all nodes that are of type 'group'. Node title is 'Hockey Stats', so breadcrumb is "Home > Hockey Stats > group node title" on 'group' nodes.
Trying to do the same thing with a Page Manager page does not work. For example, a page at path alias 'dashboard/hockey-stats' with title 'Hockey Stats'.
It's my thinking that the above would generate a breadcrumb like "Home > Hockey Stats > group node title", but instead it outputs "Home > group node title".
Comment #3
donquixote commentedAh.. I have an idea.
Can you install devel, and put a dpm like this:
If page manager hijacks the node/% path, it could be that $item['map'][1] no longer works as it used to.
This is just a blind guess, I have not done much with page manager yet.
----------
That said, I still don't get 100% what you are trying to do. I have the suspicion there is a deeper misunderstanding in your approach.
If you totally disable your mymodule, what is the breadcrumb that you get?
I suppose, just "Home > [PANELS PAGE]", without the node title appended?
Also, what is the panels page you are talking about? Is this the node itself, just displayed with panels, or is it something separate?
Comment #4
bsuttis commentedPanels page -- I am using Page Manager to override the node display at node/%nid. It's the node with views embedded that make use of the NID for contextual content.
For example, at node/349:
$item['map'][1] is a stdClass object (I believe it's the node object again, but not output due to 'Recursion').
All I'm trying to do is be able to use a Panels page at an arbitrary path alias as a breadcrumb parent. The page at dashboard/hockey-stats does not have a menu item, just a path alias, but I want this page to act as a parent for node/349. The custom page at dashboard/hockey-stats embeds views, no nodes.
With nothing enabled, my breadcrumb at node/349 is "Home > [node:title]"
Maybe this helps illustrate my point?
Comment #5
donquixote commentedIn your initial example, can you remove the findTitle() thing? This looks just wrong to me, giving every node the same breadcrumb item title.
Then, can you do another dpm(), (no matter where)
dpm(drupal_get_normal_path('dashboard/hockey-stats'));If dashboard/hockey-stats is an alias, then I wonder what is behind that. Or is this already the system path?
Comment #6
bsuttis commentedDoing dpm(drupal_get_normal_path('dashboard/hockey-stats')); returns a string with 'dashboard/hockey-stats'.
This path was created when creating the Panels page.
Removed the findTitle() code.
Comment #7
donquixote commentedI think I have your solution :)
You need a findTitle() method (in addition to the findParent stuff), but it should not target node/% but the panels page.
Otherwise the title for the hockey stats page would be empty, because the menu system does not define a title (if I understand you right). Crumbs will just skip items with empty title.
Does make sense?
Comment #8
bsuttis commentedGreat, it's working as desired now, thanks muchly!
Comment #9
donquixote commentedVery nice to hear!
Comment #10
donquixote commentedHi,
you might want to try crumbs-7.x-1.2.
It has a system based on token, to define a node's parent path.
Let me know if it works :)
Comment #10.0
donquixote commentedGrammar fixes
Comment #11
hawkeye.twolfCan we get this custom Panels page plugin committed to the module?
Comment #12
donquixote commented@derek.deraps (#11):
What exactly do you mean? The one from #7 ?
I'm afraid this is too specific to this case.
Comment #13
hawkeye.twolfHi @donquixote! I mean a plugin that is able to grab the page title from the custom Page Manager page when it's used as a parent path. E.g., I have a custom Page Manager panels page that lives at /departments, and then a bunch of "Department" nodes that live at /departments/*, and I want Crumbs to be able to pull in the title from the Page Manager panels page parent.
Does that make sense?
Thanks!
Derek
Comment #14
donquixote commentedYes, this does make sense.
Can you do some research how to extract the title from the panels page?
Crumbs always starts with something like - in your case -
menu_get_item('departments'). From that we want to extract the title.Ideally, could you
- Check if there is any relevant existing issue in https://www.drupal.org/project/issues/crumbs?text=panels&status=All
- If not, create a new one.
- Try to create a patch, or an implementation idea.
I can handle the Crumbs side, but I am not experienced enough with Panels.
Comment #15
dddbbb commentedI'd also really like to see the suggestion from #13 implemented. Does the fact that this issue is marked as fixed hamper the chances of that? New issue perhaps?
Comment #16
donquixote commentedYes, I guess this would be a new issue.
But ideally someone would do some research, so that the new issue can be very specific.