Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
deletesectionitem.php
1<?php
2
4
11use CIBlockSection;
12use CUtil;
13
14final class DeleteSectionItem extends BaseItem
15{
16 private IblockRightsChecker $rights;
17
18 public static function getId(): ?string
19 {
20 return 'delete_section';
21 }
22
23 public function __construct(IblockRightsChecker $rights)
24 {
25 $this->rights = $rights;
26 }
27
28 protected function getText(): string
29 {
30 return Loc::getMessage('IBLOCK_GRID_ROW_ACTIONS_DELETE_SECTION_NAME');
31 }
32
33 public function getControl(array $rawFields): ?array
34 {
35 $id = (int)($rawFields['ID'] ?? 0);
36 if ($id <= 0)
37 {
38 return null;
39 }
40
41 $actionId = self::getId();
42 $data = CUtil::PhpToJSObject([
43 'id' => $id,
44 ]);
45 $confirmMessage = \CUtil::JSEscape(
46 Loc::getMessage('IBLOCK_GRID_ROW_ACTIONS_DELETE_SECTION_CONFIRM_MESSAGE')
47 );
48
49 $confirmButtonMessage = \CUtil::JSEscape(
50 Loc::getMessage('IBLOCK_GRID_ROW_ACTIONS_DELETE_SECTION_CONFIRM_BUTTON')
51 );
52 $backButtonMessage = \CUtil::JSEscape(
53 Loc::getMessage('IBLOCK_GRID_ROW_ACTIONS_DELETE_SECTION_BACK_BUTTON')
54 );
55
56 $this->onclick = "IblockGridInstance.sendSmallPopupWithConfirm('{$actionId}', {$data}, '{$confirmMessage}', '{$confirmButtonMessage}', '{$backButtonMessage}')";
57
58 return parent::getControl($rawFields);
59 }
60
61 public function processRequest(HttpRequest $request): ?Result
62 {
63 global $APPLICATION;
64
69 $id = $request->getPost('id');
70 if (empty($id) || !is_numeric($id))
71 {
72 return null;
73 }
74 $id = (int)$id;
75
76 if (!$this->rights->canDeleteSection($id))
77 {
78 throw new AccessDeniedException('Cannot delete element');
79 }
80
81 $result = new Result();
82
83 $updateResult = CIBlockSection::Delete($id);
84 if (!$updateResult)
85 {
86 $message = (string)$APPLICATION->GetException() ?: 'Cannot delete element';
87 $result->addError(new Error($message));
88 }
89
90 return $result;
91 }
92}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
processRequest(HttpRequest $request)