8.2.x filter.module check_markup($text, $format_id = NULL, $langcode = '', $filter_types_to_skip = array())
8.0.x filter.module check_markup($text, $format_id = NULL, $langcode = '', $filter_types_to_skip = array())
8.1.x filter.module check_markup($text, $format_id = NULL, $langcode = '', $filter_types_to_skip = array())
8.3.x filter.module check_markup($text, $format_id = NULL, $langcode = '', $filter_types_to_skip = array())
4.7.x filter.module check_markup($text, $format = FILTER_FORMAT_DEFAULT, $check = TRUE)
5.x filter.module check_markup($text, $format = FILTER_FORMAT_DEFAULT, $check = TRUE)
6.x filter.module check_markup($text, $format = FILTER_FORMAT_DEFAULT, $check = TRUE)
7.x filter.module check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE)

Runs all the enabled filters on a piece of text.

Note: Because filters can inject JavaScript or execute PHP code, security is vital here. When a user supplies a text format, you should validate it using $format->access() before accepting/using it. This is normally done in the validation stage of the Form API. You should for example never make a preview of content in a disallowed format.

Note: this function should only be used when filtering text for use elsewhere than on a rendered HTML page. If this is part of a HTML page, then a renderable array with a #type 'processed_text' element should be used instead of this, because that will allow cacheability metadata to be set and bubbled up and attachments to be associated (assets, placeholders, etc.). In other words: if you are presenting the filtered text in a HTML page, the only way this will be presented correctly, is by using the 'processed_text' element.


string $text: The text to be filtered.

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().

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.

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, except for filters of the types that are marked to be skipped. FilterInterface::TYPE_HTML_RESTRICTOR is the only type that cannot be skipped.

Return value

\Drupal\Component\Render\MarkupInterface The filtered text.

See also


Related topics

9 calls to check_markup()
AreaTextTest::testAreaText in core/modules/views/tests/src/Kernel/Handler/AreaTextTest.php
EditorController::getUntransformedText in core/modules/editor/src/EditorController.php
Returns an Ajax response to render a text field without transformation filters.
FilterAPITest::testCheckMarkupFilterOrder in core/modules/filter/tests/src/Kernel/FilterAPITest.php
Tests that the filter order is respected.
FilterAPITest::testCheckMarkupFilterSubset in core/modules/filter/tests/src/Kernel/FilterAPITest.php
Tests the ability to apply only a subset of filters.
FilterNoFormatTest::testCheckMarkupNoFormat in core/modules/filter/src/Tests/FilterNoFormatTest.php
Tests text without format.

... See full list


core/modules/filter/filter.module, line 294
Framework for handling the filtering of content.


function check_markup($text, $format_id = NULL, $langcode = '', $filter_types_to_skip = array()) {
  $build = array(
    '#type' => 'processed_text',
    '#text' => $text,
    '#format' => $format_id,
    '#filter_types_to_skip' => $filter_types_to_skip,
    '#langcode' => $langcode,
  return \Drupal::service('renderer')->renderPlain($build);