Drupal 8  8.0.2
Html Class Reference

Static Public Member Functions

static getClass ($class)
 
static cleanCssIdentifier ($identifier, array $filter=array( ' '=> '-', '_'=> '-', '/'=> '-', '['=> '-', ']'=> '',))
 
static setIsAjax ($is_ajax)
 
static getUniqueId ($id)
 
static getId ($id)
 
static resetSeenIds ()
 
static normalize ($html)
 
static load ($html)
 
static serialize (\DOMDocument $document)
 
static escapeCdataElement (\DOMNode $node, $comment_start= '//', $comment_end= '')
 
static decodeEntities ($text)
 
static escape ($text)
 

Static Protected Attributes

static $classes = array()
 
static $seenIdsInit
 
static $seenIds
 
static $isAjax = FALSE
 

Detailed Description

Provides DOMDocument helpers for parsing and serializing HTML strings.

Member Function Documentation

static cleanCssIdentifier (   $identifier,
array  $filter = array(    ' ' => '-',    '_' => '-',    '/' => '-',    '[' => '-',    ']' => '',  ) 
)
static

Prepares a string for use as a CSS identifier (element, class, or ID name).

http://www.w3.org/TR/CSS21/syndata.html#characters shows the syntax for valid CSS identifiers (including element names, classes, and IDs in selectors.)

Parameters
string$identifierThe identifier to clean.
array$filterAn array of string replacements to use on the identifier.
Returns
string The cleaned identifier.

Referenced by ViewEditForm\buildOptionForm(), FieldPluginBase\elementClasses(), FieldPluginBase\elementLabelClasses(), FieldPluginBase\elementWrapperClasses(), Grid\getCustomClass(), ExposedFormTest\getExpectedExposedFormId(), ViewEditForm\getFormBucket(), StylePluginBase\getRowClass(), and HtmlTest\testCleanCssIdentifier().

Here is the caller graph for this function:

static decodeEntities (   $text)
static

Decodes all HTML entities including numerical ones to regular UTF-8 bytes.

Double-escaped entities will only be decoded once ("&amp;lt;" becomes "&lt;", not "<"). Be careful when using this function, as it will revert previous sanitization efforts (<script> will become <script>).

This method is not the opposite of Html::escape(). For example, this method will convert "&eacute;" to "é", whereas Html::escape() will not convert "é" to "&eacute;".

Parameters
string$textThe text to decode entities in.
Returns
string The input $text, with all HTML entities decoded once.
See Also
html_entity_decode()
::escape()

Referenced by ViewExecutable\_buildArguments(), DbLogTest\assertLogMessage(), FilterUnitTest\assertNoNormalized(), XssTest\assertNormalized(), FilterUnitTest\assertNormalized(), XssTest\assertNotNormalized(), FormBuilder\buttonWasClicked(), WebTestBase\checkForMetaRefresh(), UrlHelper\filterBadProtocol(), DisplayPluginBase\getArgumentsTokens(), Links\getLinks(), EntityAutocompleteMatcher\getMatches(), MailFormatHelper\htmlToText(), DbLogController\overview(), FilterPluginBase\prepareFilterSelectOptions(), FilterCaption\process(), ContextualLinks\render(), PlainTextOutput\renderFromHtml(), OptionsSelectWidget\sanitizeLabel(), HtmlTest\testDecodeEntities(), HtmlTest\testDecodeEntitiesAndEscape(), and SearchPageTextTest\testSearchText().

Here is the caller graph for this function:

static escapeCdataElement ( \DOMNode  $node,
  $comment_start = '//',
  $comment_end = '' 
)
static

Adds comments around a <!CDATA section in a .

::loadHTML() in ::load() makes CDATA sections from the contents of inline script and style tags. This can cause HTML4 browsers to throw exceptions.

This function attempts to solve the problem by creating a to comment the CDATA tag.

Parameters
\DOMNode$nodeThe element potentially containing a CDATA node.
string$comment_start(optional) A string to use as a comment start marker to escape the CDATA declaration. Defaults to '//'.
string$comment_end(optional) A string to use as a comment end marker to escape the CDATA declaration. Defaults to an empty string.
static getClass (   $class)
static

Prepares a string for use as a valid class name.

Do not pass one string containing multiple classes as they will be incorrectly concatenated with dashes, i.e. "one two" will become "one-two".

Parameters
string$classThe class name to clean.
Returns
string The cleaned class name.

References Unicode\strtolower().

Referenced by WidgetBase\form(), BlockContentForm\form(), CommentWidget\formElement(), BlockTest\moveBlockToRegion(), DbLogController\overview(), ContextualLinks\preRenderLinks(), FieldUiTable\preRenderRegionRows(), FormBuilder\retrieveForm(), BlockForm\submitForm(), FieldUiTable\tablePreRender(), BlockUiTest\testBlockPlacementIndicator(), BlockRenderOrderTest\testBlockRenderOrder(), BlockTest\testBlockThemeSelector(), HtmlTest\testHtmlClass(), and BlockContentTypeTest\testsBlockContentAddTypes().

