Unassign.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Block\Status\Grid\Column;
  7. use Magento\Framework\App\ObjectManager;
  8. use \Magento\Backend\Block\Template\Context;
  9. use Magento\Framework\Serialize\Serializer\Json;
  10. /**
  11. * @api
  12. * @since 100.0.2
  13. */
  14. class Unassign extends \Magento\Backend\Block\Widget\Grid\Column
  15. {
  16. /**
  17. * @var Json
  18. */
  19. private $json;
  20. /**
  21. * @inheritDoc
  22. *
  23. * @param Json|null $json
  24. */
  25. public function __construct(
  26. Context $context,
  27. array $data = [],
  28. ?Json $json = null
  29. ) {
  30. parent::__construct($context, $data);
  31. $this->json = $json ?? ObjectManager::getInstance()->get(Json::class);
  32. }
  33. /**
  34. * Add decorated action to column
  35. *
  36. * @return array
  37. */
  38. public function getFrameCallback()
  39. {
  40. return [$this, 'decorateAction'];
  41. }
  42. /**
  43. * Decorate values to column
  44. *
  45. * @param string $value
  46. * @param \Magento\Sales\Model\Order\Status $row
  47. * @param \Magento\Backend\Block\Widget\Grid\Column $column
  48. * @param bool $isExport
  49. * @return string
  50. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  51. */
  52. public function decorateAction($value, $row, $column, $isExport)
  53. {
  54. $cell = '';
  55. $state = $row->getState();
  56. if (!empty($state)) {
  57. $url = $this->getUrl('*/*/unassign');
  58. $label = __('Unassign');
  59. $cell = '<a href="#" data-post="'
  60. .$this->escapeHtmlAttr(
  61. $this->json->serialize([
  62. 'action' => $url,
  63. 'data' => ['status' => $row->getStatus(), 'state' => $row->getState()]
  64. ])
  65. )
  66. .'">' . $label . '</a>';
  67. }
  68. return $cell;
  69. }
  70. }