Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
EditLinkAction.php
1
<?php
2
3
namespace
Bitrix\Landing\History\Action
;
4
5
use
Bitrix\Landing\Block
;
6
use
Bitrix\Landing\Node
;
7
8
class
EditLinkAction
extends
BaseAction
9
{
10
protected
const
JS_COMMAND
=
'editLink'
;
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\Link::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
unset(
70
$params
[
'params'
][
'valueAfter'
],
71
$params
[
'params'
][
'valueBefore'
],
72
$params
[
'params'
][
'position'
],
73
);
74
75
return
$params
;
76
}
77
84
public
static
function
compareParams
(array $oldParams, array $newParams): bool
85
{
86
// todo: or compare just file ids?
87
unset(
88
$oldParams[
'valueBefore'
], $newParams[
'valueBefore'
],
89
);
90
91
return
$oldParams === $newParams;
92
}
93
}
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\EditLinkAction
Definition
EditLinkAction.php:9
Bitrix\Landing\History\Action\EditLinkAction\getJsCommand
getJsCommand(bool $undo=true)
Definition
EditLinkAction.php:59
Bitrix\Landing\History\Action\EditLinkAction\compareParams
static compareParams(array $oldParams, array $newParams)
Definition
EditLinkAction.php:84
Bitrix\Landing\History\Action\EditLinkAction\execute
execute(bool $undo=true)
Definition
EditLinkAction.php:12
Bitrix\Landing\History\Action\EditLinkAction\JS_COMMAND
const JS_COMMAND
Definition
EditLinkAction.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
EditLinkAction.php
Создано системой
1.10.0