Here is the call graph for this function:

Here is the caller graph for this function:

static getId (   $id)
static

Prepares a string for use as a valid HTML ID.

Only use this function when you want to intentionally skip the uniqueness guarantee of self::getUniqueId().

Parameters
string$idThe ID to clean.
Returns
string The cleaned ID.
See Also
self::getUniqueId()

References Unicode\strtolower().

Referenced by FormBuilder\doBuildForm(), FormBuilder\prepareForm(), Toolbar\preRenderToolbar(), and HtmlTest\testHtmlGetId().

Here is the call graph for this function:

Here is the caller graph for this function:

static getUniqueId (   $id)
static

Prepares a string for use as a valid HTML ID and guarantees uniqueness.

This function ensures that each passed HTML ID value only exists once on the page. By tracking the already returned ids, this function enables forms, blocks, and other content to be output multiple times on the same page, without breaking (X)HTML validation.

For already existing IDs, a counter is appended to the ID string. Therefore, JavaScript and CSS code should not rely on any value that was generated by this function and instead should rely on manually added CSS classes or similarly reliable constructs.

Two consecutive hyphens separate the counter from the original ID. To manage uniqueness across multiple Ajax requests on the same page, Ajax requests POST an array of all IDs currently present on the page, which are used to prime this function's cache upon first invocation.

To allow reverse-parsing of IDs submitted via Ajax, any multiple consecutive hyphens in the originally passed $id are replaced with a single hyphen.

Parameters
string$idThe ID to clean.
Returns
string The cleaned ID.

References Crypt\randomBytesBase64().

Referenced by Table\buildOptionsForm(), DialogRenderer\determineTargetSelector(), FormBuilder\doBuildForm(), WidgetBase\formMultipleElements(), TipPluginText\getAriaId(), ViewUI\getStandardButtons(), DisplayPluginBase\optionLink(), FormBuilder\prepareForm(), ManagedFile\processManagedFile(), BlockTest\testBlockThemeSelector(), ExposedFormTest\testExposedBlock(), HtmlTest\testHtmlGetUniqueId(), and HtmlTest\testHtmlGetUniqueIdWithAjaxIds().

Here is the call graph for this function:

Here is the caller graph for this function:

static load (   $html)
static

Parses an HTML snippet and returns it as a DOM object.

This function loads the body part of a partial (X)HTML document and returns a full object that represents this document.

Use ::serialize() to serialize this back to a string.

Parameters
string$htmlThe partial (X)HTML snippet to load. Invalid markup will be corrected on import.
Returns
A that represents the loaded (X)HTML snippet.

Referenced by FilterHtml\filterAttributes(), Standard\filterXssDataAttributes(), FilterHtml\getHTMLRestrictions(), FilterAlign\process(), FilterCaption\process(), EditorFileReference\process(), PlaceholderGeneratorTest\testCreatePlaceholderGeneratesValidHtmlMarkup(), and RendererPlaceholdersTest\testRenderChildrenPlaceholdersDifferentArguments().

Here is the caller graph for this function:

static normalize (   $html)
static

Normalizes an HTML snippet.

This function is essentially ::normalizeDocument(), but operates on an HTML string instead of a .

Parameters
string$htmlThe HTML string to normalize.
Returns
string The normalized HTML string.

Referenced by FieldFilteredMarkup\create(), MailFormatHelper\htmlToText(), FilterHtmlCorrector\process(), RendererPlaceholdersTest\testCacheableParent(), and FilterUnitTest\testHtmlCorrectorFilter().

Here is the caller graph for this function:

static resetSeenIds ( )
static

Resets the list of seen IDs.

Referenced by ViewUI\addFormToStack(), FormBuilder\processForm(), FormTestBase\tearDown(), BlockViewBuilderTest\testBasicRendering(), and HtmlTest\testHtmlGetUniqueId().

Here is the caller graph for this function:

static serialize ( \DOMDocument  $document)
static

Converts the body of a back to an HTML snippet.

The function serializes the body part of a back to an (X)HTML snippet. The resulting (X)HTML snippet will be properly formatted to be compatible with HTML user agents.

Parameters
\DOMDocument$documentA object to serialize, only the tags below the first <body> node will be converted.
Returns
string A valid (X)HTML snippet, as a string.

Referenced by FilterHtml\filterAttributes(), Standard\filterXssDataAttributes(), FilterAlign\process(), FilterCaption\process(), PlaceholderGeneratorTest\testCreatePlaceholderGeneratesValidHtmlMarkup(), and HtmlTest\testSerialize().

Here is the caller graph for this function:

static setIsAjax (   $is_ajax)
static

Sets if this request is an Ajax request.

Parameters
bool$is_ajaxTRUE if this request is an Ajax request, FALSE otherwise.

Referenced by AjaxResponseSubscriber\onRequest(), HtmlTest\testHtmlGetId(), and HtmlTest\testHtmlGetUniqueIdWithAjaxIds().

Here is the caller graph for this function:


The documentation for this class was generated from the following file: