Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
deletesectionitem.php
1
<?php
2
3
namespace
Bitrix\Iblock\Grid\Row\Actions\Item
;
4
5
use
Bitrix\Iblock\Grid\Access\IblockRightsChecker
;
6
use
Bitrix\Main\AccessDeniedException
;
7
use
Bitrix\Main\Error
;
8
use
Bitrix\Main\HttpRequest
;
9
use
Bitrix\Main\Localization\Loc
;
10
use
Bitrix\Main\Result
;
11
use CIBlockSection;
12
use CUtil;
13
14
final
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
}
Bitrix\Iblock\Grid\Access\IblockRightsChecker
Definition
iblockrightschecker.php:10
Bitrix\Iblock\Grid\Row\Actions\Item\BaseItem
Definition
baseitem.php:8
Bitrix\Iblock\Grid\Row\Actions\Item\DeleteSectionItem
Definition
deletesectionitem.php:15
Bitrix\Iblock\Grid\Row\Actions\Item\DeleteSectionItem\getControl
getControl(array $rawFields)
Definition
deletesectionitem.php:33
Bitrix\Iblock\Grid\Row\Actions\Item\DeleteSectionItem\__construct
__construct(IblockRightsChecker $rights)
Definition
deletesectionitem.php:23
Bitrix\Iblock\Grid\Row\Actions\Item\DeleteSectionItem\getText
getText()
Definition
deletesectionitem.php:28
Bitrix\Iblock\Grid\Row\Actions\Item\DeleteSectionItem\getId
static getId()
Definition
deletesectionitem.php:18
Bitrix\Main\AccessDeniedException
Definition
exception.php:214
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\HttpRequest
Definition
httprequest.php:20
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\ORM\Data\Result
Definition
result.php:16
Bitrix\Main\Result
Definition
result.php:14
Bitrix\Main\Grid\Row\Action\Action\processRequest
processRequest(HttpRequest $request)
Bitrix\Iblock\Grid\Row\Actions\Item
Definition
activateelementitem.php:3
modules
iblock
lib
grid
row
actions
item
deletesectionitem.php
Создано системой
1.10.0