While we can specify our own suggestions eg. for links, drupal_find_theme_functions strips out all "themename_" occurences. So when I try to make my own context suggestion such as (using bartik):
theme('links__bartik_main_navigation', array('links' => $links));
it won't find my defined function in template.php
bartik_links__bartik_main_navigation($vars)
but it will be looking for:
links__main_navigation
the reason is this line in theme.inc (985):
$new_hook = str_replace($prefix . '_', '', $match);
proposing to replace this with preg_replace (might affect performance, since it's being called many times while rebuilding theme registry)
$new_hook = preg_replace("/^" . $prefix . "_/", "", $match);
which will strip the prefix_ (eg. "bartik_") only from the beginning of defined functions
patch attached
Comments
Comment #1
sign commentedaccidentaly removed one line from original theme.inc,
Comment #3
wojtha commentedRerolled @sign's patch against current HEAD.
Comment #4
wojtha commentedsorry for doubled attachement, Ajax upload in Opera 11 seems to be buggy.
Comment #5
wojtha commentedReplaced doublequotes with quotes - they are better in this case. + Fixed typo in comments.
Comment #6
wojtha commentedAs we can be sure that prefix is present (because of preg_grep - see the patch) we could use *stupid* substr() which is lightning fast in comparison to preg_replace().
For 100.000 iterations I'm getting on my machine:
0.0668s for str_replace
0.2267s for preg_replace
0.0397s for substr
Alternative - faster - fix of this issue.
Comment #7
wojtha commentedBumping to 8.x
Comment #8
wojtha commented#6: 1038788_drupal_find_theme_function_removes_prefix_substr.patch queued for re-testing.
Comment #9
dvessel commented#6: 1038788_drupal_find_theme_function_removes_prefix_substr.patch queued for re-testing.
Comment #10
dvessel commentedThis won't break anything and it was handled poorly previously. It should go in for both 7 & 8.
Comment #11
dries commentedGood catch, and nice tiny performance improvement. Committed to 7.x and 8.x.