Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
EditTextAction.php
1<?php
2
4
7
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}
static compareParams(array $oldParams, array $newParams)
static encode($text)
Definition emoji.php:17
static decode($text)
Definition emoji.php:24