Code with bug:
if ($id = entity_id($entity_type, $entity)) {
$variables['theme_hook_suggestions'][] = $entity_type . '__' . $id;
}If $id contains "-" it's not converted to "_" and template ignored.
Description from theme_get_suggestions function docs:
// Remove slashes or null per SA-CORE-2009-003 and change - (hyphen) to _
// (underscore).
//
// When we discover templates in @see drupal_find_theme_templates,
// hyphens (-) are converted to underscores (_) before the theme hook
// is registered. We do this because the hyphens used for delimiters
// in hook suggestions cannot be used in the function names of the
// associated preprocess functions. Any page templates designed to be used
// on paths that contain a hyphen are also registered with these hyphens
// converted to underscores so here we must convert any hyphens in path
// arguments to underscores here before fetching theme hook suggestions
// to ensure the templates are appropriately recognized.
$arg = str_replace(array("/", "\\", "\0", '-'), array('', '', '', '_'), $arg);
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | entity-2265621-1-use-underscores-not-hyphens-for-theme_hook_suggestions.patch | 1.14 KB | alan d. |
Comments
Comment #1
alan d. commentedThis one can confuse even experienced developers when theming up Beans ;)
Edit: I am not 100% sure if bundles are allowed with hyphens, but I've never seen specific rules. Does the Entity API call $func = "hook_{$bundle}_something"; anywhere?
Comment #2
chris matthews commentedThe 2 year old patch in #1 to entity.theme.inc applied cleanly to the latest entity 7.x-1.x-dev and (if still relevant) needs review.