Action.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Block\Adminhtml\Reorder\Renderer;
  7. /**
  8. * Adminhtml alert queue grid block action item renderer
  9. *
  10. * @author Magento Core Team <core@magentocommerce.com>
  11. */
  12. class Action extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer
  13. {
  14. /**
  15. * Array to store all options data
  16. *
  17. * @var array
  18. */
  19. protected $_actions = [];
  20. /**
  21. * Sales reorder
  22. *
  23. * @var \Magento\Sales\Helper\Reorder
  24. */
  25. protected $_salesReorder = null;
  26. /**
  27. * @param \Magento\Backend\Block\Context $context
  28. * @param \Magento\Sales\Helper\Reorder $salesReorder
  29. * @param array $data
  30. */
  31. public function __construct(
  32. \Magento\Backend\Block\Context $context,
  33. \Magento\Sales\Helper\Reorder $salesReorder,
  34. array $data = []
  35. ) {
  36. $this->_salesReorder = $salesReorder;
  37. parent::__construct($context, $data);
  38. }
  39. /**
  40. * @param \Magento\Framework\DataObject $row
  41. * @return string
  42. */
  43. public function render(\Magento\Framework\DataObject $row)
  44. {
  45. $this->_actions = [];
  46. if ($this->_salesReorder->canReorder($row->getId())) {
  47. $reorderAction = [
  48. '@' => [
  49. 'href' => $this->getUrl('sales/order_create/reorder', ['order_id' => $row->getId()]),
  50. ],
  51. '#' => __('Reorder'),
  52. ];
  53. $this->addToActions($reorderAction);
  54. }
  55. $this->_eventManager->dispatch(
  56. 'adminhtml_customer_orders_add_action_renderer',
  57. ['renderer' => $this, 'row' => $row]
  58. );
  59. return $this->_actionsToHtml();
  60. }
  61. /**
  62. * Get escaped value
  63. *
  64. * @param string $value
  65. * @return string
  66. */
  67. protected function _getEscapedValue($value)
  68. {
  69. return addcslashes(htmlspecialchars($value), '\\\'');
  70. }
  71. /**
  72. * Render options array as a HTML string
  73. *
  74. * @param array $actions
  75. * @return string
  76. */
  77. protected function _actionsToHtml(array $actions = [])
  78. {
  79. $html = [];
  80. $attributesObject = new \Magento\Framework\DataObject();
  81. if (empty($actions)) {
  82. $actions = $this->_actions;
  83. }
  84. foreach ($actions as $action) {
  85. $attributesObject->setData($action['@']);
  86. $html[] = '<a ' . $attributesObject->serialize() . '>' . $action['#'] . '</a>';
  87. }
  88. return implode('', $html);
  89. }
  90. /**
  91. * Add one action array to all options data storage
  92. *
  93. * @param array $actionArray
  94. * @return void
  95. */
  96. public function addToActions($actionArray)
  97. {
  98. $this->_actions[] = $actionArray;
  99. }
  100. }