You are here

public static function SafeMarkup::checkPlain in Drupal 8

Encodes special characters in a plain-text string for display as HTML.

Also validates strings as UTF-8. All processed strings are also automatically flagged as safe markup strings for rendering.

Parameters

string $text: The text to be checked or processed.

Return value

\Drupal\Component\Render\HtmlEscapedText An HtmlEscapedText object that escapes when rendered to string.

Deprecated

Will be removed before Drupal 9.0.0. Rely on Twig's auto-escaping feature, or use the #plain_text key when constructing a render array that contains plain text in order to use the renderer's auto-escaping feature. If neither of these are possible, \Drupal\Component\Utility\Html::escape() can be used in places where explicit escaping is needed.

See also

https://www.drupal.org/node/2549395

drupal_validate_utf8()

1 call to SafeMarkup::checkPlain()
SafeMarkupTest::testCheckPlain in core/tests/Drupal/Tests/Component/Utility/SafeMarkupTest.php
Tests SafeMarkup::checkPlain().

File

core/lib/Drupal/Component/Utility/SafeMarkup.php, line 69

Class

SafeMarkup
Contains deprecated functionality related to sanitization of markup.

Namespace

Drupal\Component\Utility

Code

public static function checkPlain($text) {
  @trigger_error('SafeMarkup::checkPlain() is scheduled for removal in Drupal 9.0.0. Rely on Twig\'s auto-escaping feature, or use the @link theme_render #plain_text @endlink key when constructing a render array that contains plain text in order to use the renderer\'s auto-escaping feature. If neither of these are possible, \\Drupal\\Component\\Utility\\Html::escape() can be used in places where explicit escaping is needed. See https://www.drupal.org/node/2549395.', E_USER_DEPRECATED);
  return new HtmlEscapedText($text);
}