diff -u b/core/modules/filter/filter.module b/core/modules/filter/filter.module --- b/core/modules/filter/filter.module +++ b/core/modules/filter/filter.module @@ -105,7 +105,6 @@ ); $type['processed_text'] = array( '#text' => '', - '#format' => NULL, '#filter_types_to_skip' => array(), '#langcode' => '', '#pre_render' => array( @@ -307,13 +306,13 @@ * * @param string $text * The text to be filtered. - * @param string|null $format_id - * (optional) The machine name of the filter format to be used to filter the - * text. Defaults to the fallback format. See filter_fallback_format(). + * @param string $format_id + * The machine name of the filter format to be used to filter the text. * @param string $langcode * (optional) The language code of the text to be filtered, e.g. 'en' for - * English. This allows filters to be language-aware so language-specific - * text replacement can be implemented. Defaults to an empty string. + * English. This allows filters to be language-aware so language-specific text + * replacement can be implemented. Defaults to + * Drupal\Core\Language\LanguageInterface::LANGCODE_NOT_SPECIFIED. * @param array $filter_types_to_skip * (optional) An array of filter types to skip, or an empty array (default) * to skip no filter types. All of the format's filters will be applied, @@ -328,7 +327,7 @@ * * @ingroup sanitization */ -function check_markup($text, $format_id = NULL, $langcode = '', $filter_types_to_skip = array()) { +function check_markup($text, $format_id, $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED, $filter_types_to_skip = array()) { $build = array( '#type' => 'processed_text', '#text' => $text, @@ -443,14 +442,13 @@ * * @param string $text * The text to be filtered. - * @param string $format_id - * The machine name of the filter format to be used to filter the text. If - * NULL, the fallback format is used. See filter_fallback_format(). + * @param string|null $format_id + * (optional) The machine name of the filter format to be used to filter the + * text. Defaults to the fallback format. See filter_fallback_format(). * @param string $langcode * (optional) The language code of the text to be filtered, e.g. 'en' for - * English. This allows filters to be language-aware so language-specific text - * replacement can be implemented. Defaults to - * Drupal\Core\Language\LanguageInterface::LANGCODE_NOT_SPECIFIED. + * English. This allows filters to be language-aware so language-specific + * text replacement can be implemented. Defaults to an empty string. * @param array $filter_types_to_skip * (optional) An array of filter types to skip, or an empty array (default) * to skip no filter types. All of the format's filters will be applied, @@ -465,7 +463,7 @@ * * @ingroup sanitization */ -function check_markup($text, $format_id, $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED, $filter_types_to_skip = array()) { +function check_markup($text, $format_id = NULL, $langcode = '', $filter_types_to_skip = array()) { $build = array( '#type' => 'processed_text', '#text' => $text, diff -u b/core/modules/filter/src/Tests/FilterNoFormatTest.php b/core/modules/filter/src/Tests/FilterNoFormatTest.php --- b/core/modules/filter/src/Tests/FilterNoFormatTest.php +++ b/core/modules/filter/src/Tests/FilterNoFormatTest.php @@ -26,8 +26,7 @@ /** * Tests text without format. * - * Tests if text with no format is filtered the same way as text in the - * fallback format. + * Tests if text with no format is throwing an appropriate exception. */ function testCheckMarkupNoFormat() { // Create some text. Include some HTML and line breaks, so we get a good @@ -36,6 +35,16 @@ // Make sure that when this text is run through check_markup() with no text - // format, it is filtered as though it is in the fallback format. - $this->assertEqual(check_markup($text, NULL), check_markup($text, filter_fallback_format()), 'Text with no format is filtered the same as text in the fallback format.'); + // format, it throws an appropriate exception. + try { + check_markup($text, NULL); + $this->fail('\InvalidArgumentException expected'); + } + catch (\InvalidArgumentException $e) { + $this->pass('\InvalidArgumentException expected and caught.'); + } + catch (Exceptio $e) { + $this->fail('\InvalidArgumentException expected, but ' . get_class($e) . ' was thrown.'); + } + } } diff -u b/core/modules/views/src/Tests/Handler/AreaTextTest.php b/core/modules/views/src/Tests/Handler/AreaTextTest.php --- b/core/modules/views/src/Tests/Handler/AreaTextTest.php +++ b/core/modules/views/src/Tests/Handler/AreaTextTest.php @@ -58,14 +58,14 @@ $view->display_handler->handlers['header']['area']->options['format'] = filter_default_format(); $build = $view->display_handler->handlers['header']['area']->render(); - $this->assertEqual(check_markup($string, NULL), drupal_render($build), 'Existent format should return something'); + $this->assertEqual(check_markup($string, filter_fallback_format()), drupal_render($build), 'Existent format should return something'); // Empty results, and it shouldn't be displayed . $this->assertEqual(array(), $view->display_handler->handlers['header']['area']->render(TRUE), 'No result should lead to no header'); // Empty results, and it should be displayed. $view->display_handler->handlers['header']['area']->options['empty'] = TRUE; $build = $view->display_handler->handlers['header']['area']->render(TRUE); - $this->assertEqual(check_markup($string, NULL), drupal_render($build), 'No result, but empty enabled lead to a full header'); + $this->assertEqual(check_markup($string, filter_fallback_format()), drupal_render($build), 'No result, but empty enabled lead to a full header'); } } only in patch2: unchanged: --- a/core/modules/filter/src/Element/ProcessedText.php +++ b/core/modules/filter/src/Element/ProcessedText.php @@ -65,6 +65,9 @@ public function getInfo() { * @return array * The passed-in element with the filtered text in '#markup'. * + * @throws |InvalidArgumentException + * When no $format_id is specified. + * * @ingroup sanitization */ public static function preRenderText($element) { @@ -74,7 +77,7 @@ public static function preRenderText($element) { $langcode = $element['#langcode']; if (!isset($format_id)) { - $format_id = static::configFactory()->get('filter.settings')->get('fallback_format'); + throw new \InvalidArgumentException('Format ID is not set'); } // If the requested text format does not exist, the text cannot be filtered. /** @var \Drupal\filter\Entity\FilterFormat $format **/