Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
toolbar.php
1<?
3
8use \Bitrix\Main\SidePanel;
9
11{
12 protected function getDefaultPreFilters()
13 {
14 return [
15 new ActionFilter\Authentication(),
16 new ActionFilter\HttpMethod([ActionFilter\HttpMethod::METHOD_POST]),
17 new ActionFilter\Csrf(),
18 new ActionFilter\CloseSession(),
19 ];
20 }
21
22 public function minimizeAction(JsonPayload $payload)
23 {
24 $toolbar = $this->getToolbar($payload);
25 if ($toolbar === null)
26 {
27 return [];
28 }
29
30 $itemOptions = $this->getItemOptions($payload);
31 $result = $toolbar->createOrUpdateItem($itemOptions);
32
33 $item = null;
34 if (!$result->isSuccess())
35 {
36 $this->addErrors($result->getErrors());
37 }
38 else
39 {
41 $toolbarItem = $result->getData()['item'];
42 $item = [
43 'title' => $toolbarItem->getTitle(),
44 'entityType' => $toolbarItem->getEntityType(),
45 'entityId' => $toolbarItem->getEntityId(),
46 'url' => $toolbarItem->getUrl(),
47 ];
48 }
49
50 return [
51 'item' => $item,
52 ];
53 }
54
55 public function maximizeAction(JsonPayload $payload)
56 {
57 $this->minimizeAction($payload);
58 }
59
60 public function removeAction(JsonPayload $payload)
61 {
62 [$entityType, $entityId] = $this->getItemId($payload);
63 $toolbar = $this->getToolbar($payload);
64 $toolbar?->removeItem($entityType, $entityId);
65 }
66
67 public function removeAllAction(JsonPayload $payload)
68 {
69 $toolbar = $this->getToolbar($payload);
70 $toolbar?->removeAll();
71 }
72
73 public function collapseAction(JsonPayload $payload)
74 {
75 $toolbar = $this->getToolbar($payload);
76 $toolbar?->collapse();
77 }
78
79 public function expandAction(JsonPayload $payload)
80 {
81 $toolbar = $this->getToolbar($payload);
82 $toolbar?->expand();
83 }
84
85 private function getToolbar(JsonPayload $payload): ?SidePanel\Toolbar
86 {
87 $request = $payload->getData();
88 $request = is_array($request) ? $request : [];
89
90 $context =
91 isset($request['toolbar']['context']) && is_string($request['toolbar']['context'])
92 ? trim($request['toolbar']['context'])
93 : null
94 ;
95
96 if ($context === null || strlen($context) < 1)
97 {
98 return null;
99 }
100
101 return SidePanel\Toolbar::getOrCreate($context);
102 }
103
104 private function getItemOptions(JsonPayload $payload): array
105 {
106 $request = $payload->getData();
107 $request = is_array($request) ? $request : [];
108
109 return isset($request['item']) && is_array($request['item']) ? $request['item'] : [];
110 }
111
112 private function getItemId(JsonPayload $payload): array
113 {
114 $options = $this->getItemOptions($payload);
115 $entityType =
116 isset($options['entityType']) && is_string($options['entityType'])
117 ? trim($options['entityType'])
118 : ''
119 ;
120
121 $entityId =
122 isset($options['entityId']) && is_string($options['entityId'])
123 ? trim($options['entityId'])
124 : ''
125 ;
126
127 return [$entityType, $entityId];
128 }
129}
collapseAction(JsonPayload $payload)
Definition toolbar.php:73
removeAllAction(JsonPayload $payload)
Definition toolbar.php:67
expandAction(JsonPayload $payload)
Definition toolbar.php:79
maximizeAction(JsonPayload $payload)
Definition toolbar.php:55
removeAction(JsonPayload $payload)
Definition toolbar.php:60