Issue #1974396 by effulgentsia: Narrow the API of _text_sanitize() and make it public.
parent
7981d5d07b
commit
af7bd45648
|
@ -321,9 +321,9 @@ function hook_field_load($entity_type, $entities, $field, $instances, $langcode,
|
|||
// Only process items with a cacheable format, the rest will be handled
|
||||
// by formatters if needed.
|
||||
if (empty($instances[$id]['settings']['text_processing']) || filter_format_allowcache($item['format'])) {
|
||||
$items[$id][$delta]['safe_value'] = isset($item['value']) ? _text_sanitize($instances[$id], $langcode, $item, 'value') : '';
|
||||
$items[$id][$delta]['safe_value'] = isset($item['value']) ? text_sanitize($instances[$id]['settings']['text_processing'], $langcode, $item, 'value') : '';
|
||||
if ($field['type'] == 'text_with_summary') {
|
||||
$items[$id][$delta]['safe_summary'] = isset($item['summary']) ? _text_sanitize($instances[$id], $langcode, $item, 'summary') : '';
|
||||
$items[$id][$delta]['safe_summary'] = isset($item['summary']) ? text_sanitize($instances[$id]['settings']['text_processing'], $langcode, $item, 'summary') : '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,8 +52,8 @@ class NodeTokenReplaceTest extends NodeTestBase {
|
|||
$tests['[node:type]'] = 'article';
|
||||
$tests['[node:type-name]'] = 'Article';
|
||||
$tests['[node:title]'] = check_plain($node->title);
|
||||
$tests['[node:body]'] = _text_sanitize($instance, $node->langcode, $node->body[$node->langcode][0], 'value');
|
||||
$tests['[node:summary]'] = _text_sanitize($instance, $node->langcode, $node->body[$node->langcode][0], 'summary');
|
||||
$tests['[node:body]'] = text_sanitize($instance['settings']['text_processing'], $node->langcode, $node->body[$node->langcode][0], 'value');
|
||||
$tests['[node:summary]'] = text_sanitize($instance['settings']['text_processing'], $node->langcode, $node->body[$node->langcode][0], 'summary');
|
||||
$tests['[node:langcode]'] = check_plain($node->langcode);
|
||||
$tests['[node:url]'] = url('node/' . $node->nid, $url_options);
|
||||
$tests['[node:edit-url]'] = url('node/' . $node->nid . '/edit', $url_options);
|
||||
|
@ -94,7 +94,7 @@ class NodeTokenReplaceTest extends NodeTestBase {
|
|||
|
||||
// Generate and test sanitized token - use full body as expected value.
|
||||
$tests = array();
|
||||
$tests['[node:summary]'] = _text_sanitize($instance, $node->langcode, $node->body[$node->langcode][0], 'value');
|
||||
$tests['[node:summary]'] = text_sanitize($instance['settings']['text_processing'], $node->langcode, $node->body[$node->langcode][0], 'value');
|
||||
|
||||
// Test to make sure that we generated something for each token.
|
||||
$this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated for node without a summary.');
|
||||
|
|
|
@ -143,11 +143,11 @@ function node_tokens($type, $tokens, array $data = array(), array $options = arr
|
|||
|
||||
// If the summary was requested and is not empty, use it.
|
||||
if ($name == 'summary' && !empty($items[0]['summary'])) {
|
||||
$output = $sanitize ? _text_sanitize($instance, $field_langcode, $items[0], 'summary') : $items[0]['summary'];
|
||||
$output = $sanitize ? text_sanitize($instance['settings']['text_processing'], $field_langcode, $items[0], 'summary') : $items[0]['summary'];
|
||||
}
|
||||
// Attempt to provide a suitable version of the 'body' field.
|
||||
else {
|
||||
$output = $sanitize ? _text_sanitize($instance, $field_langcode, $items[0], 'value') : $items[0]['value'];
|
||||
$output = $sanitize ? text_sanitize($instance['settings']['text_processing'], $field_langcode, $items[0], 'value') : $items[0]['value'];
|
||||
// A summary was requested.
|
||||
if ($name == 'summary') {
|
||||
// Generate an optionally trimmed summary of the body field.
|
||||
|
|
|
@ -38,7 +38,7 @@ class TextDefaultFormatter extends FormatterBase {
|
|||
$elements = array();
|
||||
|
||||
foreach ($items as $delta => $item) {
|
||||
$output = _text_sanitize($this->instance, $langcode, $item, 'value');
|
||||
$output = text_sanitize($this->instance['settings']['text_processing'], $langcode, $item, 'value');
|
||||
$elements[$delta] = array('#markup' => $output);
|
||||
}
|
||||
|
||||
|
|
|
@ -70,10 +70,10 @@ class TextTrimmedFormatter extends FormatterBase {
|
|||
|
||||
foreach ($items as $delta => $item) {
|
||||
if ($this->getPluginId() == 'text_summary_or_trimmed' && !empty($item['summary'])) {
|
||||
$output = _text_sanitize($this->instance, $langcode, $item, 'summary');
|
||||
$output = text_sanitize($this->instance['settings']['text_processing'], $langcode, $item, 'summary');
|
||||
}
|
||||
else {
|
||||
$output = _text_sanitize($this->instance, $langcode, $item, 'value');
|
||||
$output = text_sanitize($this->instance['settings']['text_processing'], $langcode, $item, 'value');
|
||||
$output = text_summary($output, $this->instance['settings']['text_processing'] ? $item['format'] : NULL, $this->getSetting('trim_length'));
|
||||
}
|
||||
$elements[$delta] = array('#markup' => $output);
|
||||
|
|
|
@ -179,9 +179,9 @@ function text_field_load($entity_type, $entities, $field, $instances, $langcode,
|
|||
// Only process items with a cacheable format, the rest will be handled
|
||||
// by formatters if needed.
|
||||
if (empty($instances[$id]['settings']['text_processing']) || filter_format_allowcache($item['format'])) {
|
||||
$items[$id][$delta]['safe_value'] = isset($item['value']) ? _text_sanitize($instances[$id], $langcode, $item, 'value') : '';
|
||||
$items[$id][$delta]['safe_value'] = isset($item['value']) ? text_sanitize($instances[$id]['settings']['text_processing'], $langcode, $item, 'value') : '';
|
||||
if ($field['type'] == 'text_with_summary') {
|
||||
$items[$id][$delta]['safe_summary'] = isset($item['summary']) ? _text_sanitize($instances[$id], $langcode, $item, 'summary') : '';
|
||||
$items[$id][$delta]['safe_summary'] = isset($item['summary']) ? text_sanitize($instances[$id]['settings']['text_processing'], $langcode, $item, 'summary') : '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -204,25 +204,25 @@ function text_field_is_empty($item, $field) {
|
|||
* 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
|
||||
* @param bool $text_processing
|
||||
* Whether to process the text via check_markup().
|
||||
* @param string $langcode
|
||||
* The language associated with $item.
|
||||
* @param $item
|
||||
* @param array $item
|
||||
* The field value to sanitize.
|
||||
* @param $column
|
||||
* @param string $column
|
||||
* The column to sanitize (either 'value' or 'summary').
|
||||
*
|
||||
* @return
|
||||
* @return string
|
||||
* The sanitized string.
|
||||
*/
|
||||
function _text_sanitize($instance, $langcode, $item, $column) {
|
||||
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 ($instance['settings']['text_processing']) {
|
||||
if ($text_processing) {
|
||||
return check_markup($item[$column], $item['format'], $langcode);
|
||||
}
|
||||
// Escape all HTML and retain newlines.
|
||||
|
|
Loading…
Reference in New Issue