Closed (fixed)
Project:
Examples for Developers
Component:
Render Example
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
28 Jul 2010 at 14:14 UTC
Updated:
10 Oct 2010 at 23:20 UTC
Jump to comment: Most recent file
Here's a first shot at a render example, demonstrating D7 render arrays and altering.
Reviews, suggestions appreciated.
| Comment | File | Size | Author |
|---|---|---|---|
| #25 | examples.render_example_867256_25.patch | 26.49 KB | rfay |
| #14 | examples.render_example_867256_13.patch | 20.22 KB | rfay |
| #9 | examples.render_example_867256_08.patch | 12.91 KB | rfay |
| #4 | examples.render_example_rfay_867256_03.patch | 7.14 KB | rfay |
| examples.render_example_rfay.patch | 7.73 KB | rfay |
Comments
Comment #1
moshe weitzman commentedLooks good. My one hesitation is render_example_form_alter(). I think there is already confusion between render arrays and form arrays and its best to leave forms out of the learning discussion. Not a big deal tho. Thanks for the example.
Comment #2
rfayComment #3
rfayRemoved the form_alter portion. The intent *is* to explain about render arrays.
@moshe: Are there links that should be added to this? A good blog post somewhere? I didn't see any links on http://sf2010.drupal.org/conference/sessions/page-render-drill-down-drup...
Comment #4
rfayOops. Seem not to have attached the patch.
Comment #5
rfayHmm...
I notice one big thing I didn't know about altering Render Arrays before:
There is no container to which I can properly append the item I'm rendering in.
If altering a block, the block->content contains *just* the stuff that was in the block (there is no container in there). So it might contain *just* a list of menu items, or *just* form elements.
Bottom line: This example ends up adding a form as an element in a
on a menu, or a form as an element in a form on a form block. None of those are what's intended. Also, I'm adding the page fieldset to the the footer, which is a little awkward, but not as bad as the above.
@moshe: Any suggestions about how to do this better?
Comment #6
rfayI think I'm going to have to put this down for now. Here's what I found:
1. No matter what I add to a block, it gets processed the way the block wanted to be processed. So If I add something into a menu block, it comes out inside the
. If I add to a block which is a form, it comes out inside the form. Obviously both bad for the HTML.- region
- block1
- pseudoblock
- original block2
- my_addition
2. @Moshe suggested pushing the existing block down a level and then making it a peer of what I was adding:
In that case I get errors because the default Bartik theme assumes that everything below the region level is an official block that has a #block in it (template.php). This could just be an oversight/assumption in Bartik that should be fixed.
So the right way forward on this might be to fix the Bartik issue.
Comment #7
rfayThe approach in #6 failed probably just because of the assumptions Bartik was making. The Bartik code in its theme_page_alter() should probably be moved to block module, or at least it could be more suave and careful. #6 should be re-tried with another theme, and an issue should be filed with Bartik.
But there are other ways of approaching this, as pointed out by @moshe in IRC:
1. Append to the rendered element using #after_build
2. Add another theme_wrappers before the block's own wrapper
Comment #8
rfayHere's a new version. Not done yet, and tests not done yet, but this demonstrates things like #pre_render, #post_render, #theme_wrappers, etc.
Works fine with themes other than bartik, but emits errors with bartik due to #889100: remove bartik_page_alter() and extra block classes.
Also, filed
Comment #9
rfayAppears that I forgot the patch.
Comment #11
rfay#9: examples.render_example_867256_08.patch queued for re-testing.
Comment #12
rfay#889100: remove bartik_page_alter() and extra block classes landed, so this is fine now.
Comment #13
chx commented+ foreach($xpath_array as $xpath) { <= space after foreach
kpr needs a comment explaining it's from devel and what it does.
Comment #14
rfayHere's the current version. Includes chx comment from #13, plus lots and lots more. The only think I consider missing is an example with #access and tests for all the new stuff that I added (the actual arrays that are rendered on the new page that's added)
Comment #15
ilo commentedI'm reviewing it.. just two notes:
.info file does not declare 'package = Example modules'
and, any particular reason why devel is a dependency of the reder example? (still did no look deep enough to discover myself)
Edited: I mean, in render example, kpr() can be replaced with a copy of dprint_r() function and remove the dependancy.
Comment #16
rfayI'm using kpr() in the code, provided by devel. It's just the way I'm using to present a complex array in a navigable fashion. Open to better ways.
Comment #17
chx commentedI think the Krumo dependency from devel is fine. I have no problems with that. As you need to reroll with the info anyways, maybe add "we could use debug() but that's not really nice for such complex arrays". Mentioning debug() is always good :)
Comment #18
ilo commentedNo problem including devel, probably it is already installed in the system.
One concern about the patch..
this is an abstract from render_example.test
But "examples/render_example" has no form at all, it is just an static page, and the form that has to be tested is at: "examples/render_example/altering"..
In fact, locally I'm unable to pass the tests, so.. how does the bot test this module and return no errors?
Edited: These are the results when I run tests locally:
12 passes, 10 fails, 0 exceptions, and 4 debug messages
Comment #19
rfay@ilo, there are two separate pages. You probably haven't rebuilt your menu router.
Comment #20
ilo commented@rfay, sure? I'm looking the code:
the path 'examples/render_example' uses the 'render_example_info' callback:
I see no form in this function, it is just a text.. but the testcase is submitting a form in that url:
Is me who have not rebuild the menu? can you verify that locally tests pass?
Comment #21
rfaySorry, I was misreading your statement.
I have been working on the code, not the tests. I haven't returned to the tests since I expanded to 3 pages.
And unfortunately PIFR does *not run* new tests associated with a patch. Pretty weird. Makes you feel pretty vulnerable. If you look at http://qa.drupal.org/pifr/test/90164, you'll see no running of render example tests.#879662: Use test.directory.review instead of module list
Comment #22
ilo commentedOk! I was affraid my Drupal setup was doing something nasty. Sorry, my fault then, I should had look for something in the pift queue. Definitely I need to do a quick update on too many things!
Will you work on it or do I try to fix the testscase?
Comment #23
rfayI won't be able to work on this until at least Friday, so I'd love you to have a go at it!
Note that there are no tests at all for the new stuff (the example renders).
Comment #24
ilo commentedYeah, the problem is, I have no idea about the rendering stuff yet, so I'd have to sit down and learn about it :)
Comment #25
rfayOK, here's the version I'll commit if it's green (which it will be because the tests don't get run :-)
Comment #26
rfayCommitted to HEAD: http://drupal.org/cvs?commit=427658
All reviews and discussion are welcome. I'm writing an article about this and I'll get a d.o handbook page for rendering going as well.
Comment #27
rfayI forgot that introducing devel as a dependency would break this. So it failed the Bot. I'm going to have to find out from somebody if it's even possible to test with a contrib module as a dependency of another contrib module.
Comment #28
rfayFixed it with a 'dependencies' => array('devel') in the getInfo() method. Thanks to berdir!
Head is now fixed.