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

endiku’s picture

My apologies. Last minute tinkering made me post the wrong original code. Here it is.

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)) ? $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)) ? $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']['value']];
  }
}
markus_petrux’s picture

Version: 6.x-3.x-dev » 6.x-2.x-dev
Status: Active » Needs work

I think this is not particulary related to CCK3. Changing version associated to the issue.

No patch, so it needs work.

mikeytown2’s picture

Not 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).

/**
 * Theme function for 'default' text field formatter.
 */
function theme_text_formatter_default($element) {
  return ($allowed =_text_allowed_values($element)) ? $allowed : $element['#item']['safe']; // LINE 216
}
mikeytown2’s picture

This is the solution I'm using

/**
 * Theme function for 'default' text field formatter.
 */
function theme_text_formatter_default($element) {
  return ($allowed =_text_allowed_values($element)) ? $allowed : isset($element['#item']['safe']) ? $element['#item']['safe'] : '';
}
TwoD’s picture

I'm getting the same notice as @mikeytown2, but it's now on line 217, also during previews.