Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
EditEmbedAction.php
1
<?php
2
3
namespace
Bitrix\Landing\History\Action
;
4
5
use
Bitrix\Landing\Block
;
6
use
Bitrix\Landing\Node
;
7
8
class
EditEmbedAction
extends
BaseAction
9
{
10
protected
const
JS_COMMAND
=
'editEmbed'
;
11
12
public
function
execute
(
bool
$undo =
true
): bool
13
{
14
$block =
new
Block
((
int
)$this->params[
'block'
]);
15
$selector = $this->params[
'selector'
] ?:
''
;
16
$position = (int)($this->params[
'position'
] ?: 0);
17
$value = $undo ? $this->params[
'valueBefore'
] : $this->params[
'valueAfter'
];
18
19
if
($selector)
20
{
21
$doc = $block->getDom();
22
$resultList = $doc->querySelectorAll($selector);
23
if
(isset($resultList[$position]))
24
{
25
Node\Embed::saveNode($block, $selector, [
26
$position => $value
27
]);
28
29
$block->saveContent($doc->saveHTML());
30
31
return
$block->save();
32
}
33
}
34
35
return
false
;
36
}
37
38
public
static
function
enrichParams
(array
$params
): array
39
{
43
$block =
$params
[
'block'
];
44
45
return
[
46
'block'
=> $block->getId(),
47
'selector'
=>
$params
[
'selector'
] ?:
''
,
48
'position'
=>
$params
[
'position'
] ?: 0,
49
'lid'
=> $block->getLandingId(),
50
'valueAfter'
=>
$params
[
'valueAfter'
] ?:
''
,
51
'valueBefore'
=>
$params
[
'valueBefore'
] ?:
''
,
52
];
53
}
54
59
public
function
getJsCommand
(
bool
$undo =
true
): array
60
{
61
$params
= parent::getJsCommand($undo);
62
63
$params
[
'params'
][
'selector'
] .=
'@'
.
$params
[
'params'
][
'position'
];
64
$params
[
'params'
][
'value'
] =
65
$undo
66
?
$params
[
'params'
][
'valueBefore'
]
67
:
$params
[
'params'
][
'valueAfter'
]
68
;
69
70
unset(
71
$params
[
'params'
][
'valueAfter'
],
72
$params
[
'params'
][
'valueBefore'
],
73
$params
[
'params'
][
'position'
],
74
);
75
76
return
$params
;
77
}
78
85
public
static
function
compareParams
(array $oldParams, array $newParams): bool
86
{
87
unset($oldParams[
'valueBefore'
], $newParams[
'valueBefore'
]);
88
89
return
$oldParams === $newParams;
90
}
91
}
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\EditEmbedAction
Definition
EditEmbedAction.php:9
Bitrix\Landing\History\Action\EditEmbedAction\getJsCommand
getJsCommand(bool $undo=true)
Definition
EditEmbedAction.php:59
Bitrix\Landing\History\Action\EditEmbedAction\compareParams
static compareParams(array $oldParams, array $newParams)
Definition
EditEmbedAction.php:85
Bitrix\Landing\History\Action\EditEmbedAction\execute
execute(bool $undo=true)
Definition
EditEmbedAction.php:12
Bitrix\Landing\History\Action\EditEmbedAction\JS_COMMAND
const JS_COMMAND
Definition
EditEmbedAction.php:10
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
EditEmbedAction.php
Создано системой
1.10.0