Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
htmlcontent.php
1<?php
3
6use Bitrix\Main\Page\Asset;
9
13class HtmlContent extends AjaxJson
14{
15 private $jsPathList = [];
16 private $cssPathList = [];
17
24 public function __construct(ContentAreaInterface $content, $status = self::STATUS_SUCCESS, ErrorCollection $errorCollection = null, array $additionalResponseParams = [])
25 {
26 $html = $content->getHtml();
27
28 $this->collectAssetsPathList();
29
30 $result = [
31 'html' => $html,
32 'assets' => [
33 'css' => $this->getCssList(),
34 'js' => $this->getJsList(),
35 'string' => $this->getStringList()
36 ],
37 'additionalParams' => $additionalResponseParams,
38 ];
39 if($content instanceof DataSectionInterface)
40 {
41 $result[$content->getSectionName()] = $content->getSectionData();
42 }
43
44 parent::__construct($result, $status, $errorCollection);
45
46 $this->addHeader('X-Process-Assets', 'assets');
47 }
48
49 final protected function collectAssetsPathList()
50 {
51 Asset::getInstance()->getCss();
52 Asset::getInstance()->getJs();
53 Asset::getInstance()->getStrings();
54
55 $this->jsPathList = Asset::getInstance()->getTargetList('JS');
56 $this->cssPathList = Asset::getInstance()->getTargetList('CSS');
57 }
58
62 final protected function getJsList()
63 {
64 $jsList = [];
65 foreach($this->jsPathList as $targetAsset)
66 {
67 $assetInfo = Asset::getInstance()->getAssetInfo($targetAsset['NAME'], AssetMode::ALL);
68 if (!empty($assetInfo['JS']))
69 {
70 $jsList = array_merge($jsList, $assetInfo['JS']);
71 }
72 }
73
74 return $jsList;
75 }
76
80 final protected function getCssList()
81 {
82 $cssList = [];
83 foreach ($this->cssPathList as $targetAsset)
84 {
85 $assetInfo = Asset::getInstance()->getAssetInfo($targetAsset['NAME'], AssetMode::ALL);
86 if (!empty($assetInfo['CSS']))
87 {
88 $cssList = array_merge($cssList, $assetInfo['CSS']);
89 }
90 }
91
92 return $cssList;
93 }
94
98 final protected function getStringList()
99 {
100 $stringList = [];
101 foreach($this->cssPathList as $targetAsset)
102 {
103 $assetInfo = Asset::getInstance()->getAssetInfo($targetAsset['NAME'], AssetMode::ALL);
104 if (!empty($assetInfo['STRINGS']))
105 {
106 $stringList = array_merge($stringList, $assetInfo['STRINGS']);
107 }
108 }
109
110 foreach($this->jsPathList as $targetAsset)
111 {
112 $assetInfo = Asset::getInstance()->getAssetInfo($targetAsset['NAME'], AssetMode::ALL);
113 if (!empty($assetInfo['STRINGS']))
114 {
115 $stringList = array_merge($stringList, $assetInfo['STRINGS']);
116 }
117 }
118
119 $stringList[] = Asset::getInstance()->showFilesList();
120
121 return $stringList;
122 }
123}
__construct(ContentAreaInterface $content, $status=self::STATUS_SUCCESS, ErrorCollection $errorCollection=null, array $additionalResponseParams=[])
addHeader($name, $value='')