Additional.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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\Massaction;
  7. /**
  8. * @api
  9. * @SuppressWarnings(PHPMD.DepthOfInheritance)
  10. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  11. * @deprecated 100.2.0 in favour of UI component implementation
  12. * @since 100.0.2
  13. */
  14. class Additional extends \Magento\Backend\Block\Widget\Form\Generic
  15. {
  16. /**
  17. * @var \Magento\Framework\View\Layout\Argument\Interpreter\Options
  18. */
  19. protected $_optionsInterpreter;
  20. /**
  21. * @param \Magento\Backend\Block\Template\Context $context
  22. * @param \Magento\Framework\Registry $registry
  23. * @param \Magento\Framework\Data\FormFactory $formFactory
  24. * @param \Magento\Framework\View\Layout\Argument\Interpreter\Options $optionsInterpreter
  25. * @param array $data
  26. */
  27. public function __construct(
  28. \Magento\Backend\Block\Template\Context $context,
  29. \Magento\Framework\Registry $registry,
  30. \Magento\Framework\Data\FormFactory $formFactory,
  31. \Magento\Framework\View\Layout\Argument\Interpreter\Options $optionsInterpreter,
  32. array $data = []
  33. ) {
  34. parent::__construct($context, $registry, $formFactory, $data);
  35. $this->_optionsInterpreter = $optionsInterpreter;
  36. }
  37. /**
  38. * Prepare form before rendering HTML
  39. *
  40. * @return $this
  41. */
  42. protected function _prepareForm()
  43. {
  44. /** @var \Magento\Framework\Data\Form $form */
  45. $form = $this->_formFactory->create();
  46. foreach ($this->getData('fields') as $itemId => $item) {
  47. $this->_prepareFormItem($item);
  48. $form->addField($itemId, $item['type'], $item);
  49. }
  50. $this->setForm($form);
  51. return $this;
  52. }
  53. /**
  54. * Prepare form item
  55. *
  56. * @param array &$item
  57. * @return void
  58. */
  59. protected function _prepareFormItem(array &$item)
  60. {
  61. if ($item['type'] == 'select' && is_string($item['values'])) {
  62. $modelClass = $item['values'];
  63. $item['values'] = $this->_optionsInterpreter->evaluate(['model' => $modelClass]);
  64. }
  65. $item['class'] = isset($item['class']) ? $item['class'] . ' absolute-advice' : 'absolute-advice';
  66. }
  67. }