Theming Gotcha

If you want to change the markup output In Drupal you can replace core theming functions and templates with your own implementations.

Let's say there is a theming function called theme_image which generates an image tag based on a given PHP array. If you want to modify this markup, usually you implement a function called {mytheme}_image, which is then taken instead of theme_image.

Now there is another feature in Drupal core: You can map theme keys to theme functions. It works a bit like aliases: you can map the theme key 'picture' to 'image', which means that when you call the 'picture' theme (i.e. theme('picture', $vars) ), this call is mapped to theme_image. This way you can have multiple theme keys mapped to the same theme functions, which appears nice.

The problem is that the theme key and not the theme function defines the naming convention for your custom overrides. In order to create your own version of theme_image, you have to create a function called {mytheme}_picture - as "picture" is the key, and not image.

Gotcha! And here is the corresponding core issue: