Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
EditAttributesAction.php
1<?php
2
4
7
9{
10 protected const JS_COMMAND = 'editAttributes';
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 = $this->params['position'];
17 $attribute = $this->params['attribute'];
18 $value = $undo ? $this->params['valueBefore'] : $this->params['valueAfter'];
19
20 // todo: what if wrapper node?
21 if ($selector && isset($value) && $attribute)
22 {
23 $landingModeBefore = Landing::getEditMode();
25 $block->setAttributes([
26 $selector => [
27 $position => [
28 $attribute => $value,
29 ],
30 ],
31 ]);
32 Landing::setEditMode($landingModeBefore);
33
34 return $block->getError()->isEmpty() && $block->save();
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 'lid' => $block->getLandingId(),
50 'selector' => $params['selector'] ?: '',
51 'position' => $params['position'] ?? -1,
52 'attribute' => $params['attribute'] ?? '',
53 'isWrapper' => $params['isWrapper'] ?? false,
54 'valueBefore' => $params['valueBefore'],
55 'valueAfter' => $params['valueAfter'],
56 ];
57 }
58
59 public function isNeedPush(): bool
60 {
61 return
62 parent::isNeedPush()
63 && $this->params['valueBefore'] !== $this->params['valueAfter'];
64 }
65
70 public function getJsCommand(bool $undo = true): array
71 {
72 $params = parent::getJsCommand($undo);
73
74 $params['params']['value'] =
75 $undo
76 ? $params['params']['valueBefore']
77 : $params['params']['valueAfter'];
78
79 unset(
80 $params['params']['valueAfter'],
81 $params['params']['valueBefore'],
82 );
83
84 return $params;
85 }
86
93 public static function compareParams(array $oldParams, array $newParams): bool
94 {
95 unset($oldParams['valueBefore'], $newParams['valueBefore']);
96
97 return $oldParams === $newParams;
98 }
99}
static compareParams(array $oldParams, array $newParams)
static setEditMode($mode=true)
Definition landing.php:423