GiftOptions.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\GiftMessage\Block\Cart\Item\Renderer\Actions;
  7. use Magento\Backend\Block\Template\Context;
  8. use Magento\Checkout\Block\Cart\Item\Renderer\Actions\Generic;
  9. use Magento\Framework\Json\Encoder;
  10. /**
  11. * @api
  12. * @since 100.0.2
  13. */
  14. class GiftOptions extends Generic
  15. {
  16. /**
  17. * @var bool
  18. */
  19. protected $_isScopePrivate = false;
  20. /**
  21. * @var array
  22. */
  23. protected $jsLayout;
  24. /**
  25. * @var array|LayoutProcessorInterface[]
  26. */
  27. protected $layoutProcessors;
  28. /**
  29. * @var Encoder
  30. */
  31. protected $jsonEncoder;
  32. /**
  33. * @param Context $context
  34. * @param Encoder $jsonEncoder
  35. * @param array $layoutProcessors
  36. * @param array $data
  37. */
  38. public function __construct(
  39. Context $context,
  40. Encoder $jsonEncoder,
  41. array $layoutProcessors = [],
  42. array $data = []
  43. ) {
  44. parent::__construct($context, $data);
  45. $this->jsonEncoder = $jsonEncoder;
  46. $this->_isScopePrivate = true;
  47. $this->jsLayout = isset($data['jsLayout']) && is_array($data['jsLayout']) ? $data['jsLayout'] : [];
  48. $this->layoutProcessors = $layoutProcessors;
  49. }
  50. /**
  51. * Return JS layout
  52. *
  53. * @return string
  54. */
  55. public function getJsLayout()
  56. {
  57. $jsLayout = $this->jsLayout;
  58. foreach ($this->layoutProcessors as $processor) {
  59. $jsLayout = $processor->process($jsLayout, $this->getItem());
  60. }
  61. return $this->jsonEncoder->encode($jsLayout);
  62. }
  63. }