BuildWidget.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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\HttpPostActionInterface as HttpPostActionInterface;
  9. class BuildWidget extends \Magento\Backend\App\Action implements HttpPostActionInterface
  10. {
  11. /**
  12. * Authorization level of a basic admin session
  13. */
  14. const ADMIN_RESOURCE = 'Magento_Widget::widget_instance';
  15. /**
  16. * @var \Magento\Widget\Model\Widget
  17. */
  18. protected $_widget;
  19. /**
  20. * @param \Magento\Backend\App\Action\Context $context
  21. * @param \Magento\Widget\Model\Widget $widget
  22. */
  23. public function __construct(
  24. \Magento\Backend\App\Action\Context $context,
  25. \Magento\Widget\Model\Widget $widget
  26. ) {
  27. $this->_widget = $widget;
  28. parent::__construct($context);
  29. }
  30. /**
  31. * Format widget pseudo-code for inserting into wysiwyg editor
  32. *
  33. * @return void
  34. */
  35. public function execute()
  36. {
  37. $type = $this->getRequest()->getPost('widget_type');
  38. $params = $this->getRequest()->getPost('parameters', []);
  39. $asIs = $this->getRequest()->getPost('as_is');
  40. $html = $this->_widget->getWidgetDeclaration($type, $params, $asIs);
  41. $this->getResponse()->setBody($html);
  42. }
  43. }