hook_field_sanitize

Versions
7
hook_field_sanitize($obj_type, $object, $field, $instance, $langcode, &$items)

Define custom sanitize behavior for this module's field types.

This hook is invoked just before the field values are handed to formatters for display. Formatters being essentially theme functions, it is important that any data sanitization happens outside the theme layer.

Parameters

$obj_type The type of $object.

$object The object for the operation.

$field The field structure for the operation.

$instance The instance structure for $field on $object's bundle.

$langcode The language associated to $items.

$items $object->{$field['field_name']}, or an empty array if unset.

Related topics

Code

modules/field/field.api.php, line 319

<?php
function hook_field_sanitize($obj_type, $object, $field, $instance, $langcode, &$items) {
  foreach ($items as $delta => $item) {
    // Only sanitize items which were not already processed inside
    // hook_field_load(), i.e. items with uncacheable text formats, or coming
    // from a form preview.
    if (!isset($items[$delta]['safe'])) {
      if (!empty($instance['settings']['text_processing'])) {
        $format = $item['format'];
        $items[$delta]['safe'] = isset($item['value']) ? check_markup($item['value'], $format, $langcode, TRUE) : '';
        if ($field['type'] == 'text_with_summary') {
          $items[$delta]['safe_summary'] = isset($item['summary']) ? check_markup($item['summary'], $format, $langcode, TRUE) : '';
        }
      }
      else {
        $items[$delta]['safe'] = check_plain($item['value']);
        if ($field['type'] == 'text_with_summary') {
          $items[$delta]['safe_summary'] = check_plain($item['summary']);
        }
      }
    }
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.