function SafeMarkup::format

Formats a string for HTML display by replacing variable placeholders.

Parameters

string $string: A string containing placeholders. The string itself will not be escaped, any unsafe content must be in $args and inserted via placeholders.

array $args: An array with placeholder replacements, keyed by placeholder. See \Drupal\Component\Render\FormattableMarkup::placeholderFormat() for additional information about placeholders.

Return value

string|\Drupal\Component\Render\MarkupInterface The formatted string, which is an instance of MarkupInterface unless sanitization of an unsafe argument was suppressed (see above).

Deprecated

in drupal:8.0.0 and is removed from drupal:9.0.0. Use \Drupal\Component\Render\FormattableMarkup.

See also

\Drupal\Component\Render\FormattableMarkup::placeholderFormat()

\Drupal\Component\Render\FormattableMarkup

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

1 call to SafeMarkup::format()
SafeMarkupTest::testFormat in core/tests/Drupal/Tests/Component/Utility/SafeMarkupTest.php
Tests string formatting with SafeMarkup::format().

File

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

Class

SafeMarkup
Contains deprecated functionality related to sanitization of markup.

Namespace

Drupal\Component\Utility

Code

public static function format($string, array $args) {
    @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);
    return new FormattableMarkup($string, $args);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.