When setting the source for the tooltip in Leaflet Views, if you choose a text field that allows markup, or if you are rewriting the field's markup in the view, that markup is displayed in the tooltip according to the formatter settings.

Screenshots

Title field, when it's configured to link to its node content:
Tooltip using rewritten Title field

Body field using the Default formatter (Summary formatter also looks like this):
Tooltip with markup rendered

Body field using the Plain text formatter:
Plain text tooltip

Markup should be stripped from the tooltip text before it's rendered. For Body and other fields that can contain markup themselves, would it be possible to force the formatter to Plain text? What would be a good solution to catch odd cases like simple text fields that are rewritten with markup?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

interdruper’s picture

Status: Active » Needs review
FileSize
703 bytes

An easy fix is to filter any html tag in the Javascript code.
Patch attached.

othermachines’s picture

Patch applies cleanly against 7.x-1.x. Works as advertised.

Before:

Before

After:

After

xaa’s picture

there is still the problem for the html tag '
could you adjust the patch, please ?
see http://i.imgur.com/Hhr4UTG.png

ahillio’s picture

Yes patch applies and works. I've used it several times on leaflet-1.1 (haven't tried it on dev).

@xaa are you sure you properly patched the module with this? It's a simple patch so should work I think...

dmegatool’s picture

The apostrophe doesn't work for me either. It shows as &#039 in the tooltip. Other characters seems ok... Why is this different than the marker tag which works perfectly, without patching the js ?

One thing I noticed, ’ works but not ' (they're different and I need the latter one).

interdruper’s picture

The problem here is that the text inside the HTML tags is including html-special characters.
You must previously escape them if you want to get rid of them:

// escape html-special chars
str = marker.label.replace(/'/g, "'");
str = str.replace(/"/ig, '"');
str = str.replace(/&/ig, '&');

// get rid of any html tag
lMarker.options.title = str.replace(/(<([^>]+)>)/ig,"");

Sorry, I cannot find out a more elegant way to do this.

timodwhit’s picture

Have you tried to do something like: $point['label'] = strip_tags($this->rendered_fields[$id][$this->options['name_field']]); on line 267 of leaflet_views_plugin_style.inc?

I'll post a patch soon

timodwhit’s picture

Here is a patch that strips the tags from the view in the formatter

xaa’s picture

thank you for the patch Timodwhit. Unfortunately not working here.
Could you test it dmegatool ?

dmegatool’s picture

Not working here either. Still showing &#039;

hutch’s picture

try something like

$point['label'] = htmlspecialchars_decode(strip_tags($this->rendered_fields[$id][$this->options['name_field']]), ENT_QUOTES);
dmegatool’s picture

Still not doing it.

xaa’s picture

idem.

interdruper’s picture

Have you tried modification #6 over patch #1?

timodwhit’s picture

FileSize
819 bytes

@hutch's solution worked for me, I did need to clear the cache though: I tried name ' & "" <> and it printed out properly... Patch rerolled.

xaa’s picture

interdruper yes I tried #6 over patch #1

yaten’s picture

Leaflet 7.x-1.1 + patch #15 fixed my problem ( " ..039; " became " ' ").

Thanks.

  • RdeBoer committed bc49a90 on 7.x-1.x authored by timodwhit
    Issue #2169197 by timodwhit, interdruper: Tooltip does not strip markup
    
RdeBoer’s picture

Patch from #14 applied.

Thanks everyone!

Available now in Leaflet 7.x-1.x-dev or 7.x-1.2 and later, once released.

Rik

RdeBoer’s picture

Assigned: Unassigned » RdeBoer
Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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

asiby’s picture

Hello. I need to revive this issues because as of today, I can confirm that the issue is still present (more than a year after being marked closed). The htmlspecialchars_decode is now being called without the ENT_QUOTES flag and as a result, the default behaviour is to leave quotes alone.

Can the maintainer please reopen it?

asiby’s picture

Here is a patch for it.

RdeBoer’s picture

Status: Closed (fixed) » Patch (to be ported)

Re-opened so it doesn't get forgotten.

c7bamford’s picture

Patches should be created from the module's level so that automated builds can use them.