Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
EditIconAction.php
1<?php
2
4
8
10{
11 protected const JS_COMMAND = 'editIcon';
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\Icon::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 {
41 // convert format form getNode to js-command like
42 if (count($params['valueBefore']['classList']) === 1)
43 {
44 $params['valueBefore']['classList'] = explode(' ', $params['valueBefore']['classList'][0]);
45 }
46 if ($params['valueBefore']['data-pseudo-url'])
47 {
48 $params['valueBefore']['url'] = $params['valueBefore']['data-pseudo-url'];
49 unset($params['valueBefore']['data-pseudo-url']);
50 }
51
55 $block = $params['block'];
56
57 return [
58 'block' => $block->getId(),
59 'selector' => $params['selector'] ?: '',
60 'position' => $params['position'] ?: 0,
61 'lid' => $block->getLandingId(),
62 'valueAfter' => $params['valueAfter'] ?: '',
63 'valueBefore' => $params['valueBefore'] ?: '',
64 ];
65 }
66
71 public function getJsCommand(bool $undo = true): array
72 {
73 $params = parent::getJsCommand($undo);
74
75 $params['params']['selector'] .= '@' . $params['params']['position'];
76 $params['params']['value'] =
77 $undo
78 ? $params['params']['valueBefore']
79 : $params['params']['valueAfter'];
80 if (isset($params['params']['value']['url']))
81 {
82 $params['params']['value']['url'] = Json::decode($params['params']['value']['url']);
83 }
84
85 unset(
86 $params['params']['valueAfter'],
87 $params['params']['valueBefore'],
88 $params['params']['position'],
89 );
90
91 return $params;
92 }
93
100 public static function compareParams(array $oldParams, array $newParams): bool
101 {
102 unset($oldParams['valueBefore'], $newParams['valueBefore']);
103
104 return $oldParams === $newParams;
105 }
106}
static compareParams(array $oldParams, array $newParams)