hi,
I'm using 7.x-1.0-alpha6 with an omega 7.x-3.1 subtheme and I see node titles broken in teaser display mode, something like this:
broken teaser title html
After looking at page source I found some html tag inside the title attribute of html anchor around title (when displaying in teaser mode).
<h2 property="dc:title" datatype="" class="node-title"><a href="/product/fere-hos-importunus-loquor-pneum-suscipit" title="<div data-edit-id="node/128/title/und/teaser"><div class="field-item">Fere Hos Importunus Loquor Pneum Suscipit</div></div>"><div data-edit-id="node/128/title/und/teaser"><div class="field-item">Fere Hos Importunus Loquor Pneum Suscipit</div></div></a></h2>
I found that the problem is wrong way used to wrap title in some html wrapper inside function theme_edit_wrap_field($variables). you added your html wrapper tags, directly to title string:

return '<'. $el . drupal_attributes($variables['attributes']) . '><' . $el .' class="field-item">' .  $variables['value'] . '</' . $el . '></' . $el . '>';

so variable $title in file sites/<domain>/themes/omega/omega/templates/node.tpl.php become non-plain text, then themes like omega using node title as title attribute of anchor wrapper in teaser display mode will generate wrong html codes, and cause something broken like this. for example omega uses this code:

<h2<?php print $title_attributes; ?>><a href="<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a></h2>

To prevent this problem I suggest use variables $title_prefix and $title_suffix instead appending and prepending tags to $title.

Comments

nod_’s picture

Version: 7.x-1.0-alpha6 » 7.x-1.x-dev

Yeah I see the issue, title prefix and suffix doesn't work well though. I had to do it like that :(

wim leers’s picture

Title: broken html structure in teaser mode » Use of theme_edit_wrap_field() breaks node titles for some themes
Priority: Major » Normal

#1: Can you clarify? Why are $title_(pre|suf)fix not viable?

nod_’s picture

because on that case what is wrapped is different to what is rerendered.

Manovra76’s picture

I have the same problem, in the node teaser title with tag to full node, the new attributes broken html. I use this work around

file: edit.module
function: theme_edit_wrap_field
row: 669

replace:
------------
return '<'. $el . drupal_attributes($variables['attributes']) . '><' . $el .' class="field-item">' . $variables['value'] . '';
------------
with
------------
if(strpos($variables['edit_id'],'title')===FALSE) {
return '<'. $el . drupal_attributes($variables['attributes']) . '><' . $el .' class="field-item">' . $variables['value'] . '';
} else {
return '<'. $el . '><' . $el .' >' . $variables['value'] . '';
}
------------

is not the solution, but the html is not broken.

wim leers’s picture

Title: Use of theme_edit_wrap_field() breaks node titles for some themes » Figure out work-around: the use of theme_edit_wrap_field() breaks node titles for some themes
Priority: Normal » Major
Issue tags: +Spark

So… how are we ever going to succeed in solving this? AFAICT this is not a solvable problem? It's due to insufficient abstraction requirements in D7. I think the only conceivable solution is to add a work-around for this in Edit itself?

wim leers’s picture

Status: Needs work » Fixed

D'oh, it's actually much simpler. The only time where this is a problem, is where a team also prints the title as an attribute (i.e. when it assumes the title does not contain any HTML). That's a poor assumption to make. E.g. some titles may contain <em>, which is perfectly sensible. When used in an attribute, any and all HTML should be stripped.

So, instead of:

<h2<?php print $title_attributes; ?>><a href="<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a></h2>

please use this instead:

<h2<?php print $title_attributes; ?>><a href="<?php print $node_url ?>" title="<?php print filter_xss($title, array()) ?>"><?php print $title ?></a></h2>

Or, more specifically:

title="<?php print $title ?>"

title="<?php print filter_xss($title, array()) ?>"

(Ideally, you would handle this in theme preprocess functions.)

Problem solved, correct output guaranteed.


Fix upcoming (I need to link to this comment), in the form of documentation in the README.

wim leers’s picture

Title: Figure out work-around: the use of theme_edit_wrap_field() breaks node titles for some themes » Some themes print the node title in an attribute, thereby breaking HTML
Component: Code » Documentation
Assigned: Unassigned » wim leers

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