If you use "allowed values" (either flat method or php code) in a text field then the input format chosen for your node and field will be ignored and plain text will be used instead.
The culprit is here in text.module with the formatter functions. They all call _text_allowed_values() which returns the plain text value $element['#item']['value'] instead of the formatted value $element['#item']['safe'] which is made from the "input format" selected for your content type and field.
Original code.
function theme_text_formatter_default($element) {
return ($allowed =_text_allowed_values($element)) ? $allowed : $element['#item']['safe'];
}
/**
* Theme function for 'plain' text field formatter.
*/
function theme_text_formatter_plain($element) {
return ($allowed =_text_allowed_values($element)) ? strip_tags($allowed) : strip_tags($element['#item']['safe']);
}
/**
* Theme function for 'trimmed' text field formatter.
*/
function theme_text_formatter_trimmed($element) {
$field = content_fields($element['#field_name'], $element['#type_name']);
return ($allowed =_text_allowed_values($element)) ? node_teaser($allowed) : node_teaser($element['#item']['safe'], $field['text_processing'] ? $element['#item']['format'] : NULL);
}
function _text_allowed_values($element) {
$field = content_fields($element['#field_name'], $element['#type_name']);
if (($allowed_values = content_allowed_values($field)) && isset($allowed_values[$element['#item']['value']])) {
return $allowed_values[$element['#item']['safe']];
}
}
My suggestion is to change two things.
1. apply the different features to $allowed for each function (strip_tags($allowed) and node_teaser($allowed)) and
2. change _text_allowed_values to return $element['#item']['safe'] instead of $element['#item']['value']
Suggested code
function theme_text_formatter_plain($element) {
return ($allowed =_text_allowed_values($element)) ? strip_tags($allowed) : strip_tags($element['#item']['safe']);
}
/**
* Theme function for 'trimmed' text field formatter.
*/
function theme_text_formatter_trimmed($element) {
$field = content_fields($element['#field_name'], $element['#type_name']);
return ($allowed =_text_allowed_values($element)) ? node_teaser($allowed) : node_teaser($element['#item']['safe'], $field['text_processing'] ? $element['#item']['format'] : NULL);
}
function _text_allowed_values($element) {
$field = content_fields($element['#field_name'], $element['#type_name']);
if (($allowed_values = content_allowed_values($field)) && isset($allowed_values[$element['#item']['value']])) {
return $allowed_values[$element['#item']['safe']];
}
}
Comments
Comment #1
endiku CreditAttribution: endiku commentedMy apologies. Last minute tinkering made me post the wrong original code. Here it is.
Comment #2
markus_petrux CreditAttribution: markus_petrux commentedI think this is not particulary related to CCK3. Changing version associated to the issue.
No patch, so it needs work.
Comment #3
mikeytown2 CreditAttribution: mikeytown2 commentedNot sure how revelent this is but I got this notice on a node/add page with the referrer being the same node/add page as well... preview page is what triggered the notices.
Notice: Undefined index: safe in theme_text_formatter_default() (line 216 of sites/all/modules/cck/modules/text/text.module).
Comment #4
mikeytown2 CreditAttribution: mikeytown2 commentedThis is the solution I'm using
Comment #5
TwoDI'm getting the same notice as @mikeytown2, but it's now on line 217, also during previews.