Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
speed.php
1<?php
2
4
5use \Bitrix\Landing\Assets;
6use \Bitrix\Landing\Field;
7use \Bitrix\Landing\Help;
8use \Bitrix\Landing\Landing;
9use \Bitrix\Main\Localization\Loc;
10
11Loc::loadMessages(__FILE__);
12
14{
15 const LAZYLOAD_EXTENSION_NAME = 'landing_lazyload';
16
17 protected $isNeedPublication = true;
18
23 protected function getMap()
24 {
25 $helpUrl = Help::getHelpUrl('SPEED');
26
27 return [
28 'ASSETS' => new Field\Text('ASSETS', []),
29 'USE_LAZY' => new Field\Checkbox(
30 'USE_LAZY',
31 [
32 'title' => Loc::getMessage('LANDING_HOOK_SPEED_USE_LAZY_NEW'),
33 'help' => $helpUrl
34 ? '<a href="' . $helpUrl . '" target="_blank">' .
35 Loc::getMessage('LANDING_HOOK_SPEED_HELP') .
36 '</a>'
37 : '',
38 ]
39 ),
40 'USE_WEBPACK' => new Field\Checkbox(
41 'USE_WEBPACK',
42 [
43 'title' => ($mess = Loc::getMessage('LANDING_HOOK_SPEED_USE_WEBPACK2'))
44 ? $mess
45 : Loc::getMessage('LANDING_HOOK_SPEED_USE_WEBPACK'),
46 ]
47 ),
48 ];
49 }
50
55 public function getTitle()
56 {
57 return Loc::getMessage('LANDING_HOOK_SPEED_TTILE');
58 }
59
66 public function addData($field, $data)
67 {
68 if (!is_array($data))
69 {
70 $data = [$data];
71 }
72 if (
73 $this->fields[$field]
74 && ($hookData = $this->fields[$field]->getValue())
75 )
76 {
77 $mergedData = array_unique(array_merge(unserialize($hookData, ['allowed_classes' => false]), $data));
78 }
79 else
80 {
81 $mergedData = $data;
82 }
83
84 return serialize($mergedData);
85 }
86
91 public function enabled()
92 {
93 if ($this->issetCustomExec())
94 {
95 return true;
96 }
97
98 if ($this->isPage())
99 {
100 return false;
101 }
102
103 return true;
104 }
105
110 public function exec(): void
111 {
112 if (Landing::getEditMode())
113 {
114 $this->disableWebpack();
115 }
116 else
117 {
118 $this->execWebpack();
119 $this->execLazyLoad();
120 }
121 }
122
123 protected function disableWebpack(): void
124 {
125 $assets = Assets\Manager::getInstance();
126 $assets->setStandartMode();
127 }
128
129 protected function execWebpack(): void
130 {
131 $assets = Assets\Manager::getInstance();
132 if ($this->fields['USE_WEBPACK']->getValue() !== 'N')
133 {
134 $assets->setWebpackMode();
135 }
136 else
137 {
138 $assets->setStandartMode();
139 }
140 }
141
142 protected function execLazyLoad(): void
143 {
144 if ($this->fields['USE_LAZY']->getValue() !== 'N')
145 {
146 $assets = Assets\Manager::getInstance();
147 $assets->addAsset(self::LAZYLOAD_EXTENSION_NAME, Assets\Location::LOCATION_BEFORE_ALL);
148 }
149 }
150}
static getHelpUrl(string $code)
Definition help.php:268
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29