Save.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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\Instance;
  8. use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
  9. class Save extends \Magento\Widget\Controller\Adminhtml\Widget\Instance implements HttpPostActionInterface
  10. {
  11. /**
  12. * Save action
  13. *
  14. * @return void
  15. */
  16. public function execute()
  17. {
  18. $widgetInstance = $this->_initWidgetInstance();
  19. if (!$widgetInstance) {
  20. $this->_redirect('adminhtml/*/');
  21. return;
  22. }
  23. $widgetInstance->setTitle(
  24. $this->getRequest()->getPost('title')
  25. )->setStoreIds(
  26. $this->getRequest()->getPost('store_ids', [0])
  27. )->setSortOrder(
  28. $this->getRequest()->getPost('sort_order', 0)
  29. )->setPageGroups(
  30. $this->getRequest()->getPost('widget_instance')
  31. )->setWidgetParameters(
  32. $this->getRequest()->getPost('parameters')
  33. );
  34. try {
  35. $widgetInstance->save();
  36. $this->messageManager->addSuccess(__('The widget instance has been saved.'));
  37. if ($this->getRequest()->getParam('back', false)) {
  38. $this->_redirect(
  39. 'adminhtml/*/edit',
  40. ['instance_id' => $widgetInstance->getId(), '_current' => true]
  41. );
  42. } else {
  43. $this->_redirect('adminhtml/*/');
  44. }
  45. return;
  46. } catch (\Exception $exception) {
  47. $this->messageManager->addError($exception->getMessage());
  48. $this->_logger->critical($exception);
  49. $this->_redirect('adminhtml/*/edit', ['_current' => true]);
  50. return;
  51. }
  52. }
  53. }