Tuesday, September 6, 2011

Marinelli 3, Drupal 7: HTML entities shown in banner image_title and image_description

Today I was beginning to create new content on a website in Drupal I renewed updating to D7 and installing the great Marinelli Theme (7.x-3.0-beta11)
I noticed that some characters in banners title and description showed as HTML entities (i.e. & #039; for the single quote symbol).

I digged in the code and I fixed the issue in a quite rude but effective way.
Learning more about the t() funcion from Drupal bootstrap.inc I found what was the meaning of Parameters give to that function
  • !variable: Inserted as is. Use this for text that has already been sanitized.
  • @variable: Escaped to HTML using check_plain(). Use this for anything displayed on a page on the site. 
The generation of banner title and description string is there made with the @ parameter. Unfortunately somewhere else in the code a further check_plain() call is made on the same strings. This second application of check_plain() function simply converts the symbols into HTML entities and this is the cause of the issue.

My solution was to replace the @ parameter with the ! one in t() function calls into marinelli_banner_markups()
This function in marinelli/logics/banners.inc

Here you are the code snippets:

'alt' => t('!image_desc', array('!image_desc'=>$banner['image_description'])),
'title'   => t('!image_title', array('!image_title'=>$banner['image_title'])),

...

'longdesc' => t('!image_desc', array('!image_desc'=>$banner['image_description']))

Keep on hackin' ;-)

0 commenti:

Post a Comment