function Html::serialize
Same name in other branches
- 8.9.x core/lib/Drupal/Component/Utility/Html.php \Drupal\Component\Utility\Html::serialize()
- 10 core/lib/Drupal/Component/Utility/Html.php \Drupal\Component\Utility\Html::serialize()
- 11.x core/lib/Drupal/Component/Utility/Html.php \Drupal\Component\Utility\Html::serialize()
Converts the body of a \DOMDocument back to an HTML snippet.
The function serializes the body part of a \DOMDocument back to an (X)HTML snippet. The resulting (X)HTML snippet will be properly formatted to be compatible with HTML user agents.
Parameters
\DOMDocument $document: A \DOMDocument object to serialize, only the tags below the first <body> node will be converted.
Return value
string A valid (X)HTML snippet, as a string.
13 calls to Html::serialize()
- EditorFileReference::process in core/
modules/ editor/ src/ Plugin/ Filter/ EditorFileReference.php - Performs the filter processing.
- FilterAlign::process in core/
modules/ filter/ src/ Plugin/ Filter/ FilterAlign.php - Performs the filter processing.
- FilterHtml::filterAttributes in core/
modules/ filter/ src/ Plugin/ Filter/ FilterHtml.php - Provides filtering of tag attributes into accepted HTML.
- Html::normalize in core/
lib/ Drupal/ Component/ Utility/ Html.php - Normalizes an HTML snippet.
- Html::transformRootRelativeUrlsToAbsolute in core/
lib/ Drupal/ Component/ Utility/ Html.php - Converts all root-relative URLs to absolute URLs.
File
-
core/
lib/ Drupal/ Component/ Utility/ Html.php, line 308
Class
- Html
- Provides DOMDocument helpers for parsing and serializing HTML strings.
Namespace
Drupal\Component\UtilityCode
public static function serialize(\DOMDocument $document) {
$body_node = $document->getElementsByTagName('body')
->item(0);
$html = '';
if ($body_node !== NULL) {
foreach ($body_node->getElementsByTagName('script') as $node) {
static::escapeCdataElement($node);
}
foreach ($body_node->getElementsByTagName('style') as $node) {
static::escapeCdataElement($node, '/*', '*/');
}
foreach ($body_node->childNodes as $node) {
$html .= $document->saveXML($node);
}
}
return $html;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.