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().
bool $text_processing: Whether to process the text via check_markup().
string $langcode: The language associated with $item.
array $item: The field value to sanitize.
string $column: The column to sanitize (either 'value' or 'summary').
string The sanitized string.
function text_sanitize($text_processing, $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}"];
  }
  if ($text_processing) {
    return check_markup($item[$column], $item['format'], $langcode);
  }
  // Escape all HTML and retain newlines.
  // @see \Drupal\text\Plugin\field\formatter\TextPlainFormatter
  return nl2br(check_plain($item[$column]));
}