Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
EditLinkAction.php
1<?php
2
4
7
9{
10 protected const JS_COMMAND = 'editLink';
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 $value = $undo ? $this->params['valueBefore'] : $this->params['valueAfter'];
18
19 if ($selector)
20 {
21 $doc = $block->getDom();
22 $resultList = $doc->querySelectorAll($selector);
23 if (isset($resultList[$position]))
24 {
25 Node\Link::saveNode($block, $selector, [
26 $position => $value,
27 ]);
28
29 $block->saveContent($doc->saveHTML());
30
31 return $block->save();
32 }
33 }
34
35 return false;
36 }
37
38 public static function enrichParams(array $params): array
39 {
43 $block = $params['block'];
44
45 return [
46 'block' => $block->getId(),
47 'selector' => $params['selector'] ?: '',
48 'position' => $params['position'] ?: 0,
49 'lid' => $block->getLandingId(),
50 'valueAfter' => $params['valueAfter'] ?: '',
51 'valueBefore' => $params['valueBefore'] ?: '',
52 ];
53 }
54
59 public function getJsCommand(bool $undo = true): array
60 {
61 $params = parent::getJsCommand($undo);
62
63 $params['params']['selector'] .= '@' . $params['params']['position'];
64 $params['params']['value'] =
65 $undo
66 ? $params['params']['valueBefore']
67 : $params['params']['valueAfter'];
68
69 unset(
70 $params['params']['valueAfter'],
71 $params['params']['valueBefore'],
72 $params['params']['position'],
73 );
74
75 return $params;
76 }
77
84 public static function compareParams(array $oldParams, array $newParams): bool
85 {
86 // todo: or compare just file ids?
87 unset(
88 $oldParams['valueBefore'], $newParams['valueBefore'],
89 );
90
91 return $oldParams === $newParams;
92 }
93}