So, at the moment, when these modules inject their links (using hook_nodeapi), they add an element to the $node object that has a #value of "<span class='print-link'></span>". To populate this HTML div, they then do a preg_replace on the #value, replacing the closing '</span>' with '[the new link]</span>'.
This is, to put it bluntly, wrong.
The markup should be placed in #prefix (opener) and #suffix (closer) attributes. With this in place, adding subsequent links becomes a matter of simple concatenation rather than the more intensive preg_replace function. (By happy chance, it also removes the need for an 'if' statement, as it doesn't matter if you concatenate an empty string onto it.) It's also much easier for other developers to step in and theme the block, and further, the #prefix/#suffix doesn't render when the #value is empty. Which is nice.
To be frank I'm not 100% sure this shouldn't be done elsewhere - say, by populating the links during the 'load' step, and passing the pre-built links to a theme function in the 'view' step - but that's beyond my immediate concern at the moment.
Find attached some .diffs (generated by my text editor, I have no knowledge of patch file construction) to apply these changes to print.module, print_mail.module and print_pdf.module, which appear to be the only places the 'print_links' element is referenced - haven't had time to chase any other references down.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | remove-empty-span-d7-version.patch | 1.02 KB | dropfen |
| #6 | remove-empty-span-d7-version.patch | 1.21 KB | dropfen |
| #5 | empty-span-d7.patch | 823 bytes | dropfen |
| print_pdf.module.diff.txt | 914 bytes | kingandy | |
| print_mail.module.diff.txt | 927 bytes | kingandy |
Comments
Comment #1
jcnventuraThanks a lot for the patch.
I guess everyday one learns something new.. I didn't know that this #suffix / #prefix stuff existed!
I've committed it to CVS.
Comment #2
kingandyI just noticed my HTML got filtered out of the original post. Suffice to say there should be a bunch of SPANs in there :)
Comment #3
jcnventuraThe patches got through, and that's the one I've read more carefully :)
Comment #5
dropfen commentedempty spans are still present in 7.x-1.x version.
here somes the patch.
Comment #6
dropfen commentedOops, sorry ;)
This is the right one.
Comment #7
dropfen commentedfix coding guidlines.
Comment #8
jcnventuraNo, the code is as good as it gets.. This span is reused by the PDF and email modules. If you apply this patch, the other sub-modules will not have the prefix and suffix added. In 7.x-2.x, there's a single point that handles this span insertion, and that can decide if it's needed or not.
Setting back the original values.
Comment #8.0
jcnventuraMaking example code visible.