diff --git a/core/modules/field/field.api.php b/core/modules/field/field.api.php index 095c28d4970..bc178ed7337 100644 --- a/core/modules/field/field.api.php +++ b/core/modules/field/field.api.php @@ -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') : ''; } } } diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php index 7a9e5f0762a..633d3f3f900 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php @@ -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.'); diff --git a/core/modules/node/node.tokens.inc b/core/modules/node/node.tokens.inc index d1c921130f4..241b83bf04f 100644 --- a/core/modules/node/node.tokens.inc +++ b/core/modules/node/node.tokens.inc @@ -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. diff --git a/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextDefaultFormatter.php b/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextDefaultFormatter.php index efdf8bb640f..4a96cc3da03 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextDefaultFormatter.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextDefaultFormatter.php @@ -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); } diff --git a/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextTrimmedFormatter.php b/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextTrimmedFormatter.php index 24ae3af0925..ba8b417da5b 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextTrimmedFormatter.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextTrimmedFormatter.php @@ -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); diff --git a/core/modules/text/text.module b/core/modules/text/text.module index 37df945236b..4bf51b60016 100644 --- a/core/modules/text/text.module +++ b/core/modules/text/text.module @@ -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.