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