Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
EditEmbedAction.php
1<?php
2
4
7
9{
10 protected const JS_COMMAND = 'editEmbed';
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\Embed::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
70 unset(
71 $params['params']['valueAfter'],
72 $params['params']['valueBefore'],
73 $params['params']['position'],
74 );
75
76 return $params;
77 }
78
85 public static function compareParams(array $oldParams, array $newParams): bool
86 {
87 unset($oldParams['valueBefore'], $newParams['valueBefore']);
88
89 return $oldParams === $newParams;
90 }
91}
static compareParams(array $oldParams, array $newParams)