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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sign’s picture

accidentaly removed one line from original theme.inc,

Status: Needs review » Needs work

The last submitted patch, 1038788_drupal_find_theme_function_removes_prefix.patch, failed testing.

wojtha’s picture

Rerolled @sign's patch against current HEAD.

wojtha’s picture

Status: Needs work » Needs review

sorry for doubled attachement, Ajax upload in Opera 11 seems to be buggy.

wojtha’s picture

Replaced doublequotes with quotes - they are better in this case. + Fixed typo in comments.

wojtha’s picture

As 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.

wojtha’s picture

Version: 7.x-dev » 8.x-dev

Bumping to 8.x

wojtha’s picture

dvessel’s picture

dvessel’s picture

Status: Needs review » Reviewed & tested by the community

This won't break anything and it was handled poorly previously. It should go in for both 7 & 8.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Good catch, and nice tiny performance improvement. Committed to 7.x and 8.x.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.