Closed (fixed)
Project:
Custom Breadcrumbs
Version:
6.x-2.x-dev
Component:
custom_breadcrumbs
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
7 Oct 2010 at 08:07 UTC
Updated:
5 Nov 2010 at 16:00 UTC
Just looking for information here, because this looks super-weird at first glance, and there is no explanation in the function's header comment.
custom_breadcrumbs.module implements hook_preprocess(), which means that code is run for every single template-based theme call.
Is this really necessary?
Comments
Comment #1
MGN commentedIts used to (optionally) set the home breadcrumb on every page. This seems to be the best approach suggested thus far to provide this feature.
Comment #2
jweowu commentedWhy is it not restricted to the 'page' template?
I can understand using
hook_preprocess()as a method of getting in ahead oftemplate_preprocess_page()(another way is to usehook_preprocess_page()andhook_theme_registry_alter()to reorder the preprocess functions), but I'm a bit confused as to why this code is run for every template called?It would be great if there was a comment added to the code to indicate the problem that this is a solution to?
Comment #3
MGN commentedIn custom_breadcrumbs.module, I think it could be restricted to the page template, since it is doing the same thing on every page.
In custom_breadcrumbsapi, it is not restricted to the page template so you can define custom breadcrumbs based on the theme template called on a particular page. For example, you can use this module to customize the breadcrumb trail on the forum topic list page, or any other page that defines a template. Even if the module sets its own breadcrumb on these pages, you can customize it using this feature.
I agree it should be better documented - in all the custom breadcrumbs modules. I'll look into changing the base custom breadcrumbs module to only fire on the page template. As long as we can set the HOME breadcrumb on every page in the site, I think this should be sufficient.
Thanks for the suggestion.
Comment #4
MGN commented@jweowu, I tried your suggestion to implement hook_preprocess_page() instead of hook_preprocess(), but it doesn't fire on many pages - anything under admin/*, (i.e. administration forms), for example. But I have found that I can use hook_preprocess, with an if clause only executing code if ($hook == 'page') ... . I am not sure why this works on every page, but hook_preprocess_page doesn't. Any ideas? Other suggestions for tightening up this code?
Thanks
EDIT: The following seems to work:
Comment #5
jweowu commentedLooking at _theme_process_registry(), it looks to me like it should have picked your hook_preprocess_page(), provided you remembered to clear the theme registry before testing it?
Comment #6
MGN commentedThanks. I thought I was clearing the cache, but apparently not. I just tried again and now hook_preprocess_page gets called on every page, as expected. I'll commit the changes to 6.x-2.x-dev soon. Thanks again for helping with this.
Comment #7
MGN commentedCommitted to 6.x-2.x-dev.