Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. HtmlEscapedText.php

class HtmlEscapedText

Escapes HTML syntax characters to HTML entities for display in markup.

This class can be used to provide theme engine-like late escaping functionality.

Hierarchy

  • class \Drupal\Component\Render\HtmlEscapedText implements \Drupal\Component\Render\MarkupInterface, \Drupal\Component\Render\Countable

Expanded class hierarchy of HtmlEscapedText

1 file declares its use of HtmlEscapedText
Token.php in core/lib/Drupal/Core/Utility/Token.php

File

core/lib/Drupal/Component/Render/HtmlEscapedText.php, line 15

Namespace

Drupal\Component\Render
View source
class HtmlEscapedText implements MarkupInterface, \Countable {
    
    /**
     * The string to escape.
     *
     * @var string
     */
    protected $string;
    
    /**
     * Constructs an HtmlEscapedText object.
     *
     * @param string $string
     *   The string to escape. This value will be cast to a string.
     */
    public function __construct($string) {
        $this->string = (string) $string;
    }
    
    /**
     * {@inheritdoc}
     */
    public function __toString() {
        return Html::escape($this->string);
    }
    
    /**
     * {@inheritdoc}
     */
    public function count() : int {
        return mb_strlen($this->string);
    }
    
    /**
     * {@inheritdoc}
     */
    public function jsonSerialize() : string {
        return $this->__toString();
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
HtmlEscapedText::$string protected property The string to escape.
HtmlEscapedText::count public function
HtmlEscapedText::jsonSerialize public function
HtmlEscapedText::__construct public function Constructs an HtmlEscapedText object.
HtmlEscapedText::__toString public function Returns markup. Overrides MarkupInterface::__toString

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal