Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
EditAttributesAction.php
1
<?php
2
3
namespace
Bitrix\Landing\History\Action
;
4
5
use
Bitrix\Landing\Block
;
6
use
Bitrix\Landing\Landing
;
7
8
class
EditAttributesAction
extends
BaseAction
9
{
10
protected
const
JS_COMMAND
=
'editAttributes'
;
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 = $this->params[
'position'
];
17
$attribute = $this->params[
'attribute'
];
18
$value = $undo ? $this->params[
'valueBefore'
] : $this->params[
'valueAfter'
];
19
20
// todo: what if wrapper node?
21
if
($selector && isset($value) && $attribute)
22
{
23
$landingModeBefore =
Landing::getEditMode
();
24
Landing::setEditMode
();
25
$block->setAttributes([
26
$selector => [
27
$position => [
28
$attribute => $value,
29
],
30
],
31
]);
32
Landing::setEditMode
($landingModeBefore);
33
34
return
$block->getError()->isEmpty() && $block->save();
35
}
36
37
return
false
;
38
}
39
40
public
static
function
enrichParams
(array
$params
): array
41
{
45
$block =
$params
[
'block'
];
46
47
return
[
48
'block'
=> $block->getId(),
49
'lid'
=> $block->getLandingId(),
50
'selector'
=>
$params
[
'selector'
] ?:
''
,
51
'position'
=>
$params
[
'position'
] ?? -1,
52
'attribute'
=>
$params
[
'attribute'
] ??
''
,
53
'isWrapper'
=>
$params
[
'isWrapper'
] ??
false
,
54
'valueBefore'
=>
$params
[
'valueBefore'
],
55
'valueAfter'
=>
$params
[
'valueAfter'
],
56
];
57
}
58
59
public
function
isNeedPush
(): bool
60
{
61
return
62
parent::isNeedPush()
63
&& $this->params[
'valueBefore'
] !== $this->params[
'valueAfter'
];
64
}
65
70
public
function
getJsCommand
(
bool
$undo =
true
): array
71
{
72
$params
= parent::getJsCommand($undo);
73
74
$params
[
'params'
][
'value'
] =
75
$undo
76
?
$params
[
'params'
][
'valueBefore'
]
77
:
$params
[
'params'
][
'valueAfter'
];
78
79
unset(
80
$params
[
'params'
][
'valueAfter'
],
81
$params
[
'params'
][
'valueBefore'
],
82
);
83
84
return
$params
;
85
}
86
93
public
static
function
compareParams
(array $oldParams, array $newParams): bool
94
{
95
unset($oldParams[
'valueBefore'
], $newParams[
'valueBefore'
]);
96
97
return
$oldParams === $newParams;
98
}
99
}
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\EditAttributesAction
Definition
EditAttributesAction.php:9
Bitrix\Landing\History\Action\EditAttributesAction\getJsCommand
getJsCommand(bool $undo=true)
Definition
EditAttributesAction.php:70
Bitrix\Landing\History\Action\EditAttributesAction\isNeedPush
isNeedPush()
Definition
EditAttributesAction.php:59
Bitrix\Landing\History\Action\EditAttributesAction\compareParams
static compareParams(array $oldParams, array $newParams)
Definition
EditAttributesAction.php:93
Bitrix\Landing\History\Action\EditAttributesAction\execute
execute(bool $undo=true)
Definition
EditAttributesAction.php:12
Bitrix\Landing\History\Action\EditAttributesAction\JS_COMMAND
const JS_COMMAND
Definition
EditAttributesAction.php:10
Bitrix\Landing\Landing\getEditMode
static getEditMode()
Definition
landing.php:432
Bitrix\Landing\Landing\setEditMode
static setEditMode($mode=true)
Definition
landing.php:423
Bitrix\Landing\Block
Definition
cache.php:2
Bitrix\Landing\History\Action
Definition
AddBlockAction.php:3
Bitrix\Landing\Landing
Definition
cache.php:2
modules
landing
lib
History
Action
EditAttributesAction.php
Создано системой
1.10.0