123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- /**
- * Adminhtml Manage Widgets Instance Controller
- */
- namespace Magento\Widget\Controller\Adminhtml\Widget;
- abstract class Instance extends \Magento\Backend\App\Action
- {
- /**
- * Authorization level of a basic admin session
- *
- * @see _isAllowed()
- */
- const ADMIN_RESOURCE = 'Magento_Widget::widget_instance';
- /**
- * Core registry
- *
- * @var \Magento\Framework\Registry
- */
- protected $_coreRegistry;
- /**
- * @var \Magento\Widget\Model\Widget\InstanceFactory
- */
- protected $_widgetFactory;
- /**
- * @var \Psr\Log\LoggerInterface
- */
- protected $_logger;
- /**
- * @var \Magento\Framework\Math\Random
- */
- protected $mathRandom;
- /**
- * @var \Magento\Framework\Translate\InlineInterface
- */
- protected $_translateInline;
- /**
- * @param \Magento\Backend\App\Action\Context $context
- * @param \Magento\Framework\Registry $coreRegistry
- * @param \Magento\Widget\Model\Widget\InstanceFactory $widgetFactory
- * @param \Psr\Log\LoggerInterface $logger
- * @param \Magento\Framework\Math\Random $mathRandom
- * @param \Magento\Framework\Translate\InlineInterface $translateInline
- */
- public function __construct(
- \Magento\Backend\App\Action\Context $context,
- \Magento\Framework\Registry $coreRegistry,
- \Magento\Widget\Model\Widget\InstanceFactory $widgetFactory,
- \Psr\Log\LoggerInterface $logger,
- \Magento\Framework\Math\Random $mathRandom,
- \Magento\Framework\Translate\InlineInterface $translateInline
- ) {
- $this->_translateInline = $translateInline;
- $this->_coreRegistry = $coreRegistry;
- $this->_widgetFactory = $widgetFactory;
- $this->_logger = $logger;
- $this->mathRandom = $mathRandom;
- parent::__construct($context);
- }
- /**
- * Load layout, set active menu and breadcrumbs
- *
- * @return $this
- */
- protected function _initAction()
- {
- $this->_view->loadLayout();
- $this->_setActiveMenu(
- 'Magento_Widget::cms_widget_instance'
- )->_addBreadcrumb(
- __('CMS'),
- __('CMS')
- )->_addBreadcrumb(
- __('Manage Widget Instances'),
- __('Manage Widget Instances')
- );
- return $this;
- }
- /**
- * Init widget instance object and set it to registry
- *
- * @return \Magento\Widget\Model\Widget\Instance|boolean
- */
- protected function _initWidgetInstance()
- {
- /** @var $widgetInstance \Magento\Widget\Model\Widget\Instance */
- $widgetInstance = $this->_widgetFactory->create();
- $code = $this->getRequest()->getParam('code', null);
- $instanceId = $this->getRequest()->getParam('instance_id', null);
- if ($instanceId) {
- $widgetInstance->load($instanceId)->setCode($code);
- if (!$widgetInstance->getId()) {
- $this->messageManager->addError(__('Please specify a correct widget.'));
- return false;
- }
- } else {
- // Widget id was not provided on the query-string. Locate the widget instance
- // type (namespace\classname) based upon the widget code (aka, widget id).
- $themeId = $this->getRequest()->getParam('theme_id', null);
- $type = $code != null ? $widgetInstance->getWidgetReference('code', $code, 'type') : null;
- $widgetInstance->setType($type)->setCode($code)->setThemeId($themeId);
- }
- $this->_coreRegistry->register('current_widget_instance', $widgetInstance);
- return $widgetInstance;
- }
- /**
- * Set body to response
- *
- * @param string $body
- * @return void
- */
- protected function setBody($body)
- {
- $this->_translateInline->processResponseBody($body);
- $this->getResponse()->setBody($body);
- }
- }
|