The entity reference dropdown isn't showing special characters in title properly. I tried both Simple and Views selection modes.

Ex.
A node titled "Test's 1" displays as "Test's 1"

Comments

zdean’s picture

I'm also seeing this. The title "Test's" shows as "Test&039;s"

Graham Brand’s picture

This was giving me an issue when using an entity reference field in a contextual filter on a view. Entities where the Title contains an apostrophe are not being selected by a contextual filter on Title, which I suppose is comparing the actual Titles of the content type (without HTML entity versions of the apostrophe) with the Titles held by the entity reference field (which have the HTML entity versions of the apostrophe).

I got round this by passing the Nid as an argument and using that instead, but I could see this being a problem where someone really did need to filter on the Title.

bunthorne’s picture

I'm having the same problem where my ampersands in title fields are displaying as their HTML entity (&amp) in the select lists. It looks like this issue was addressed separately in the References module at http://drupal.org/node/1391814, although I don't know if it's the same problem and/or solution.

maxplus’s picture

Hi,
I'm having the same problem with the & symbol in a node title and using a select list.
Does anybody have a solution or a temporary workaround for this?
I don't know exactly how this is solved for the References module in the latest dev.

kunago’s picture

I have dirty-fixed this issue since I have also been experiencing '&' issue and to be honest, I simply don't like to see this in the options list.

I have discovered the function "filter_xss_admin" in "entityreference_plugin_style.inc" is to blame. Unless someone reviews the necessity of converting each entity to the code there might only be dirty fixes.

damien tournoud’s picture

SharonD214@aol.com’s picture

How did you fix this? I've got an apostrophe that should in my entity list as ' that I would like to get rid of.

Thanks
Sharon

SharonD214@aol.com’s picture

Guido Forks’s picture

I added this bit of Javascript into page.tpl.php which I found on another thread (I've changed it include encoded apostrophes):

<script type="text/javascript">
(function ($) {
  Drupal.behaviors.correct_ampersand = {
    attach: function(context, settings) {
      /** Change &amp; back to & in select options **/
      $('select option').each(function() {
        var text = $(this).text();
        if (text.indexOf('&amp;') >= 0) {
          text = text.replace("&amp;", "&");
        }
        if (text.indexOf('&#039;') >= 0) {
          text = text.replace("&#039;", "'");
        }
        $(this).text(text);
      });
    }
  }
})
(jQuery);
</script>

Original code by this chap here: https://www.drupal.org/node/1665818#comment-8507309

Phil

SharonD214@aol.com’s picture

Issue summary: View changes

Phil - Thanks this works great!

Sharon

phily’s picture

Patch on comment #32 at https://www.drupal.org/node/1665818#comment-7069158 works for me with Drupal 7.36 and Entity Reference 7.x-1.1

weri’s picture

weri’s picture

It's related to this core bug.

dipali.dhole’s picture

#9 works fine for me. +1

caldenjacobs’s picture

I'm running latest 7.50.x core and still experiencing this issue, so it's not fixed by #12 or #13, unless I'm missing something.

#11 works for me manually applied against the latest dev release.

virajrajankar’s picture

Assigned: Unassigned » virajrajankar
Status: Closed (duplicate) » Needs review
virajrajankar’s picture

You can use this function drupal_html_to_text($string, $allowed_tags = NULL) to remove special character from any string.

You will get the output of You Know You&acirc;&euro;&trade; to "You Know You’".

You need to write hook_node_presave in your custom module to use "drupal_html_to_text()".


Example Code :

Create custom module and put below code.

function Mymodule_node_presave($node){  
  $node->title = drupal_html_to_text($node->title);
}
rooby’s picture

Status: Needs review » Active

There is no patch to review.

rooby’s picture

Status: Active » Closed (duplicate)
rooby’s picture

NumanAslam’s picture

Use htmlspecialchars_decode() function

silentbob’s picture

Maybe this helps someone somehow. Its a different context but i had also an issue with special characters using the t() function.

If the node title is like this: Hello here comes my special character '
The ' would be rendered as #039;

 $false_output = t('This title will render wrong: @title', array(
              '@title' => $node->title,
  ));

Changing the placeholder variable prefix from @ to ! solved my issue. As it outputs the title as it is, without any restriction.

$correct_output = t('This title will render wrong: !title', array(
           '!title' => $node->title,
 ));