public static HtmlTag::preRenderHtmlTag($element)
Pre-render callback: Renders a generic HTML tag with attributes into #markup.
Parameters
array $element: An associative array containing:
-
#tag: The tag name to output. Typical tags added to the HTML HEAD:
- meta: To provide meta information, such as a page refresh.
- link: To refer to stylesheets and other contextual information.
- script: To load JavaScript.
The value of #tag is escaped.
- #attributes: (optional) An array of HTML attributes to apply to the tag. The attributes are escaped, see \Drupal\Core\Template\Attribute.
- #value: (optional) A string containing tag content, such as inline CSS. The value of #value will be XSS admin filtered if it is not safe.
- #noscript: (optional) If TRUE, the markup (including any prefix or suffix) will be wrapped in a <noscript> element. (Note that passing any non-empty value here will add the <noscript> tag.)
Return value
array
File
- core/lib/Drupal/Core/Render/Element/HtmlTag.php, line 81
Class
- HtmlTag
- Provides a render element for any HTML tag, with properties and value.
Namespace
Drupal\Core\Render\Element
Code
public static function preRenderHtmlTag($element) { $attributes = isset($element['#attributes']) ? new Attribute($element['#attributes']) : ''; // An HTML tag should not contain any special characters. Escape them to // ensure this cannot be abused. $escaped_tag = HtmlUtility::escape($element['#tag']); $markup = '<' . $escaped_tag . $attributes; // Construct a void element. if (in_array($element['#tag'], self::$voidElements)) { $markup .= " />\n"; } // Construct all other elements. else { $markup .= '>'; $markup .= $element['#value'] instanceof MarkupInterface ? $element['#value'] : Xss::filterAdmin($element['#value']); $markup .= '</' . $escaped_tag . ">\n"; } if (!empty($element['#noscript'])) { $markup = "<noscript>$markup</noscript>"; } $element['#markup'] = Markup::create($markup); return $element; }
Please login to continue.