Closed (works as designed)
Project:
Crumbs, the Breadcrumbs suite
Version:
6.x-1.x-dev
Component:
Code
Priority:
Minor
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
21 Sep 2010 at 14:48 UTC
Updated:
26 Oct 2012 at 12:50 UTC
Comments
Comment #1
kenorb commentedComment #2
donquixote commentedAh, you mean like "find__node__" for router path "node/%" ?
You can always implement find(), and then dpm($item->route). If this says "node/%", you can then implement "find__node__".
But yes, could be useful to have this kind of debug message as a feature.
Comment #3
kenorb commentedCurrently I've this:
But I don't know if it's the right place to print it.
Comment #4
kenorb commentedAlready implemented here:
http://drupal.org/project/crumbs_plus
Comment #5
donquixote commentedI hope you noticed the 2.x branch?
A quick question for the API redesign:
For a router path of "node/%", would it help if the method was $plugin->findParent__node_x(), instead of $plugin->findParent__node__() ?
The only "risk" would be if some router path does actually use the letter x as an url fragment. I don't believe this is realistic.
For that rare case we could introduce an escape sequence, such as: "/%/" becomes "_x_", but "/x" becomes "__x_", but maybe it is better to just not start with that paranoia.
Comment #6
kenorb commentedNo, I didn't. That's great.
I think double underscore or triple are good, similar to Views API.
Comment #7
donquixote commentedViews API ? Where do they use double underscore?
We need to think about the following characters that are not allowed in method names, but common in router paths:
'-', '_', '%', '/', and in rare cases '.'.
Comment #8
donquixote commentedOf course we could invent a really safe notatation, with '_' as the escape character.
So, '-' would become '_d' (d = dash), '_' would become '_u' or '__', '%' would become '_x', '/' would become '_s', and '.' would become '_t' (dot).
The result would be a pain to read,
'node/%/edit' would become 'node_s_x_sedit'. Ouch.
To improve this a little bit, we need to have shortcut for '/%/' and for '/':
'/%/' becomes '_x_'
'/%' becomes '_x', if at the end of the path.
'/' becomes '_slash_' (no, I really don't like this one)
'_' becomes '__'.
'-' becomes '_dash_'
'.' becomes '_dot_'.
Comment #9
donquixote commentedAnother attempt. Replacements ordered by priority.
'/%/' becomes '_x_'
'/%' becomes '_x', if at the end of the path.
'/x/' becomes '__x_'.
'/x' becomes '__x_', if at the end of the path.
'/' becomes '_', if not followed by '%'.
'_' becomes '__u_' (ugly)
'-' becomes '__dash_' (ugly)
'.' becomes '__dot_' (ugly)
Thus,
'_x_' becomes '__u_x__u_'
'_x' becomes '__u_x', if at the end of the path.
'__' becomes '__u___u_'
If this pattern is now completely reversible, I dunno. But it is horribly ugly for '-', '_' and '.'.
I wish method names were not that restricted ..
Yes I know you can always do if/else magic, but then you don't need these special method names anyway.
The point is not that we want to have method names with '__x_', but simply to avoid false positives for exotic paths. For instance, findParent__node_x() should only match 'node/%', and not 'node/-' or 'node/.' or 'node-_' etc.
Comment #10
donquixote commentedI decided to change this mechanic.
Here is the new implementation (on my local version), in crumbs.plugin_engine.inc.
If this thing returns FALSE for a given router path, then this router path can not be represented by a method name.
In such cases you need to use the basic method (in 2.x this is findParent() and findTitle()), without a suffix.
You can use
switch ($item['path'])orif ($item['path'] === '...')to filter for specific router paths.For instance, router paths that contain a dash "-" or an underscore, an upper case character, etc, do no longer their own method names.
I think this restriction is much better than having to worry about possible ambiguities, or having awkward-looking method names with things like "__dash_" in them. After all, that method suffix trick is just a shortcut, not a technical necessity.
Comment #11
donquixote commentedThe new syntax is now
findParent__node_x_edit
findParent__node_x
etc.
Where '/%/' is replaced by '_x_'.
Dashes and underscores are simply not allowed in router paths. Or, if you have such a router path, you simply can't use it for a method suffix. You need to deal with that path in the suffix-less method.
Comment #12
donquixote commented"needs review" = "probably fixed in 2.x"
I think the new scheme is quite obvious. In case of doubt, run dpm(menu_get_item()) to have a look at the router path.
Btw, there is a new debug tool in the 2.x branch, where you can check how the parent path is determined for a given path.
Comment #13
kenorb commentedViews examples with double-underscore:
hook_preprocess_views_view__VIEWNAME
http://drupal.org/node/241570#comment-2508512
http://drupal.org/node/165706
See: Dynamic theming
Comment #14
donquixote commentedAh yes.
We also use double underscore, to separate the method base name from the method suffix.
So, what does it mean for crumbs?
I think the new pattern is quite ok, isn't it?
Comment #15
donquixote commentedA lot of this discussion is outdated now, and will only confuse people.
It is no longer findParent__node__(), but findParent__node_x(). Etc.
If there is still a need for documentation on the method suffix, let's discuss this in a new issue focused on the Drupal 7 version.
See #1814556: Method suffix for paths with dashes