You are here

trait AssetHtmlTagRenderElementTrait in HTTP/2 Server Push 8

Hierarchy

File

src/Asset/AssetHtmlTagRenderElementTrait.php, line 5

Namespace

Drupal\http2_server_push\Asset
View source
trait AssetHtmlTagRenderElementTrait {

  /**
   * Whether the render element is a <link rel=stylesheet>.
   *
   * @param array $element
   *   A render element.
   *
   * @return bool
   */
  protected static function isLinkRelStylesheet(array $element) {
    return isset($element['#type']) && $element['#type'] === 'html_tag' && (isset($element['#tag']) && $element['#tag'] === 'link') && (isset($element['#attributes']) && isset($element['#attributes']['rel']) && $element['#attributes']['rel'] === 'stylesheet');
  }

  /**
   * Whether the render element is a <script>.
   *
   * @param array $element
   *   A render element.
   *
   * @return bool
   */
  protected static function isScript(array $element) {
    return isset($element['#type']) && $element['#type'] === 'html_tag' && (isset($element['#tag']) && $element['#tag'] === 'script');
  }

  /**
   * Whether the render element is unconditional.
   *
   * An unconditional element is not browser-specific, i.e. is not wrapped in a
   * conditional comment via the '#browsers' property.
   *
   * @param array $element
   *   A render element.
   *
   * @return bool
   *
   * @see \Drupal\Core\Render\Element\HtmlTag::preRenderConditionalComments
   */
  protected static function isUnconditional(array $element) {
    return empty($element['#browsers']) || $element['#browsers']['!IE'] === TRUE && $element['#browsers']['IE'] === TRUE;
  }

  /**
   * Whether the given attribute on the render element has a root-relative URL.
   *
   * @param array $element
   *   A render element.
   * @param string $attribute_name
   *   The name of an attribute.
   *
   * @return bool
   */
  protected static function hasRootRelativeUrl(array $element, $attribute_name) {
    $attribute_value = $element['#attributes'][$attribute_name];
    return $attribute_value[0] === '/' && $attribute_value[1] !== '/';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AssetHtmlTagRenderElementTrait::hasRootRelativeUrl protected static function Whether the given attribute on the render element has a root-relative URL.
AssetHtmlTagRenderElementTrait::isLinkRelStylesheet protected static function Whether the render element is a <link rel=stylesheet>.
AssetHtmlTagRenderElementTrait::isScript protected static function Whether the render element is a <script>.
AssetHtmlTagRenderElementTrait::isUnconditional protected static function Whether the render element is unconditional.