Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Save.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
10 
11 class Save extends \Magento\Widget\Controller\Adminhtml\Widget\Instance implements HttpPostActionInterface
12 {
18  public function execute()
19  {
20  $widgetInstance = $this->_initWidgetInstance();
21  if (!$widgetInstance) {
22  $this->_redirect('adminhtml/*/');
23  return;
24  }
25  $widgetInstance->setTitle(
26  $this->getRequest()->getPost('title')
27  )->setStoreIds(
28  $this->getRequest()->getPost('store_ids', [0])
29  )->setSortOrder(
30  $this->getRequest()->getPost('sort_order', 0)
31  )->setPageGroups(
32  $this->getRequest()->getPost('widget_instance')
33  )->setWidgetParameters(
34  $this->getRequest()->getPost('parameters')
35  );
36  try {
37  $widgetInstance->save();
38  $this->messageManager->addSuccess(__('The widget instance has been saved.'));
39  if ($this->getRequest()->getParam('back', false)) {
40  $this->_redirect(
41  'adminhtml/*/edit',
42  ['instance_id' => $widgetInstance->getId(), '_current' => true]
43  );
44  } else {
45  $this->_redirect('adminhtml/*/');
46  }
47  return;
48  } catch (\Exception $exception) {
49  $this->messageManager->addError($exception->getMessage());
50  $this->_logger->critical($exception);
51  $this->_redirect('adminhtml/*/edit', ['_current' => true]);
52  return;
53  }
54  }
55 }
__()
Definition: __.php:13