DeleteButton.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Block\Adminhtml\Edit;
  7. use Magento\Customer\Api\AccountManagementInterface;
  8. use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
  9. /**
  10. * Class DeleteButton
  11. *
  12. * @package Magento\Customer\Block\Adminhtml\Edit
  13. */
  14. class DeleteButton extends GenericButton implements ButtonProviderInterface
  15. {
  16. /**
  17. * @var AccountManagementInterface
  18. */
  19. protected $customerAccountManagement;
  20. /**
  21. * Constructor
  22. *
  23. * @param \Magento\Backend\Block\Widget\Context $context
  24. * @param \Magento\Framework\Registry $registry
  25. * @param AccountManagementInterface $customerAccountManagement
  26. */
  27. public function __construct(
  28. \Magento\Backend\Block\Widget\Context $context,
  29. \Magento\Framework\Registry $registry,
  30. AccountManagementInterface $customerAccountManagement
  31. ) {
  32. parent::__construct($context, $registry);
  33. $this->customerAccountManagement = $customerAccountManagement;
  34. }
  35. /**
  36. * Get button data.
  37. *
  38. * @return array
  39. */
  40. public function getButtonData()
  41. {
  42. $customerId = $this->getCustomerId();
  43. $canModify = $customerId && !$this->customerAccountManagement->isReadonly($this->getCustomerId());
  44. $data = [];
  45. if ($customerId && $canModify) {
  46. $data = [
  47. 'label' => __('Delete Customer'),
  48. 'class' => 'delete',
  49. 'id' => 'customer-edit-delete-button',
  50. 'data_attribute' => [
  51. 'url' => $this->getDeleteUrl()
  52. ],
  53. 'on_click' => '',
  54. 'sort_order' => 20,
  55. 'aclResource' => 'Magento_Customer::delete',
  56. ];
  57. }
  58. return $data;
  59. }
  60. /**
  61. * Get delete url.
  62. *
  63. * @return string
  64. */
  65. public function getDeleteUrl()
  66. {
  67. return $this->getUrl('*/*/delete', ['id' => $this->getCustomerId()]);
  68. }
  69. }