Version 1
[yaffs-website] / web / modules / contrib / http2_server_push / src / Asset / AssetHtmlTagRenderElementTrait.php
1 <?php
2
3 namespace Drupal\http2_server_push\Asset;
4
5 trait AssetHtmlTagRenderElementTrait {
6
7   /**
8    * Whether the render element is a <link rel=stylesheet>.
9    *
10    * @param array $element
11    *   A render element.
12    *
13    * @return bool
14    */
15   protected static function isLinkRelStylesheet(array $element) {
16     return
17       (isset($element['#type']) && $element['#type'] === 'html_tag')
18       &&
19       (isset($element['#tag']) && $element['#tag'] === 'link')
20       &&
21       (isset($element['#attributes']) && isset($element['#attributes']['rel']) && $element['#attributes']['rel'] === 'stylesheet');
22   }
23
24   /**
25    * Whether the render element is a <script>.
26    *
27    * @param array $element
28    *   A render element.
29    *
30    * @return bool
31    */
32   protected static function isScript(array $element) {
33     return
34       (isset($element['#type']) && $element['#type'] === 'html_tag')
35       &&
36       (isset($element['#tag']) && $element['#tag'] === 'script');
37   }
38
39   /**
40    * Whether the render element is unconditional.
41    *
42    * An unconditional element is not browser-specific, i.e. is not wrapped in a
43    * conditional comment via the '#browsers' property.
44    *
45    * @see \Drupal\Core\Render\Element\HtmlTag::preRenderConditionalComments
46    *
47    * @param array $element
48    *   A render element.
49    *
50    * @return bool
51    */
52   protected static function isUnconditional(array $element) {
53     return empty($element['#browsers']) || ($element['#browsers']['!IE'] === TRUE && $element['#browsers']['IE'] === TRUE);
54   }
55
56   /**
57    * Whether the given attribute on the render element has a root-relative URL.
58    *
59    * @param array $element
60    *   A render element.
61    *
62    * @return bool
63    */
64   protected static function hasRootRelativeUrl(array $element, $attribute_name) {
65     $attribute_value = $element['#attributes'][$attribute_name];
66     return $attribute_value[0] === '/' && $attribute_value[1] !== '/';
67   }
68
69 }