Closed (fixed)
Project:
Drupal core
Version:
6.x-dev
Component:
documentation
Priority:
Normal
Category:
Task
Assigned:
Issue tags:
Reporter:
Created:
22 Apr 2010 at 08:51 UTC
Updated:
3 Jan 2014 at 01:42 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
dyannenovaI'm not sure that I did this correctly, since it's my first try at api documentation, but here's a patch using user_block_info as the example.
Comment #2
cwgordon7 commentedComment #3
David_Rothstein commentedSay it ain't so - I think this was my first ever API docs contribution! Well, yeah, it is kind of weird, though, and probably should go away :)
However:
http://api.drupal.org/api/function/hook_block_configure/7
http://api.drupal.org/api/function/hook_block_save/7
http://api.drupal.org/api/function/hook_block_view/7
'cache' => DRUPAL_CACHE_PER_ROLE | DRUPAL_CACHE_PER_PAGEexample, since it's pretty unintuitive how to do that unless you are familiar with bitmasks. And actually, it's not 100% clear at first glance what that combination even means - I think the deal is supposed to be that the block content can change per role and (even for users with the same role) can also change per page, but it could probably use a good code comment there too...Comment #4
jhodgdonOne thing to consider is that we have a fully-worked-out blocks example module, so the example functions in hook_block_* don't have to do illustrate every possible case:
http://api.drupal.org/api/drupal/developer--examples--block_example--blo...
That would probably be the place to suggest we add examples for caching.
None of our other hook sample functions illustrate every possible case... I think we should just choose the search block, user login block, or some other block in core to use as an example, and put that in for all the hook_block_*, since that's what we've done with other hook example functions.
Comment #5
dale42Should have a patch for this in the next day or so.
Comment #6
dale42Following jhodgdon's guidance, I took the examples from an existing Drupal module (specifically, node module). After reviewing a number of examples I believe the optimal solution is borrowing the examples and language from the example module. However, that would be a wholesale change and somewhat outside the scope of this issue (which was changing "exciting" and "amazing").
I did identify some language still referencing hook_block(), which I replaced.
The one thing that bothers me is the "weight, status, region, visibility, pages" reference in the hook_block_info doc header. These are items you rarely define in practice and if the caching examples are out these should be should be moved to the example module, as well. I kept them, but added a note that they are rarely set from the module.
Since no one commented on "weight, status, region, visibility, pages" being grouped together in a single bullet point instead of being split out per usually parameter specification, I left them grouped. If we keep them, I think each item should be split into its own bullet.
Comment #7
jhodgdonI think the best thing to do with weight etc. is to make them each separate bullet points, and clearly label them as (optional). e.g.:
- 'weight': (optional) Initial value for the ordering weight of this block. Usually not set by the module.
These definitely do need to be documented in hook_block_info(), but I don't think they need to be illustrated in the example.
Other than that change, I think this patch is great. Oh... You might put a code comment in each example function saying something like:
// This example comes from node.module.
Comment #8
dale42Per #7 feedback:
- Added "// This example comes from node.module." as appropriate
- All parameters in the hook_block_api() doc header have their own bullet
- weight and friends are labeled optional
- weight and friends have the line: "Usually not set by the module. Initial value can be later modified by the block admin menu."
I wanted to make it clear specifying the initial value didn't "lock" the value from being changed later.
- Since we've told people how pre-enable a block I also updated the last paragraph that stated: "After completing your blocks, do not forget to enable them in the block admin menu."
Comment #9
jhodgdonThanks -- looks much better, almost there. A few small things that should be improved:
a) I think we should have @see lines on each of these 4 hooks pointing to each other.
b) In the weight and friends section, all the lines should still wrap close to 80 characters. For instance:
Note: should be moved up to the previous line.
c) In the weight and friends section, you have written for each one: "Usually not set by the module. Initial value can be later modified by the block admin menu.". This seems a bit off to me... How about instead:
"Most modules do not provide an initial value, and any value provided can be modified by a user on the block configuration screen."
Definitely "block admin menu" is innacurate.
d) Needs . at end of this:
e) I'm not sure what this refers to:
first item in the _regions array
_regions array where? Is this the regions array in the theme.info file?
f) (i.e., include, exclude or PHP) -- needs a comma before the "or" to conform to our style standards. See http://drupal.org/node/338208#english]
g) I think since you've given this information in the weight-and-friends section, this bit can be omitted:
If you do think it's necessary, again it shouldn't say "block admin menu".
Comment #10
dale42Regarding e):
That was part of the original text, so I'm not sure. You don't need to specify regions in the theme .info file if you're using the Drupal standard regions, so that's not it. I suspect it's in the theme engine somewhere. I just ran a quick test, and if the value doesn't match a region the block is disabled. There is a different behaviour if a theme changes and the old region doesn't exist in the new theme. In this case the block was assigned to first region on the region list. I've updated the text to say the block is disabled.
All other changes made as noted.
Comment #11
jhodgdonExcellent work! Let's get this in.
Comment #12
dries commentedThis looks good. jhodgdon is a Documentation Reviewing Machine. :-)
When proofreading/reviewing the proposed changes, it occurred to me that we mention
$deltawithout explaining it. We don't use$deltain the examples either, I think.hook_block_info()sounds like it would be the appropriate place to explain$delta. I'm happy to postpone$deltadocumentation to another patch, but I'd love to get your thoughts on that before committing this patch.Comment #13
jhodgdonGood catch - let's get it in here. I think delta is important enough to warrant mentioning in the first full paragraph of the docblock (or in its own paragraph right after that). How about adding something like this:
Each block your module provides must be given a value of delta in hook_block_info(), which is passed into the other block hooks as an argument to identify the block being configured or viewed. The values of delta can be strings or numbers, and they only need to be unique within your module. Typically you would use a string identifier for a simple block that your module provides, and a numeric identifier if you allow users to create several similar blocks that you identify within your module code with numeric IDs.
??
Comment #14
jhodgdonAnd by the way, I am happy to be a Doc Reviewing Machine -- that means that many other people are stepping up and writing doc patches! Hooray! :)
Comment #15
David_Rothstein commentedWe currently do define what $delta is, in three places:
http://api.drupal.org/api/function/hook_block_view/7
http://api.drupal.org/api/function/hook_block_configure/7
http://api.drupal.org/api/function/hook_block_save/7
However, I agree it is a good idea to define it in the hook_block_info() docs instead of (or in addition?) to the other places. I mostly like @jhodgdon's suggested text, but I think we also ought to continue to mention the connection to the theme system and strongly encourage people to use (meaningful!) strings rather than integers here, whenever it is possible for them to do so.
Comment #16
jhodgdonAgreed. There isn't actually much information about what "within the theme system" means.
Hmmm...
Taking a look at the code, I see delta being used in hook_block_view_MODULE_DELTA_alter(), and it looks like we should have an @see from hook_block_view to both hook_block_view_alter() and this hook.
And then I see it coming into block.tpl.php as a theming variable, and as a template suggestion (i.e. you can use block-MODULE-DELTA.tpl.php instead of block.tpl.php).
I think we should mention these specific uses instead of being vague?
Comment #17
jhodgdonI'll make a new patch...
Comment #18
David_Rothstein commentedSounds good to me. From a theming perspective I think the most important thing is that the delta is used to construct an ID. For example, the HTML for the user login block looks like this:
<div id="block-user-login" ....>where "login" is the block's delta. That was one of the main motivations for using meaningful string deltas in D7 ('block-user-1' leads to CSS that is a lot more annoying to write and read).
Comment #19
jhodgdonOK, how's this? I took a look through the rest of the block hook docs and made a few adjustments...
Comment #20
David_Rothstein commentedLooks pretty good - my main comment would be here:
First, the hook name near the bottom is wrong; I assume hook_block_view_MODULE_DELTA_alter() is the one you want here :)
Second, after reading this, given that hook_block_info() is a very common hook that new developers might look at a lot as a starting point, I wonder if this assumes too much technical knowledge? Maybe rewording it so the technical level is somewhere in between the previous level and this one would be a good compromise, e.g something like this:
****
Other less important comments:
While we are in here, it might really be nice to clarify somewhere that 'info' in hook_block_info() controls the block's title on admin screens, while 'subject' in hook_block_view() controls the block's title when it is being displayed. I always forget which is which, personally :)
Instead of "common.inc" in the last sentence, how about just "Drupal"?
Add a comma after "theme".
I had trouble understanding what this meant, even though I already know :) The first sentence doesn't seem like a complete sentence, and for the second, I think it's worth listing the values explicitly rather than referring people to block.install.
If doing the above, then we can probably just remove the "include, exclude or PHP" parenthetical remark here.
Trailing comma on the last array element?
Trailing period on the code comment?
It's a shame that the example we're using here does not follow our own advice of putting a renderable array in 'content', but I guess we can fix that in some other issue (if/when we fix the node module itself to do that!).
Comment #21
dale42Perhaps time to rename this issue? What started as a simple example change has turned into a fairly major rewrite.
I find this line confusing: "Each block your module provides must be given a value of "delta" in hook_block_info()." To me it implies I must code something $value = "delta". The next line is great. Suggest something like:
Each block your module provides is identified by a unique identifier referred to as "delta". Delta is passed into the other block hooks as an argument to identify the block being configured or viewed.
This line seems out of place: "preferably meaningful strings, since string deltas lead to self-documenting code". It seems more like a coding style guide comment belonging in a handbook than something in the API documentation. The next sentence provides a more compelling argument for string based deltas in any event.
Regarding common.inc. I found it very helpful having the reference. There is some additional information there that someone researching caching could find useful. I vote to keep it. Actually, in some ways it makes more sense to remove all of the caching information and only refer to common.inc so there isn't double comment maintenance. Most of the caching information in the doc header is taken verbatim from common.inc.
Regarding "(i.e., include, exclude, or PHP)" in the pages value description, since we appear to be going towards inclusiveness of information I think we should keep this regardless of whether or not the value parameters are included in visibility. If someone is doing a lookup and goes straight to that point the explanation is clearer.
The extended information on selecting a good value for delta in #20 is great information but it seems more of an implementation detail than documentation of the interface. It seems better suited for a handbook page or a new Block section under "A few components of Drupal" on http://api.drupal.org/api/7. Actually, a Block section might be a good place to expand on how block caching works.
I did a search and didn't see an issue for the non standards-compliant code in node module (My search-foo is not strong, though). Does/should an issue be created?
Comment #22
jhodgdonAll/most good points. I will make a new patch later today.
Comment #23
jhodgdonHere's a new patch (and new issue title). Regarding common.inc - on api.drupal.org those constants will appear as links, so I think it is correct to leave out the name of the file they appear in (besides which, they could always move).
Regarding the early rendering of node blocks, we should probably file an issue on the node module.
Comment #24
dale42Great job on reworking hook_block_info() and nice catch on the renderable array stuff!
I'm not entirely comfortable with leaving out the common.inc reference. The link created by doxygen doesn't give an information scent that there's an entire paragraph of additional information (on a topic that can be hard to get information on). However, in this case I think the important information has been captured in the patch and the remaining information is of arguable importance so I can go along with the decision.
Looks good to go.
Comment #25
dries commentedThis looks good now. Found one thing which didn't feel quite right:
Comment #26
jhodgdonWhat's not feeling right about that? Happy to try to improve it, but I don't understand what's wrong... :)
Comment #27
dries commented"You assign each block your module provides" doesn't sound like proper English but maybe it is.
Comment #28
jhodgdonI think it's "proper", but if it's not clear enough for the average highly-literate but non-native speaker to understand, let's fix it up so it's better.
I think I did it that way in an attempt not to use the passive voice, but I guess probably it would be clearer with passive voice. So let's try this...
Comment #29
David_Rothstein commentedThis looks great to me.
Comment #30
David_Rothstein commented@torelad:
I see the paragraph in common.inc that you're referring to, and I think it's a bug that it doesn't show up e.g. on api.drupal.org. I think those constants and that paragraph need to be grouped together inside a @defgroup, and then they will display linked together correctly as part of the API docs - that seems to be the right way to do it. Maybe we can create a separate issue for that?
Comment #31
dries commentedRead really well now. Great. Committed to CVS HEAD. Thanks a lot.
Comment #32
jhodgdonRE #30 - there is already an issue on this:
#863428: DRUPAL_CACHE_* documentation unclear and incomplete in common.inc
The issue title may not indicate it, but it does address this issue.
Regarding this issue, I thinkwe should consider adding some of this to D6. It wouldn't be a straight port, because the hooks aren't the same, but the text about delta for instance, and a better example, would not be bad... Note that for D6 this is in the contrib repository. I will make the changes, possibly later today.
Comment #33
dale42@David_Rothstein/@jhodgdon: Re common.inc, excellent. Thanks.
Comment #34
jhodgdonOK, I've updated the D6 hook_block doc. Here's the result. I didn't update the example for D6, as it wasn't quite as silly as the D7 example. This should be up on api.drupal.org at some point in the near future...
Comment #35
jhodgdon