theme_links() don't allow for the html in the title (comment links broken)

gordon - August 13, 2006 - 00:51
Project:Drupal
Version:x.y.z
Component:base system
Category:bug report
Priority:critical
Assigned:chx
Status:closed
Description

since the check_plain() has been added to the title you can't put HTML into the title to include things like images (which is used alot) and things like embeded links for adding multiple <a> to a single link in hook_links().

This implementation is used a lot in the image module and the ecommerce modules.

#1

gordon - August 18, 2006 - 12:48
Title:l() and theme_links() don't allow for the html in the title» theme_links() don't allow for the html in the title

I was mistaken on l(), but theme_link() still has the issue.

I thought of adding another option which could be past to l() as the $html parameter so that it will not run the check_plain() over the title, but this will not work for links where there is only a title.

#2

Dries - September 8, 2006 - 18:19

The links can be altered now. Would that allow you to work-around the limitations?

#3

gordon - September 10, 2006 - 03:15

Yes links can be altered, but in the end they are going to be past through theme_links(). Then the title will always be past through check_plain().

This will also be an issue where you are trying to add images to links, in the my situation where I only want part of the text to be a link.

1 Idea would be to add a html option to the links array which will stop it from being past to check_plain().

Please let me know it this is an OK option and I will build a patch.

#4

m3avrck - October 2, 2006 - 20:50

Gordon, you are refering to this line of code?

  //Some links are actually not links, but we wrap these in <span> for adding title and class attributes
        $output .= '<span'. drupal_attributes($link['attributes']) .'>'. check_plain($link['title']) .'</span>';

If so, yes perhaps adding a $html = FALSE and then doing if ($html) // don't do check plain

I would be cool with that.

#5

m3avrck - October 2, 2006 - 20:54
Priority:critical» normal

not critical

#6

gordon - October 3, 2006 - 08:02

I am not sure as this breaks stuff in the E-Commerce module, and also the spam module.

#7

eaton - October 12, 2006 - 23:19

I'm creating a list of icons that are links; this makes it impossible to use the theming functions. Adding a simple $html = FALSE param at the end of the function would be much smoother.

#8

chx - October 12, 2006 - 23:27
Priority:normal» critical
Assigned to:Anonymous» chx
Status:active» needs review

First of, this is critical. Second, the fix needs to be per link, not per theme links call, or so I think. If I think right then patching this is simple.

AttachmentSize
theme_links_html.patch 716 bytes

#9

chx - October 12, 2006 - 23:37

I made a small logic flaw in the patch but it's too late to find on first read :)

AttachmentSize
theme_links_html_0.patch 718 bytes

#10

eaton - October 12, 2006 - 23:52

Above patch catches text-only entries, but not calls to l(). This one catches both. let it be known: chx wrote this version, too, including the comment! ;-)

AttachmentSize
theme_links_0.patch 1.32 KB

#11

gordon - October 13, 2006 - 00:37
Status:needs review» reviewed & tested by the community

I have tested this patch with E-Commerce, and it fixes the problem.

Thanks chx.

#12

Dries - October 15, 2006 - 20:19
Status:reviewed & tested by the community» needs work

I don't like the proposed solution.

You can overwrite the theme function if you want to change this behavior.

If that is not sufficient, I suggest we refactor the functionality so that the filtering happens on the module-side.

#13

eaton - October 15, 2006 - 21:26

Dries, this is a matter of API changes in 5.0 breaking functionality that worked in 4.7.

Previously, we did allow modules to handle the filtering: theme_links() just took an array of HTML chunks. Now, it takes an array of structured arrays.

You can overwrite the theme function if you want to change this behavior.

The problem is that the theme function *used* to allow it but now does not. It seems broken to remove a perfectly reasonable case and ask every module developer who wants to use icons as links to copy-paste a core function, implementing their own custom version.

If that is not sufficient, I suggest we refactor the functionality so that the filtering happens on the module-side.

This patch makes it an option. Set #html => TRUE, and you're in charge of the filtering.

#14

Steven - October 15, 2006 - 23:13

If you want icons, just use CSS to add them?

#15

gordon - October 15, 2006 - 23:53

css is not really an option, as the image is the link.

In the case of E-Commerce it the following line which was value in 4.7, now cannot be done.

this item is in <a href="/cart/view">your shoping cart</a>

Now modules like E-Commerce and the service links need to patch the theme to get functionality which is currently available in 4.7.

#16

chx - October 17, 2006 - 06:39
Status:needs work» reviewed & tested by the community

"You can overwrite the theme function if you want to change this behavior" since when can a module override a theme function? We do not have a too good distribution vehicle for template.php snippets.

"If that is not sufficient, I suggest we refactor the functionality so that the filtering happens on the module-side." Steven told me that the way Drupal tries to be more secure is that we provide such an API which helps the run-of-the-mill developer to not make security holes. The new t() function is a big step forwards to this direction as was the big check_plain patch which made l() more secure in 2005 March. I seriously doubt that we want to step back and ask every module developer to check_plain for his link.

#17

drumm - October 17, 2006 - 08:34

Looks okay to me after reading the last patch.

#18

Dries - October 17, 2006 - 19:27

The 'this item is in your shopping cart' example is awkward. Maybe you are trying to abuse the link system in ways you shouldn't? It looks more like textual information than a link. The function is call theme_links(), theme_text_with_links().

#19

eaton - October 17, 2006 - 19:33

I don't think it's particularly grave abuse of the system. We've removed fairly straightforward functionality, and this patch restores it in a way that's very simple and clean.

The function *already* has tons of special casing code for 'links' that are only text, not links at all. So clearly, that's a supported use. This patch just makes it possible to have more complex HTML in the link -- a list of icon-buttons, for example.

#20

drumm - October 18, 2006 - 07:24
Status:reviewed & tested by the community» needs work

There is a precedent for this in core and I believe it is broken at the moment, "login or register to post comments." I think this patch will need to fix that.

#21

chx - October 18, 2006 - 08:18
Title:theme_links() don't allow for the html in the title» theme_links() don't allow for the html in the title (comment links broken)
Status:needs work» reviewed & tested by the community

OK, then we fix comment links in this patch.

AttachmentSize
theme_links_1.patch 2.52 KB

#22

Dries - October 18, 2006 - 11:14

For me this illustrates that we did the wrong thing with the theme_links() patch. Hackability has been significantly reduced, and the complexity has been significantly increased. Maybe that is something that ought to be roll-backed in Drupal 6.0.

I'm OK to commit this patch for now. Haven't had time to test it yet.

#23

eaton - October 18, 2006 - 14:20

Dries, hackability in *general* is much higher now because we store more meta-information about each link, and via hook_links_alter, modules can muck around with links before they're rendered into a chunk of HTML. We just 'capped' a lot of the hackability at the very last stage, when we forced everything through check_plain().

Overall, I think the links patch was a very valuable addition (though, in retrospect it would've been nice to set it up as a formsapi formatted array... but that's something for 6. ;))

#24

Dries - October 18, 2006 - 18:00
Status:reviewed & tested by the community» fixed

Committed to CVS HEAD. Thanks.

#25

Anonymous - November 1, 2006 - 18:01
Status:fixed» closed
 
 

Drupal is a registered trademark of Dries Buytaert.