DeleteButton.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Customer\Block\Adminhtml\Edit\Address;
  8. use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
  9. use Magento\Customer\Ui\Component\Listing\Address\Column\Actions;
  10. /**
  11. * Delete button on edit customer address form
  12. */
  13. class DeleteButton extends GenericButton implements ButtonProviderInterface
  14. {
  15. /**
  16. * Get delete button data.
  17. *
  18. * @return array
  19. * @throws \Magento\Framework\Exception\LocalizedException
  20. */
  21. public function getButtonData()
  22. {
  23. $data = [];
  24. if ($this->getAddressId()) {
  25. $data = [
  26. 'label' => __('Delete'),
  27. 'on_click' => '',
  28. 'data_attribute' => [
  29. 'mage-init' => [
  30. 'Magento_Ui/js/form/button-adapter' => [
  31. 'actions' => [
  32. [
  33. 'targetName' => 'customer_address_form.customer_address_form',
  34. 'actionName' => 'deleteAddress',
  35. 'params' => [
  36. $this->getDeleteUrl(),
  37. ],
  38. ]
  39. ],
  40. ],
  41. ],
  42. ],
  43. 'sort_order' => 20
  44. ];
  45. }
  46. return $data;
  47. }
  48. /**
  49. * Get delete button url.
  50. *
  51. * @return string
  52. * @throws \Magento\Framework\Exception\LocalizedException
  53. */
  54. private function getDeleteUrl(): string
  55. {
  56. return $this->getUrl(
  57. Actions::CUSTOMER_ADDRESS_PATH_DELETE,
  58. ['parent_id' => $this->getCustomerId(), 'id' => $this->getAddressId()]
  59. );
  60. }
  61. }