Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
EditIconAction.php
1
<?php
2
3
namespace
Bitrix\Landing\History\Action
;
4
5
use
Bitrix\Landing\Block
;
6
use
Bitrix\Landing\Node
;
7
use
Bitrix\Main\Web\Json
;
8
9
class
EditIconAction
extends
BaseAction
10
{
11
protected
const
JS_COMMAND
=
'editIcon'
;
12
13
public
function
execute
(
bool
$undo =
true
): bool
14
{
15
$block =
new
Block
((
int
)$this->params[
'block'
]);
16
$selector = $this->params[
'selector'
] ?:
''
;
17
$position = (int)($this->params[
'position'
] ?: 0);
18
$value = $undo ? $this->params[
'valueBefore'
] : $this->params[
'valueAfter'
];
19
20
if
($selector)
21
{
22
$doc = $block->getDom();
23
$resultList = $doc->querySelectorAll($selector);
24
if
(isset($resultList[$position]))
25
{
26
Node\Icon::saveNode($block, $selector, [
27
$position => $value,
28
]);
29
30
$block->saveContent($doc->saveHTML());
31
32
return
$block->save();
33
}
34
}
35
36
return
false
;
37
}
38
39
public
static
function
enrichParams
(array
$params
): array
40
{
41
// convert format form getNode to js-command like
42
if
(count(
$params
[
'valueBefore'
][
'classList'
]) === 1)
43
{
44
$params
[
'valueBefore'
][
'classList'
] = explode(
' '
,
$params
[
'valueBefore'
][
'classList'
][0]);
45
}
46
if
(
$params
[
'valueBefore'
][
'data-pseudo-url'
])
47
{
48
$params
[
'valueBefore'
][
'url'
] =
$params
[
'valueBefore'
][
'data-pseudo-url'
];
49
unset(
$params
[
'valueBefore'
][
'data-pseudo-url'
]);
50
}
51
55
$block =
$params
[
'block'
];
56
57
return
[
58
'block'
=> $block->getId(),
59
'selector'
=>
$params
[
'selector'
] ?:
''
,
60
'position'
=>
$params
[
'position'
] ?: 0,
61
'lid'
=> $block->getLandingId(),
62
'valueAfter'
=>
$params
[
'valueAfter'
] ?:
''
,
63
'valueBefore'
=>
$params
[
'valueBefore'
] ?:
''
,
64
];
65
}
66
71
public
function
getJsCommand
(
bool
$undo =
true
): array
72
{
73
$params
= parent::getJsCommand($undo);
74
75
$params
[
'params'
][
'selector'
] .=
'@'
.
$params
[
'params'
][
'position'
];
76
$params
[
'params'
][
'value'
] =
77
$undo
78
?
$params
[
'params'
][
'valueBefore'
]
79
:
$params
[
'params'
][
'valueAfter'
];
80
if
(isset(
$params
[
'params'
][
'value'
][
'url'
]))
81
{
82
$params
[
'params'
][
'value'
][
'url'
] = Json::decode(
$params
[
'params'
][
'value'
][
'url'
]);
83
}
84
85
unset(
86
$params
[
'params'
][
'valueAfter'
],
87
$params
[
'params'
][
'valueBefore'
],
88
$params
[
'params'
][
'position'
],
89
);
90
91
return
$params
;
92
}
93
100
public
static
function
compareParams
(array $oldParams, array $newParams): bool
101
{
102
unset($oldParams[
'valueBefore'
], $newParams[
'valueBefore'
]);
103
104
return
$oldParams === $newParams;
105
}
106
}
Bitrix\Landing\Block
Definition
block.php:21
Bitrix\Landing\History\Action\BaseAction
Definition
BaseAction.php:5
Bitrix\Landing\History\Action\BaseAction\$params
array $params
Definition
BaseAction.php:7
Bitrix\Landing\History\Action\BaseAction\enrichParams
static enrichParams(array $params)
Bitrix\Landing\History\Action\EditIconAction
Definition
EditIconAction.php:10
Bitrix\Landing\History\Action\EditIconAction\getJsCommand
getJsCommand(bool $undo=true)
Definition
EditIconAction.php:71
Bitrix\Landing\History\Action\EditIconAction\compareParams
static compareParams(array $oldParams, array $newParams)
Definition
EditIconAction.php:100
Bitrix\Landing\History\Action\EditIconAction\execute
execute(bool $undo=true)
Definition
EditIconAction.php:13
Bitrix\Landing\History\Action\EditIconAction\JS_COMMAND
const JS_COMMAND
Definition
EditIconAction.php:11
Bitrix\Main\Web\Json
Definition
json.php:11
Bitrix\Landing\Block
Definition
cache.php:2
Bitrix\Landing\History\Action
Definition
AddBlockAction.php:3
Bitrix\Landing\Node
Definition
component.php:2
modules
landing
lib
History
Action
EditIconAction.php
Создано системой
1.10.0