sammarks / ablecore

A library for Drupal developers.
MIT License
5 stars 4 forks source link

Split up theme functions. #50

Closed sammarks closed 9 years ago

sammarks commented 9 years ago

Here's a situation. Let's say you have to override a module's theme function inside your template.php file and change maybe one line of code. In order to do this, you have to basically copy and paste the entire contents of the theme function into your implementation inside template.php. This is bad for several reasons:

Here's the proposed solution. Break up theme functions into two stages:

1. Generate the render array that represents the final output. 2. Pass that render array to drupal_render in the theme function.

Better yet, why don't we just modify theme functions to be able to return a render array instead of having to return HTML. That way, if you want to modify another module's theme hook, all you have to do is call the original theme hook, make your modifications to its render array and then return the final result.

Yes, I like that.

sammarks commented 9 years ago

Obviously, the best way to do this would be to create a fork of Drupal and modify all the theme functions to return render arrays instead of building some kind of Able Core add-on (like the helper functions).

We could just use hook_theme_registry_alter and look for modules that implement hook_ablecore, and update those functions so that they allow for render arrays to be returned.

Or we could modify hook_theme_registry_alter and modify all the themes so that they're passed through a general ablecore theme, which either returns the content or calls drupal_render on the content if it's an array.

sammarks commented 9 years ago

For module compatibility, we should restrict the extra functionality to just modules that use hook_ablecore. Modules that don't know about ablecore and don't know about the functionality obviously aren't going to use it.