Closed (fixed)
Project:
Custom Breadcrumbs
Version:
6.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
27 Mar 2010 at 00:29 UTC
Updated:
9 May 2010 at 20:30 UTC
Jump to comment: Most recent file
Comments
Comment #1
derhasi commentedUnfortunately the attached patch files disapperead, so have to upload it again.
Comment #2
derhasi commentedAttached the same patch, but without trailing spaces diffs, so it should be more readable.
Also needs http://drupal.org/files/issues/custom_breadcrumbs.identifiers.inc__0.txt from above
Comment #3
derhasi commentedNew patch attached, because I did not call
custom_breadcrumbs_get_identifiers()intheme_custom_breadcrumbs_help_identifiers().http://drupal.org/files/issues/custom_breadcrumbs.identifiers.inc__0.txt still required.
Comment #4
TripleEmcoder commentedSubscribing.
Comment #5
MGN commentedThanks for contributing this derhasi! I think this is the correct approach, and have been wanting to extend the use of identifiers. Rather than building the identifier-specific code into the custom breadcrumbs module, it makes sense to put it into its own file (like you did in custom_breadcrumbs.identifiers.inc).
I might prefer to do a couple of things slightly differently, but give me a little time to test this out. Most of this looks great.
I am thinking of building on the approach taken in the token module with tokenSTARTER. In this case, we would provide custom_breadcrumbs_identifiers.module and build in the basic identifiers. Then users could add their own identifiers to this module (rather than having to create their own). Of course other modules could use this new api in the way that you intended it as well. As users contributed ideas to extend the base set of identifiers, we could add them to this new module. And if users don't want to use identifiers at all, the module wouldn't need to be enabled. What do you think about this?
I am marking this as needs work for now, just because I want to try out this approach and see if it has merit, not that I see any major problems with your patch.
Comment #6
derhasi commentedThanks for your quick answer.
I don't understand what you mean with "approch in tokenSTARTER", or better to say, I cannot see a differenece to the current patch's approach. So maybe you could explain your thoughts to me.
As you said it would be nice to have a custom_breadcrumbs_identifiers.module that contains some basic identifiers. I agree, but the main functionality (hook implementation,
_custom_breadcrumbs_create_crumb_items()) has to stay in custom_breadcrumbs core. What can be done is to movecustom_breadcrumbs.identifiers.incandcustom_breadcrumbscb_identifiers_info()to the submodule (custom_breadcrumbs_identifiers.module).One thing I don't like about my patch is the handling of
$locationsfor menu set active trail. dereine suggested to use a ctools plugin to remove $locations from the functions. At the moment I don't exactly know, how it could be done with ctools, but could be worth a try.Comment #7
MGN commentedI've modified derhasi's patch so the special identifiers provided by custom breadcrumbs comes in a separate module, custom_breadcrumbs_identifiers. This allows the use of module_implements() and module_invoke() which simplifies the implementation (no need to define separate callback functions and do file includes to provide the feature). It also will better allow for future special identifier expansions.
I've also tried to simplify the approach by providing two hooks that other modules can implement to provide special identifiers : hook_cb_identifier_list() is used in the custom breadcrumbs ui to describe the behavior of each special identifier, and hook_cb_identifier_values() is used to provide the replacement value for the special identifier. As with derhasi's patch, the key feature is that special identifiers can return an array of crumbs.
I found a couple of bugs in the previous patch that are fixed in this one. The home breadcrumb trail is handled correctly now. There was also a typo with a $location needing to be $locations. Finally, I've adjusted the code comments. Otherwise, the approach is the same as in derhasi's patch.
The new submodule includes a
<book-hierarchy>identifier that demonstrates multiple-crumb replacement using parent page titles and paths to form a breadcrumb for book pages. I think this identifier may an improvement over the bookpath tokens.Comment #8
derhasi commentedI'm looking forward to review the patch. But cannot promise to do it until the weekend.
Comment #9
MGN commented@derhasi, have you had a chance to review this? I would like to commit soon and prepare to release 6.x-2.0-beta3.
Comment #10
derhasi commentedMGN, couldn't review it, but will do it tomorrow. Just wrote it down to my todo-list ...
Comment #11
derhasi commentedI finally found time to review your patch.
With your implementation in _custom_breadcrumbs_create_crumb_items() on line 535 you built in a "new feature". As I'm not sure you recognized it, I'll point it out:
Modules can implement identifiers in
hook_cb_identifiers_values()without defining them inhook_cb_identifiers_list().This is an advantage for building multiidentifiers ([identifier-*]) or identifiers with options [identifier:bold:12px]. On the other hand it does not check if the module is "owner" of the identifier by identifying it in
hook_cb_identifiers_list(). This is no problem, it only confused me in the first moment.return value check in _custom_breadcrumbs_create_crumb_items()
A Problem is your return value check in line 537. There the return should be checked on NULL, because a value-function may implement an empty array (
return array()), so it can define an item, that does not return any crumb items. For example this is necessary for a parent-menu-item implementation - if there is no parent item, there should be no crumb for that.In the attached patch I replaced line 537 with
line 539 with
if (isset($values)) {.In
custom_breadcrumbs_identifiers_cb_identifier_valuesthere should be set line 45 to$crumb_items = NULL;.I built a module to implement a parent-menu identifier. It's located on http://github.com/derhasi/dev/tree/custom_breadcrumbs_identifier.
enable custom_breadcrumbs_identifiers on update
For legacy reasons, the new submodule should be enabled automatically, to avoid missing identifiers:
therefore I adjusted custom_breadcrumbs.install:
title check in _custom_breadcrumbs_get_trail_items()
as some identifiers do not need a title to be set, I'd remove or move the title check. Did not implement a "fix" for that in the attachment.
Besides I adjusted the custom_breadcrumbs_identifiers module to fit in coding standards.
Comment #12
MGN commentedThanks for the careful review. I agree with everything you have indicated above, and I appreciate the automatic enabling of custom_breadcrumbs_identifiers on update. I expect that will save me a half dozen support requests!
I did not remove the title check in _custom_breadcrumbs_get_trail_items() at this time. While not needed for special identifiers, the check was added to prevent unintended whitespace from developing into a crumb. I think its sufficient to require a title to be present even if it is just a placeholder that will be silently ignored. [
<none>should not be used as the placeholder since it will abort the breadcrumb generation, but the identifier itself could be used...] I've tried to indicate this in the description of the identifiers.This has now been committed to 6.x-2.x-dev.