UnlockButton.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
  8. use Magento\Customer\Model\CustomerRegistry;
  9. /**
  10. * Class UnlockButton
  11. */
  12. class UnlockButton extends GenericButton implements ButtonProviderInterface
  13. {
  14. /**
  15. * @var \Magento\Customer\Model\CustomerRegistry
  16. */
  17. protected $customerRegistry;
  18. /**
  19. * Constructor
  20. *
  21. * @param \Magento\Backend\Block\Widget\Context $context
  22. * @param \Magento\Framework\Registry $registry
  23. * @param \Magento\Customer\Model\CustomerRegistry $customerRegistry
  24. */
  25. public function __construct(
  26. \Magento\Backend\Block\Widget\Context $context,
  27. \Magento\Framework\Registry $registry,
  28. CustomerRegistry $customerRegistry
  29. ) {
  30. parent::__construct($context, $registry);
  31. $this->customerRegistry = $customerRegistry;
  32. }
  33. /**
  34. * Returns Unlock button data
  35. *
  36. * @return array
  37. */
  38. public function getButtonData()
  39. {
  40. $customerId = $this->getCustomerId();
  41. $data = [];
  42. if ($customerId) {
  43. $customer = $this->customerRegistry->retrieve($customerId);
  44. if ($customer->isCustomerLocked()) {
  45. $data = [
  46. 'label' => __('Unlock'),
  47. 'class' => 'unlock unlock-customer',
  48. 'on_click' => sprintf("location.href = '%s';", $this->getUnlockUrl()),
  49. 'sort_order' => 50,
  50. ];
  51. }
  52. }
  53. return $data;
  54. }
  55. /**
  56. * Returns customer unlock action URL
  57. *
  58. * @return string
  59. */
  60. protected function getUnlockUrl()
  61. {
  62. return $this->getUrl('customer/locks/unlock', ['customer_id' => $this->getCustomerId()]);
  63. }
  64. }