I'm starting to explore Drupal 7, and, while getting some custom modules working, have encountered the safe_value property that is now getting created for fields' values, as in $node->field_something['und'][0]['safe_value']. There's rather little documentation on this property (or else I just haven't found it yet); my assumption is that this property contains the display value of the field, properly cleaned via whatever format is appropriate for that field. The intent would seem to be that one can print this value inside a module or other hunk of PHP code without first running it through check_markup.

Is this correct? That would certainly be nice... Thanks!

Comments

SilviaT’s picture

I have the same question. And also, when and how is safe_value set? What if I want to edit the value for a field? How should I handle it?
I can't find (or maybe there's not) the documentation.

feo’s picture

+1

zilverdistel’s picture

I checked the code on this, and the answer is that the safe_value is processed through the function _text_sanitize (in /modules/field/modules/text/text.module). This function clearly uses check_markup(), so safe_value can safely be used.

/**
 * Sanitizes the 'value' or 'summary' data of a text value.
 *
 * Depending on whether the field instance uses text processing, data is run
 * through check_plain() or check_markup().
 *
 * @param $instance
 *   The instance definition.
 * @param $langcode
 *  The language associated to $item.
 * @param $item
 *   The field value to sanitize.
 * @param $column
 *   The column to sanitize (either 'value' or 'summary').
 *
 * @return
 *  The sanitized string.
 */
function _text_sanitize($instance, $langcode, $item, $column) {
  // If the value uses a cacheable text format, text_field_load() precomputes
  // the sanitized string.
  if (isset($item["safe_$column"])) {
    return $item["safe_$column"];
  }
  return $instance['settings']['text_processing'] ? check_markup($item[$column], $item['format'], $langcode) : check_plain($item[$column]);
}
jim_at_miramontes’s picture

Thanks very much for tracking this down!

smndey’s picture

I had the same question. Thanks for nice clarification.