LoadOptions.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Widget\Controller\Adminhtml\Widget;
  8. use Magento\Framework\App\Action\HttpGetActionInterface;
  9. use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
  10. use Magento\Framework\App\ObjectManager;
  11. class LoadOptions extends \Magento\Backend\App\Action implements HttpGetActionInterface, HttpPostActionInterface
  12. {
  13. /**
  14. * Authorization level of a basic admin session
  15. */
  16. const ADMIN_RESOURCE = 'Magento_Widget::widget_instance';
  17. /**
  18. * @var \Magento\Widget\Helper\Conditions
  19. */
  20. private $conditionsHelper;
  21. /**
  22. * Ajax responder for loading plugin options form
  23. *
  24. * @return void
  25. */
  26. public function execute()
  27. {
  28. try {
  29. $this->_view->loadLayout();
  30. if ($paramsJson = $this->getRequest()->getParam('widget')) {
  31. $request = $this->_objectManager->get(\Magento\Framework\Json\Helper\Data::class)
  32. ->jsonDecode($paramsJson);
  33. if (is_array($request)) {
  34. $optionsBlock = $this->_view->getLayout()->getBlock('wysiwyg_widget.options');
  35. if (isset($request['widget_type'])) {
  36. $optionsBlock->setWidgetType($request['widget_type']);
  37. }
  38. if (isset($request['values'])) {
  39. $request['values'] = array_map('htmlspecialchars_decode', $request['values']);
  40. if (isset($request['values']['conditions_encoded'])) {
  41. $request['values']['conditions'] =
  42. $this->getConditionsHelper()->decode($request['values']['conditions_encoded']);
  43. }
  44. $optionsBlock->setWidgetValues($request['values']);
  45. }
  46. }
  47. $this->_view->renderLayout();
  48. }
  49. } catch (\Magento\Framework\Exception\LocalizedException $e) {
  50. $result = ['error' => true, 'message' => $e->getMessage()];
  51. $this->getResponse()->representJson(
  52. $this->_objectManager->get(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($result)
  53. );
  54. }
  55. }
  56. /**
  57. * @return \Magento\Widget\Helper\Conditions
  58. * @deprecated 101.0.0
  59. */
  60. private function getConditionsHelper()
  61. {
  62. if (!$this->conditionsHelper) {
  63. $this->conditionsHelper = ObjectManager::getInstance()->get(\Magento\Widget\Helper\Conditions::class);
  64. }
  65. return $this->conditionsHelper;
  66. }
  67. }