Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / lib / Drupal / Component / Utility / SafeMarkup.php
1 <?php
2
3 namespace Drupal\Component\Utility;
4
5 use Drupal\Component\Render\HtmlEscapedText;
6 use Drupal\Component\Render\FormattableMarkup;
7 use Drupal\Component\Render\MarkupInterface;
8
9 /**
10  * Contains deprecated functionality related to sanitization of markup.
11  *
12  * @deprecated Will be removed before Drupal 9.0.0. Use the appropriate
13  *   @link sanitization sanitization functions @endlink or the @link theme_render theme and render systems @endlink
14  *   so that the output can can be themed, escaped, and altered properly.
15  *
16  * @see https://www.drupal.org/node/2549395
17  *
18  * @see TwigExtension::escapeFilter()
19  * @see twig_render_template()
20  * @see sanitization
21  * @see theme_render
22  */
23 class SafeMarkup {
24
25   /**
26    * Checks if a string is safe to output.
27    *
28    * @param string|\Drupal\Component\Render\MarkupInterface $string
29    *   The content to be checked.
30    * @param string $strategy
31    *   (optional) This value is ignored.
32    *
33    * @return bool
34    *   TRUE if the string has been marked secure, FALSE otherwise.
35    *
36    * @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0.
37    *   Instead, you should just check if a variable is an instance of
38    *   \Drupal\Component\Render\MarkupInterface.
39    *
40    * @see https://www.drupal.org/node/2549395
41    */
42   public static function isSafe($string, $strategy = 'html') {
43     @trigger_error('SafeMarkup::isSafe() is scheduled for removal in Drupal 9.0.0. Instead, you should just check if a variable is an instance of \Drupal\Component\Render\MarkupInterface. See https://www.drupal.org/node/2549395.', E_USER_DEPRECATED);
44     return $string instanceof MarkupInterface;
45   }
46
47   /**
48    * Encodes special characters in a plain-text string for display as HTML.
49    *
50    * Also validates strings as UTF-8. All processed strings are also
51    * automatically flagged as safe markup strings for rendering.
52    *
53    * @param string $text
54    *   The text to be checked or processed.
55    *
56    * @return \Drupal\Component\Render\HtmlEscapedText
57    *   An HtmlEscapedText object that escapes when rendered to string.
58    *
59    * @deprecated Will be removed before Drupal 9.0.0. Rely on Twig's
60    *   auto-escaping feature, or use the @link theme_render #plain_text @endlink
61    *   key when constructing a render array that contains plain text in order to
62    *   use the renderer's auto-escaping feature. If neither of these are
63    *   possible, \Drupal\Component\Utility\Html::escape() can be used in places
64    *   where explicit escaping is needed.
65    *
66    * @see https://www.drupal.org/node/2549395
67    * @see drupal_validate_utf8()
68    */
69   public static function checkPlain($text) {
70     @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);
71     return new HtmlEscapedText($text);
72   }
73
74   /**
75    * Formats a string for HTML display by replacing variable placeholders.
76    *
77    * @param string $string
78    *   A string containing placeholders. The string itself will not be escaped,
79    *   any unsafe content must be in $args and inserted via placeholders.
80    * @param array $args
81    *   An array with placeholder replacements, keyed by placeholder. See
82    *   \Drupal\Component\Render\FormattableMarkup::placeholderFormat() for
83    *   additional information about placeholders.
84    *
85    * @return string|\Drupal\Component\Render\MarkupInterface
86    *   The formatted string, which is an instance of MarkupInterface unless
87    *   sanitization of an unsafe argument was suppressed (see above).
88    *
89    * @see \Drupal\Component\Render\FormattableMarkup::placeholderFormat()
90    * @see \Drupal\Component\Render\FormattableMarkup
91    *
92    * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
93    *   Use \Drupal\Component\Render\FormattableMarkup.
94    *
95    * @see https://www.drupal.org/node/2549395
96    */
97   public static function format($string, array $args) {
98     @trigger_error('SafeMarkup::format() is scheduled for removal in Drupal 9.0.0. Use \Drupal\Component\Render\FormattableMarkup. See https://www.drupal.org/node/2549395.', E_USER_DEPRECATED);
99     return new FormattableMarkup($string, $args);
100   }
101
102 }