SaveButton.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 SaveButton
  11. * @package Magento\Customer\Block\Adminhtml\Edit
  12. */
  13. class SaveButton extends GenericButton implements ButtonProviderInterface
  14. {
  15. /**
  16. * @var AccountManagementInterface
  17. */
  18. protected $customerAccountManagement;
  19. /**
  20. * Constructor
  21. *
  22. * @param \Magento\Backend\Block\Widget\Context $context
  23. * @param \Magento\Framework\Registry $registry
  24. * @param AccountManagementInterface $customerAccountManagement
  25. */
  26. public function __construct(
  27. \Magento\Backend\Block\Widget\Context $context,
  28. \Magento\Framework\Registry $registry,
  29. AccountManagementInterface $customerAccountManagement
  30. ) {
  31. parent::__construct($context, $registry);
  32. $this->customerAccountManagement = $customerAccountManagement;
  33. }
  34. /**
  35. * @return array
  36. */
  37. public function getButtonData()
  38. {
  39. $customerId = $this->getCustomerId();
  40. $canModify = !$customerId || !$this->customerAccountManagement->isReadonly($this->getCustomerId());
  41. $data = [];
  42. if ($canModify) {
  43. $data = [
  44. 'label' => __('Save Customer'),
  45. 'class' => 'save primary',
  46. 'data_attribute' => [
  47. 'mage-init' => ['button' => ['event' => 'save']],
  48. 'form-role' => 'save',
  49. ],
  50. 'sort_order' => 90,
  51. ];
  52. }
  53. return $data;
  54. }
  55. }