Problem/Motivation
Originally, there were some problems with the Default Theme Implementations topic on api.drupal.org; most have been fixed, but there's still a bit to be done (see Remaining Tasks and the comments below for more information).
Proposed resolution
Fix up a lot of documentation of theme functions and the Default Theme Implementations topic.
Remaining tasks
The main remaining task is that every *.tpl.php file that is in a module directory (NOT the ones in themes!!) needs to have
* @ingroup themeable
added to its documentation block. See
http://drupal.org/node/1354#templates
for standards.
And as a follow-up, once this is done we should get rid of the theme.php files from Drupal 8 and Drupal 7 branches of the Documentation repository.
User interface changes
None.
API changes
None.
Original report by jhodgdon
The group @themeable in the API needs some work...
http://api.drupal.org/api/group/themeable/7
Issues:
a) there are some things in the themeable group that shouldn't be there (preprocess funcs and maybe others)
b) The @defgroup header could use a better title and perhaps other rewrites. Proposed title: Something conveying the meaning "Things you can override in your theme".
c) There are things not in the group that should be, such as *.tpl.php files.
JohnAlbin is working on a patch.
| Comment | File | Size | Author |
|---|---|---|---|
| #51 | drupal-theme_func-716496-51.patch | 6.65 KB | killtheliterate |
| #51 | interdiff.txt | 6.02 KB | killtheliterate |
| #50 | drupal-theme_func-716496_50.patch | 6.63 KB | killtheliterate |
| #48 | drupal-theme_func-716496-46.patch | 6.64 KB | rootwork |
| #42 | drupal-theme_func-707484-5772470.patch | 8.57 KB | rootwork |
Comments
Comment #1
johnalbinMe!
Comment #2
jhodgdonThe doc for that topic should explain:
a) How preprocess works and how to override it
b) How to override a theme function or a .tpl.php file
Comment #3
johnalbinWaiting for #610408: Create theme.api.php to help consolidate theme-related docs. to be committed before rolling a patch.
I've been working on a bunch of changes. Maybe 30% done at this point.
One point to discuss is the one line descriptions of the theme functions and template files are worded in several different ways. We should use a consistent phrasing like we use "Implements hook_*" for hook functions.
Here's what we currently have in our theme hook one-liners:
I'm partial to "Format a" since we're not immediately displaying or presenting anything. We're marking it up and returning it for later presentation.
Comment #4
jhodgdonAll function one-line descriptions should start with a verb in 3rd person, like "Formats", "Themes", or "Returns", so regardless of which of the 13 options existing in the code base we choose, it should be slightly modified so that the verb has an S on it. They should not say "This function...", "Default theme implementation of...", or "Theme callback for...".
Given our other standards, I am in favor of one of these:
- Renders a foo.
- Formats a foo.
- Returns an HTML-formatted foo.
JohnAlbin marked both of these as jargon. However, the word "render" in a web programming context is a concise word meaning to convert something to HTML, which is what theme functions do.
Arguments against some of the other choices, beyond JohnAlbin's notes above:
#2 - "theme" is innacurate, since theme('blah', $vars) is what themes it (i.e. lets the theme override the default rendering). These functions define the default rendering of the object -- they don't theme it.
#12 - "display" is innacurate, since the theming functions don't send the information to the browser, they just convert it to HTML.
I'll post something on the coding standards group to see if we can get comments from the community on this...
Comment #5
jhodgdonWhatever we decide, we should make up a template that also says what is in the variables, and add it to the doxygen pages. Something like:
Comment #6
jhodgdonOMG. Check this out too: http://api.drupal.org/api/drupal/developer--theme.php/7
Comment #7
jhodgdonOK. JohnAlbin and I discussed this a bit on IRC.
There are one or two theme functions that do not return HTML output, although that is certainly what theme() and theming is meant for. A couple of examples:
http://api.drupal.org/api/function/theme_syslog_format/7 -- this returns formatted output for the syslog file
http://api.drupal.org/api/function/theme_aggregator_page_rss/7 -- this function actually generates *and prints* its output, complete with HTTP header... DEFINITELY not a standard theme function.
So... My call on this would be:
a) Change the doc for the return value of http://api.drupal.org/api/function/theme/7 . It is rather lame as it is, anyway. Instead, it should probably say "An string containing the formatted output (usually HTML)." I think the edge case for those two aggregator functions is not important to mention. And by the way, the main rss.xml file generated in node.module does not use a theme function. And shouldn't.
b) Make the standard for theme functions be:
With a note that in the few exceptional cases, the "HTML" can be replaced with a description of what kind of format is being generated/returned.
c) In those aggregator "theme" functions, make it VERY clear in the doc that these are not standard theme functions in that they actually generate pages/headers instead of returning strings.
Comment #8
johnalbinI completely agree with #7. :-)
Comment #9
sunSome thoughts:
1) Specifying @return is superfluous for most theme functions. It should only be stated if the return value is not HTML like everywhere else. Theme functions returning XML instead of HTML or perhaps even plain-text only, may be able to describe this in the function summary already, so explicitly stating @return really only makes sense for edge-cases.
2) If the return value is HTML, the function summary does not need to specify that it's returning HTML. Again, it's the expected default for all theme functions.
3) The description for @param $variables should be unified and kept as short as possible, since it means that we repeat something on purpose - and normally, we would just skip it instead of duplicating (compare $form, $form_state params for form constructors). But since we need to specify its contents, we can't skip it.
So effectively:
4) On preprocess and process functions: Those should be listed with theme functions starting with D7. The reason is that we actually have a couple of preprocess and process functions that perform essential data preparations for - sometimes common/generic - theme functions. Partially due to performance reasons, partially due to other reasons. I.e. the only way to achieve a different formatting is to add another preprocessor or processor. Therefore, knowing about preprocess and process functions is an important part of the game.
Comment #10
jhodgdonI don't think the word "Formats" gets across immediately that the output is HTML. I realize that experienced developers know that theme_xyz() returns HTML, but that may not be obvious to all users of api.drupal.org or readers of function doc.
I am also against omitting @return on functions that have @param. Omitting @return can also mean that there is no return value, in general, and these functions most definitely do have a return value.
Comment #11
sunBoth "HTML" and "@return" would be needlessly repeated information all over again. We avoid that in general. Information about defaults can happily live in theme().
On "Formats" - it's a uncommon term, yes, but from all known options it is the most precise.
...
Though, a total alternative - apparently even mentioned above already - would be to use the "abbreviated" summary style...
Comment #12
jhodgdonI agree about not repeating needless information, but in this case there is no link to theme() that is automatically generated.
Also, I'm not against the term format. I just want to point out that it doesn't imply HTML necessarily.
Just keep in mind that each of these functions stands alone on its own page. It needs to either (a) document its parameters and return value unambigously, or (b) link to a page that documents its parameters and return value.
So... somewhat parallel to what we do for hook implementations, how about making the link to theme() explicit in the one-liner:
I personally don't like the term "theme hook", but it's used all over the place in d.o theming handbook doc, so I think we're stuck with it...
I'm definitely open to other wording here, but I think putting theme() in the one-line description would take care of (a) making it concise (b) not repeating information (c) linking to theme() (d) documenting param/return. All in one small package.
Let's see, here are some other wording possibilities I can think of right at the moment:
1) theme() hook for a foo.
2) Formats a foo for theme().
3) Implements theme() for a foo.
Thoughts?
Comment #13
sun"@ingroup themeable" is the link to any missing, not duplicated default information about theme functions already...?
Comment #14
jhodgdonI dont' agree. The themeable group page has descriptive information, not function doc. It doesn't have @param, @return, etc.
Comment #15
sunwell, http://api.drupal.org/api/group/themeable/7 needs a major overhaul anyway. ;) Why not clarify in the very first line(s)?
There's much more to know about default behaviors of theme hooks/functions. You can look up theme_foo() just to find out that theme_foo() is not even invoked on your site, because there is an override or the theme registry has been altered. Not documented for theme_foo(), but instead, once for all theme functions (hopefully) for the group.
That said, we should consider to move some of the existing docs from theme() to the group. Groups are our new topics/chapters, explaining the high-level API, without going into function-level detail. AFAIK, the best example we have is http://api.drupal.org/api/group/ajax/7
Comment #16
jhodgdonA group page is not function doc. A function doc page like theme() is function doc.
IMO, all functions need to have function doc: @param, @return. Either directly or one link away.
This should either be on each individual function or on theme(). And they all should link to theme() anyway, IMO.
I do agree that the themeable group needs updates -- that is, after all, the title of this issue. But it is not function doc, and shouldn't be used as a substitute function doc.
Comment #17
sunIs theme() the proper relation at all?
theme() is for module developers to invoke and trigger formatting. Theme functions just happen to be called by theme(), but if I look up theme(), then I clearly need information about invoking theme() itself -- not information about basics of the theme system and common knowledge about theme functions. Such high-level information belongs into the group.
In other words: Different purpose, different audience?
Comment #18
jhodgdonI see your point, sort of...
What do you suggest then? For hook implementations, we have these dummy hook function pages in *.api.php that list the function arguments and returns. Should we make a similar dummy function called maybe theme_hook() that documents the standard args/return for theme hooks?
Comment #19
sunActually, from all suggestions I tend to like #11 more and more (which actually was your suggestion, but just happened to slip in one of your examples ;).
The abbreviated form technically kills all 3 known issues in one shot: 1) No "Formats" or other weird term, 2) States that it returns something, and 3) even states what it returns (HTML/XML/etc.)
Of course, I'd still consider this for "standard theme functions" only... the "Returns foo as neutro-calmic hoover element" edge-case should have a @return directive + most probably also requires a more elaborative explanation as function description... ;)
Comment #20
jhodgdonI can get behind #11, and I completely agree that any non-HTML functions need to be more explicit.
Comment #21
johnalbinOk. I've done a light re-write of @themeable, getting rid of a lot of text. This text is supposed to be about themeable functions/templates, not about how the theme system works.
This (137 KB! Holy crap!) patch also:
It only touches docblocks and a few code comments. No code changes at all.
Comment #22
johnalbinI forgot to mention, there are 2 exceptions to the theme function docblocks, because the theme functions are mis-written, IMO:
theme_menu_local_tasks(): #599706: Allow to alter local tasks/actions
theme_table_select_header_cell(): #768490: theme_table_select_header_cell() is not really a theme function
Oh, looks like I need to re-roll since #767872: theme_node_log_message() has never, ever been used was just committed! So here's the re-rolled patch.
Comment #23
aspilicious commentedReturns HTML .... (I guess)
Same..
For the other examples above:
- Your patch needs a lot more wrapping
- Use always 3th person verbs
109 critical left. Go review some!
Comment #24
johnalbinThanks for the review, Bram! But I'm not sure what you want me to correct.
Meaning what?
Meaning I use verb like "returns"? That's the standard, isn't it? Hooks use "Implements" and we're trying to get theme functions to use "Returns". Or did you mean something else?
As for why the template files use "HTML for a…" instead of "Returns HTML for a…", I explained my reasoning in #21 above. But its up for discussion.
Comment #25
johnalbinI said all theme functions not returning HTML have @return statements, but I forgot theme_syslog_format(). This patch corrects that.
Comment #26
jhodgdonStyle problems with this patch:
a) All function doc should start with a 2nd-person verb. Such as:
Register -> Registers, specify -> specifies.
Another one:
Also on this one, theme_menu_tree -> theme_menu_tree(). The parens turn this into a link. Once you do that, you can remove the @see below.
Here's another one:
There are quite a few other functions that also need fixing up in this way...
b)
In most existing functions where things are marked required/optional, we put the (optional) at the beginning rather than the end. Something like
c)
There should be a blank line between @param section and @return.
That's about where I stopped reviewing for style...
Comment #27
jhodgdonI am also not sure I like some of the wording....
a)
In the Handbook, these are referred to over and over as "Theme hooks" not "Theming hooks". Let's stay consistent. This wording is also used later in the group text (sometimes spelled as "themeing hooks").
b)
Should we also mention that they can be in a theme subdirectory (is that accurate?)?
c)
Shouldn't this say "or a table.tpl.php file"?
d)
Why take out the doc of what @} is ending?
e)
This is the first line for the theme() function. It's awkward to me with "the" in there... Maybe it should just be:
Generates themed output.
Comment #28
jhodgdonBeyond all of that... Is this the standard we agreed upon for documenting theme functions and templates, and actually did we agree at all?
Our standards page is not agreeing with what is in this patch:
http://drupal.org/node/1354#themeable
Comment #29
sun@jhodgdon: You sounded like you'd agree? I think we've reached a very sensible and solid consensus here.
We therefore should update that documentation chapter. Also, would it make sense to split all the theme hook docblock changes from the main themeable group documentation? The former can probably go in quickly, while the latter usually needs a couple of reviews and re-rolls. We could do both in this very issue, no need for a separate one.
Comment #30
jhodgdonOK... #11 is the consensus, you're correct. I will update the doc page. Sorry, I was confused (Monday morning). :)
Comment #31
jhodgdonSo, scratch #28 - invalid, and I have updated the doxygen section.
#26 and #27 still need to be addressed.
Comment #32
johnalbinOk. I've implemented all the suggestions in #26 and #27 in my working copy, but I've also decided to split this patch up into chunks like Sun suggests.
First patch: Fix all the theme function docs.
Second patch: Fix all the template docs.
Third patch: Fix other theme docs.
The first two patches should go quickly. Here's the first patch. It:
That's still a lot to review (86KB down from 137KB), but the patch is more focused and should be easier to review.
Comment #33
jhodgdonWow. Let's get this in. Great work, JohnAlbin!
Comment #34
dries commentedCommitted to CVS HEAD. Thanks.
Comment #35
jhodgdonWe need to leave this open for the two other patches mentioned in #32.
Comment #36
jhodgdonI'm reviving this issue.
I would like to get rid of the theme.php files in the Documetation git repository, which have a bunch of lovely stuff like:
In order to do that and not lose what those theme.php files were trying to do, we need to get:
into all *.tpl.php files in modules -- but not overrides of these files that are part of themes.
This would be a good Novice issue, and I think it should be backported to Drupal 7.
I'll update the issue summary with a pointer to this comment.
Comment #37
jhodgdonIssue summary is updated...
Also I'm provisionally un-assigning this since John hasn't done anything on it for a while. John: Feel free to claim it again, but keep in mind it's a great issue for a novice contributor. :)
Comment #37.0
jhodgdonAdd an issue summary
Comment #38
rootworkSoooo...based on jhodgdon's comment in #37 I'm assigning this to myself for the code sprint day -- I hope I'm not stepping on anyone's toes :)
Comment #39
rootworkHere is a patch that updates all the .tpl.php files that weren't already updated.
Comment #40
rootworkSetting this back to unassigned since the test passed. Still needs review, of course.
Comment #41
jhodgdonThanks! Looks good.
Let's see. I can list what is currently in the themeable group here (without this patch):
http://api.drupal.org/api/drupal/core!modules!system!theme.api.php/group...
Hm. Only 10 files...
A quick ls | grep finds 35 .tpl.php files that probably should be listed in core/modules, and I think these ones are missing from the patch:
modules/system/page.tpl.php
modules/system/region.tpl.php
There are also 3 test-related tpl.php files that I are omitted and I think should be, so that is it. Let's get those two in. Thanks!
Comment #42
rootworkRerolled patch with the two files I missed.
Comment #43
jhodgdonThanks, looks good! I'll get this committed sometime soon. It affects a bunch of files so I will need to check the review queue and not clobber any critical patches.
Comment #44
rootworkAwesome! Glad I could help, even if it was with this silly little patch :)
Comment #45
rootworkOops. Fixing status back.
Comment #46
jhodgdonThe patch no longer applies :(
Comment #47
jhodgdonThis patch needs a reroll.
Comment #48
rootworkI think I did this correctly...at the very least this little issue is giving me lots of practice with git and core patches!
Comment #49
disasm commentedI'm not a 100% sure, but looking at other modules such as core/modules/user/user.module, I think this should be themeable not themable. This will need fixed for all of the lines.
Comment #50
killtheliterate commentedRe-rolled. Applies cleanly at ea1b955.
Comment #51
killtheliterate commentedAddresses #49.
Comment #52
jhodgdonLooks good! I'll get this committed shortly. Thanks all!
Comment #53
jhodgdonThanks again -- committed to 7.x and 8.x. I'll go take care of this follow-up now too:
#1490474: Remove theme.php files [when template files have right @ingroup]
We do need to backport this to 6.x though. Probably it will involve starting over and adding the @ingroup themeable to all of the modules/*/*.tpl.php files manually rather than trying to use this patch.
Comment #53.0
jhodgdonadd task to list
Comment #54
jhodgdonI am cleaning up old 6.x documentation issues. At this point, we are not spending effort fixing them. Sorry.
This one was 8/7 first so setting back to that.