Multiaction.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Block\Adminhtml\Grid\Renderer;
  7. /**
  8. * Adminhtml customers wishlist grid item action renderer for few action controls in one cell
  9. *
  10. * @author Magento Core Team <core@magentocommerce.com>
  11. */
  12. class Multiaction extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\Action
  13. {
  14. /**
  15. * Renders column
  16. *
  17. * @param \Magento\Framework\DataObject $row
  18. * @return string
  19. */
  20. public function render(\Magento\Framework\DataObject $row)
  21. {
  22. $html = '';
  23. $actions = $this->getColumn()->getActions();
  24. if (!empty($actions) && is_array($actions)) {
  25. $links = [];
  26. foreach ($actions as $action) {
  27. if (is_array($action)) {
  28. $link = $this->_toLinkHtml($action, $row);
  29. if ($link) {
  30. $links[] = $link;
  31. }
  32. }
  33. }
  34. $html = implode('<br />', $links);
  35. }
  36. if ($html == '') {
  37. $html = '&nbsp;';
  38. }
  39. return $html;
  40. }
  41. /**
  42. * Render single action as link html
  43. *
  44. * @param array $action
  45. * @param \Magento\Framework\DataObject $row
  46. * @return string|false
  47. */
  48. protected function _toLinkHtml($action, \Magento\Framework\DataObject $row)
  49. {
  50. $product = $row->getProduct();
  51. if (isset($action['process']) && $action['process'] == 'configurable') {
  52. if ($product->canConfigure()) {
  53. $style = '';
  54. $onClick = sprintf('onclick="return %s.configureItem(%s)"', $action['control_object'], $row->getId());
  55. return sprintf('<a href="%s" %s %s>%s</a>', $action['url'], $style, $onClick, $action['caption']);
  56. } else {
  57. return false;
  58. }
  59. } else {
  60. return parent::_toLinkHtml($action, $row);
  61. }
  62. }
  63. }