Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
EditMapAction.php
1<?php
2
4
9
11{
12 protected const JS_COMMAND = 'editMap';
13
14 public function execute(bool $undo = true): bool
15 {
16 $block = new Block((int)$this->params['block']);
17 $selector = $this->params['selector'] ?: '';
18 $position = (int)($this->params['position'] ?: 0);
19 $value = $undo ? $this->params['valueBefore'] : $this->params['valueAfter'];
20
21 if ($selector)
22 {
23 $doc = $block->getDom();
24 $resultList = $doc->querySelectorAll($selector);
25 if (isset($resultList[$position]))
26 {
27 Node\Map::saveNode($block, $selector, [
28 $position => $value
29 ]);
30
31 $block->saveContent($doc->saveHTML());
32
33 return $block->save();
34 }
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 'selector' => $params['selector'] ?: '',
50 'position' => $params['position'] ?: 0,
51 'lid' => $block->getLandingId(),
52 'valueAfter' => $params['valueAfter'] ?: '',
53 'valueBefore' => $params['valueBefore'] ?: '',
54 ];
55 }
56
61 public function getJsCommand(bool $undo = true): array
62 {
63 $params = parent::getJsCommand($undo);
64
65 $params['params']['selector'] .= '@' . $params['params']['position'];
66 $params['params']['value'] =
67 $undo
68 ? $params['params']['valueBefore']
69 : $params['params']['valueAfter']
70 ;
71 $params['params']['value'] = Encoding::convertEncoding($params['params']['value'], SITE_CHARSET, 'UTF-8');
72 $params['params']['value'] = Json::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)