1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
speed.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Landing\Hook\Page;
4
5
use \Bitrix\Landing\Assets;
6
use \Bitrix\Landing\Field;
7
use \Bitrix\Landing\Help;
8
use \Bitrix\Landing\Landing;
9
use \Bitrix\Main\Localization\Loc;
10
11
Loc::loadMessages(__FILE__);
12
13
class
Speed
extends
\Bitrix\Landing\Hook\Page
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
}
Bitrix\Landing\Assets\Location\LOCATION_BEFORE_ALL
const LOCATION_BEFORE_ALL
Определения
location.php:7
Bitrix\Landing\Assets\Manager\getInstance
static getInstance()
Определения
manager.php:59
Bitrix\Landing\Field\Checkbox
Определения
checkbox.php:5
Bitrix\Landing\Field\Text
Определения
text.php:5
Bitrix\Landing\Help\getHelpUrl
static getHelpUrl(string $code)
Определения
help.php:174
Bitrix\Landing\Hook\Page\Speed
Определения
speed.php:14
Bitrix\Landing\Hook\Page\Speed\execLazyLoad
execLazyLoad()
Определения
speed.php:142
Bitrix\Landing\Hook\Page\Speed\disableWebpack
disableWebpack()
Определения
speed.php:123
Bitrix\Landing\Hook\Page\Speed\$isNeedPublication
$isNeedPublication
Определения
speed.php:17
Bitrix\Landing\Hook\Page\Speed\getMap
getMap()
Определения
speed.php:23
Bitrix\Landing\Hook\Page\Speed\getTitle
getTitle()
Определения
speed.php:55
Bitrix\Landing\Hook\Page\Speed\enabled
enabled()
Определения
speed.php:91
Bitrix\Landing\Hook\Page\Speed\exec
exec()
Определения
speed.php:110
Bitrix\Landing\Hook\Page\Speed\execWebpack
execWebpack()
Определения
speed.php:129
Bitrix\Landing\Hook\Page\Speed\LAZYLOAD_EXTENSION_NAME
const LAZYLOAD_EXTENSION_NAME
Определения
speed.php:15
Bitrix\Landing\Hook\Page\Speed\addData
addData($field, $data)
Определения
speed.php:66
Bitrix\Landing\Hook\Page\isPage
isPage()
Определения
page.php:66
Bitrix\Landing\Hook\Page\issetCustomExec
issetCustomExec()
Определения
page.php:253
$data
$data['IS_AVAILABLE']
Определения
.description.php:13
Bitrix\Landing\Assets
Определения
builder.php:3
Bitrix\Landing\Hook\Page
Определения
b24button.php:2
bitrix
modules
landing
lib
hook
page
speed.php
Создано системой
1.14.0