Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
LoadOptions.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
12 
13 class LoadOptions extends \Magento\Backend\App\Action implements HttpGetActionInterface, HttpPostActionInterface
14 {
18  const ADMIN_RESOURCE = 'Magento_Widget::widget_instance';
19 
23  private $conditionsHelper;
24 
30  public function execute()
31  {
32  try {
33  $this->_view->loadLayout();
34  if ($paramsJson = $this->getRequest()->getParam('widget')) {
35  $request = $this->_objectManager->get(\Magento\Framework\Json\Helper\Data::class)
36  ->jsonDecode($paramsJson);
37  if (is_array($request)) {
38  $optionsBlock = $this->_view->getLayout()->getBlock('wysiwyg_widget.options');
39  if (isset($request['widget_type'])) {
40  $optionsBlock->setWidgetType($request['widget_type']);
41  }
42  if (isset($request['values'])) {
43  $request['values'] = array_map('htmlspecialchars_decode', $request['values']);
44  if (isset($request['values']['conditions_encoded'])) {
45  $request['values']['conditions'] =
46  $this->getConditionsHelper()->decode($request['values']['conditions_encoded']);
47  }
48  $optionsBlock->setWidgetValues($request['values']);
49  }
50  }
51  $this->_view->renderLayout();
52  }
53  } catch (\Magento\Framework\Exception\LocalizedException $e) {
54  $result = ['error' => true, 'message' => $e->getMessage()];
55  $this->getResponse()->representJson(
56  $this->_objectManager->get(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($result)
57  );
58  }
59  }
60 
65  private function getConditionsHelper()
66  {
67  if (!$this->conditionsHelper) {
68  $this->conditionsHelper = ObjectManager::getInstance()->get(\Magento\Widget\Helper\Conditions::class);
69  }
70 
71  return $this->conditionsHelper;
72  }
73 }