Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
EditImgAction.php
1<?php
2
4
8
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}
static compareParams(array $oldParams, array $newParams)