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.

Comments

jcnventura’s picture

Status: Active » Fixed

Thanks 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.

kingandy’s picture

I just noticed my HTML got filtered out of the original post. Suffice to say there should be a bunch of SPANs in there :)

jcnventura’s picture

The patches got through, and that's the one I've read more carefully :)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

dropfen’s picture

Version: 6.x-1.10 » 7.x-1.0
Status: Closed (fixed) » Needs review
StatusFileSize
new823 bytes

empty spans are still present in 7.x-1.x version.
here somes the patch.

dropfen’s picture

StatusFileSize
new1.21 KB

Oops, sorry ;)
This is the right one.

dropfen’s picture

StatusFileSize
new1.02 KB

fix coding guidlines.

jcnventura’s picture

Version: 7.x-1.0 » 6.x-1.10
Status: Needs review » Closed (fixed)

No, 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.

jcnventura’s picture

Issue summary: View changes

Making example code visible.