Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
EditTextAction.php
1
<?php
2
3
namespace
Bitrix\Landing\History\Action
;
4
5
use
Bitrix\Landing\Block
;
6
use
Bitrix\Main\Text\Emoji
;
7
8
class
EditTextAction
extends
BaseAction
9
{
10
protected
const
JS_COMMAND
=
'editText'
;
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
18
if
($selector)
19
{
20
$doc = $block->getDom();
21
$resultList = $doc->querySelectorAll($selector);
22
if
(isset($resultList[$position]))
23
{
24
$content = $undo ? $this->params[
'valueBefore'
] : $this->params[
'valueAfter'
];
25
$content =
Emoji::decode
($content);
26
$resultList[$position]->setInnerHTML($content);
27
$block->saveContent($doc->saveHTML());
28
29
return
$block->save();
30
}
31
}
32
33
return
false
;
34
}
35
36
public
static
function
enrichParams
(array
$params
): array
37
{
41
$block =
$params
[
'block'
];
42
43
$valueBefore =
$params
[
'valueBefore'
] ?:
''
;
44
$valueBefore =
Emoji::encode
($valueBefore);
45
$valueAfter =
$params
[
'valueAfter'
] ?:
''
;
46
$valueAfter =
Emoji::encode
($valueAfter);
47
48
return
[
49
'block'
=> $block->getId(),
50
'selector'
=>
$params
[
'selector'
] ?:
''
,
51
'position'
=>
$params
[
'position'
] ?: 0,
52
'lid'
=> $block->getLandingId(),
53
'valueAfter'
=> $valueAfter,
54
'valueBefore'
=> $valueBefore,
55
];
56
}
57
62
public
function
getJsCommand
(
bool
$undo =
true
): array
63
{
64
$params
= parent::getJsCommand($undo);
65
66
$params
[
'params'
][
'selector'
] .=
'@'
.
$params
[
'params'
][
'position'
];
67
$params
[
'params'
][
'value'
] =
68
$undo
69
?
$params
[
'params'
][
'valueBefore'
]
70
:
$params
[
'params'
][
'valueAfter'
]
71
;
72
$params
[
'params'
][
'value'
] =
Emoji::decode
(
$params
[
'params'
][
'value'
]);
73
74
unset(
75
$params
[
'params'
][
'valueAfter'
],
76
$params
[
'params'
][
'valueBefore'
],
77
$params
[
'params'
][
'position'
],
78
);
79
80
return
$params
;
81
}
82
89
public
static
function
compareParams
(array $oldParams, array $newParams): bool
90
{
91
unset($oldParams[
'valueBefore'
], $newParams[
'valueBefore'
]);
92
93
return
$oldParams === $newParams;
94
}
95
}
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\EditTextAction
Definition
EditTextAction.php:9
Bitrix\Landing\History\Action\EditTextAction\getJsCommand
getJsCommand(bool $undo=true)
Definition
EditTextAction.php:62
Bitrix\Landing\History\Action\EditTextAction\compareParams
static compareParams(array $oldParams, array $newParams)
Definition
EditTextAction.php:89
Bitrix\Landing\History\Action\EditTextAction\execute
execute(bool $undo=true)
Definition
EditTextAction.php:12
Bitrix\Landing\History\Action\EditTextAction\JS_COMMAND
const JS_COMMAND
Definition
EditTextAction.php:10
Bitrix\Main\Text\Emoji
Definition
emoji.php:10
Bitrix\Main\Text\Emoji\encode
static encode($text)
Definition
emoji.php:17
Bitrix\Main\Text\Emoji\decode
static decode($text)
Definition
emoji.php:24
Bitrix\Landing\Block
Definition
cache.php:2
Bitrix\Landing\History\Action
Definition
AddBlockAction.php:3
modules
landing
lib
History
Action
EditTextAction.php
Создано системой
1.10.0