Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
UpdateContentAction.php
1<?php
2
4
6
8{
9 protected const JS_COMMAND = 'updateContent';
10
11 public function execute(bool $undo = true): bool
12 {
13 $block = new Block((int)$this->params['block']);
14 if ($block->exist())
15 {
16 $content = $undo ? $this->params['contentBefore'] : $this->params['contentAfter'];
17 $block->saveContent($content, $this->params['designed']);
18
19 return $block->save();
20 }
21
22 return false;
23 }
24
25 public static function enrichParams(array $params): array
26 {
27 return [
28 'block' => $params['block'],
29 'lid' => $params['contentAfter'],
30 'contentAfter' => $params['contentAfter'] ?: '',
31 'contentBefore' => $params['contentBefore'] ?: '',
32 'designed' => (bool)$params['designed'],
33 ];
34 }
35
36 public function isNeedPush(): bool
37 {
38 return
39 parent::isNeedPush()
40 && $this->params['contentBefore'] !== $this->params['contentAfter'];
41 }
42
47 public function getJsCommand(bool $undo = true): array
48 {
49 $params = parent::getJsCommand($undo);
50
51 $params['params']['content'] =
52 $undo
53 ? $params['params']['contentBefore']
54 : $params['params']['contentAfter']
55 ;
56
57 unset(
58 $params['params']['contentAfter'],
59 $params['params']['contentBefore'],
60 $params['params']['designed'],
61 );
62
63 return $params;
64 }
65}