Edit.php 2.9 KB

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