1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Customer\Block\Adminhtml\Group;
use Magento\Customer\Api\GroupManagementInterface;
use Magento\Customer\Api\GroupRepositoryInterface;
use Magento\Customer\Controller\RegistryConstants;
/**
* Customer group edit block
*/
class Edit extends \Magento\Backend\Block\Widget\Form\Container
{
/**
* Core registry
*
* @var \Magento\Framework\Registry
*/
protected $coreRegistry;
/**
* @var GroupRepositoryInterface
*/
protected $groupRepository;
/**
* @var GroupManagementInterface
*/
protected $groupManagement;
/**
* Constructor
*
* @param \Magento\Backend\Block\Widget\Context $context
* @param \Magento\Framework\Registry $registry
* @param GroupRepositoryInterface $groupRepository
* @param GroupManagementInterface $groupManagement
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Widget\Context $context,
\Magento\Framework\Registry $registry,
GroupRepositoryInterface $groupRepository,
GroupManagementInterface $groupManagement,
array $data = []
) {
$this->coreRegistry = $registry;
$this->groupRepository = $groupRepository;
$this->groupManagement = $groupManagement;
parent::__construct($context, $data);
}
/**
* Update Save and Delete buttons. Remove Delete button if group can't be deleted.
*
* @return void
*/
protected function _construct()
{
parent::_construct();
$this->_objectId = 'id';
$this->_controller = 'adminhtml_group';
$this->_blockGroup = 'Magento_Customer';
$this->buttonList->update('save', 'label', __('Save Customer Group'));
$this->buttonList->update('delete', 'label', __('Delete Customer Group'));
$groupId = $this->coreRegistry->registry(RegistryConstants::CURRENT_GROUP_ID);
if (!$groupId || $this->groupManagement->isReadonly($groupId)) {
$this->buttonList->remove('delete');
}
}
/**
* Retrieve the header text, either editing an existing group or creating a new one.
*
* @return \Magento\Framework\Phrase
*/
public function getHeaderText()
{
$groupId = $this->coreRegistry->registry(RegistryConstants::CURRENT_GROUP_ID);
if ($groupId === null) {
return __('New Customer Group');
} else {
$group = $this->groupRepository->getById($groupId);
return __('Edit Customer Group "%1"', $this->escapeHtml($group->getCode()));
}
}
/**
* Retrieve CSS classes added to the header.
*
* @return string
*/
public function getHeaderCssClass()
{
return 'icon-head head-customer-groups';
}
}