_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); } }