Options.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backend\Block\Widget\Grid\Column\Renderer;
  7. /**
  8. * Grid column widget for rendering grid cells that contains mapped values
  9. *
  10. * @api
  11. * @deprecated 100.2.0 in favour of UI component implementation
  12. * @since 100.0.2
  13. */
  14. class Options extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\Text
  15. {
  16. /**
  17. * Get options from column
  18. *
  19. * @return array
  20. */
  21. protected function _getOptions()
  22. {
  23. return $this->getColumn()->getOptions();
  24. }
  25. /**
  26. * Render a grid cell as options
  27. *
  28. * @param \Magento\Framework\DataObject $row
  29. * @return string|void
  30. * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  31. */
  32. public function render(\Magento\Framework\DataObject $row)
  33. {
  34. $options = $this->_getOptions();
  35. $showMissingOptionValues = (bool)$this->getColumn()->getShowMissingOptionValues();
  36. if (!empty($options) && is_array($options)) {
  37. //transform option format
  38. $output = [];
  39. foreach ($options as $option) {
  40. $output[$option['value']] = $option['label'];
  41. }
  42. $value = $row->getData($this->getColumn()->getIndex());
  43. if (is_array($value)) {
  44. $res = [];
  45. foreach ($value as $item) {
  46. if (isset($output[$item])) {
  47. $res[] = $this->escapeHtml($output[$item]);
  48. } elseif ($showMissingOptionValues) {
  49. $res[] = $this->escapeHtml($item);
  50. }
  51. }
  52. return implode(', ', $res);
  53. } elseif (isset($output[$value])) {
  54. return $this->escapeHtml($output[$value]);
  55. } elseif (in_array($value, $output)) {
  56. return $this->escapeHtml($value);
  57. }
  58. }
  59. }
  60. }