Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
EditImgAction.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
EditImgAction
extends
BaseAction
10
{
11
protected
const
JS_COMMAND
=
'editImage'
;
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\Img::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
{
44
$block =
$params
[
'block'
];
45
46
unset(
$params
[
'valueAfter'
][
'type'
]);
47
if
(!
$params
[
'src2x'
])
48
{
49
unset(
$params
[
'src2x'
]);
50
}
51
if
(!
$params
[
'src2x'
])
52
{
53
unset(
$params
[
'src2x'
]);
54
}
55
56
return
[
57
'block'
=> $block->getId(),
58
'selector'
=>
$params
[
'selector'
] ?:
''
,
59
'position'
=>
$params
[
'position'
] ?: 0,
60
'lid'
=> $block->getLandingId(),
61
'valueAfter'
=>
$params
[
'valueAfter'
] ?:
''
,
62
'valueBefore'
=>
$params
[
'valueBefore'
] ?:
''
,
63
];
64
}
65
66
public
function
isNeedPush
(): bool
67
{
68
return
69
parent::isNeedPush()
70
&& $this->params[
'valueBefore'
] !== $this->params[
'valueAfter'
];
71
}
72
77
public
function
getJsCommand
(
bool
$undo =
true
): array
78
{
79
$params
= parent::getJsCommand($undo);
80
81
$params
[
'params'
][
'selector'
] .=
'@'
.
$params
[
'params'
][
'position'
];
82
$params
[
'params'
][
'value'
] =
83
$undo
84
?
$params
[
'params'
][
'valueBefore'
]
85
:
$params
[
'params'
][
'valueAfter'
]
86
;
87
if
(isset(
$params
[
'params'
][
'value'
][
'url'
]))
88
{
89
$params
[
'params'
][
'value'
][
'url'
] = Json::decode(
$params
[
'params'
][
'value'
][
'url'
]);
90
}
91
92
unset(
93
$params
[
'params'
][
'valueAfter'
],
94
$params
[
'params'
][
'valueBefore'
],
95
$params
[
'params'
][
'position'
],
96
);
97
98
return
$params
;
99
}
100
107
public
static
function
compareParams
(array $oldParams, array $newParams): bool
108
{
109
// todo: or compare just file ids?
110
unset(
111
$oldParams[
'valueBefore'
], $newParams[
'valueBefore'
],
112
$oldParams[
'type'
], $newParams[
'type'
]
113
);
114
115
return
$oldParams === $newParams;
116
}
117
}
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\EditImgAction
Definition
EditImgAction.php:10
Bitrix\Landing\History\Action\EditImgAction\getJsCommand
getJsCommand(bool $undo=true)
Definition
EditImgAction.php:77
Bitrix\Landing\History\Action\EditImgAction\isNeedPush
isNeedPush()
Definition
EditImgAction.php:66
Bitrix\Landing\History\Action\EditImgAction\compareParams
static compareParams(array $oldParams, array $newParams)
Definition
EditImgAction.php:107
Bitrix\Landing\History\Action\EditImgAction\execute
execute(bool $undo=true)
Definition
EditImgAction.php:13
Bitrix\Landing\History\Action\EditImgAction\JS_COMMAND
const JS_COMMAND
Definition
EditImgAction.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
EditImgAction.php
Создано системой
1.10.0