Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
AddBlockAction.php
1<?php
2
4
7
9{
10 protected const JS_COMMAND = 'addBlock';
11
12 public function execute(bool $undo = true): bool
13 {
14 $blockId = (int)$this->params['block'];
15 $landing = Landing::createInstance($this->params['lid']);
16 if (
17 $landing->exist()
18 && $landing->markDeletedBlock($blockId, false)
19 )
20 {
21 foreach ($landing->getBlocks() as $id => $block)
22 {
23 if ($id === $blockId)
24 {
25 $block->setSort($block->getSort() - 1);
26 break;
27 }
28 }
29
30 $landing->resortBlocks();
31
32 return true;
33 }
34
35 return false;
36 }
37
38 public static function enrichParams(array $params): array
39 {
43 $block = $params['block'];
44 $blockSort = $block->getSort();
45 $code = $block->getCode();
46 $landing = Landing::createInstance($block->getLandingId());
47 $previousId = 0;
48 $previousSort = 0;
49 foreach ($landing->getBlocks() as $bid => $b)
50 {
51 $currentSort = $b->getSort();
52 if ($currentSort >= $previousSort && $currentSort < $blockSort)
53 {
54 $previousSort = $currentSort;
55 $previousId = $bid;
56 }
57 }
58
59 return [
60 'block' => $block->getId(),
61 'selector' => '#' . Block::getAnchor($block->getId()),
62 'lid' => $block->getLandingId(),
63 'code' => $code,
64 'currentBlock' => $previousId,
65 'insertBefore' => false,
66 ];
67 }
68}
static createInstance($id, array $params=array())
Definition landing.php:534