On this page
public static function MarkupTrait::create
public static MarkupTrait::create($string)
Creates a Markup object if necessary.
If $string is equal to a blank string then it is not necessary to create a Markup object. If $string is an object that implements MarkupInterface it is returned unchanged.
Parameters
mixed $string: The string to mark as safe. This value will be cast to a string.
Return value
string|\Drupal\Component\Render\MarkupInterface A safe string.
File
- core/lib/Drupal/Component/Render/MarkupTrait.php, line 34
Class
- MarkupTrait
- Implements MarkupInterface and Countable for rendered objects.
Namespace
Drupal\Component\RenderCode
public static function create($string) {
if ($string instanceof MarkupInterface) {
return $string;
}
$string = (string) $string;
if ($string === '') {
return '';
}
$safe_string = new static();
$safe_string->string = $string;
return $safe_string;
}
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Component!Render!MarkupTrait.php/function/MarkupTrait::create/8.1.x