contextFactory = $contextFactory ?: ObjectManager::getInstance()->get(ContextFactory::class); } /** * Render UI component by namespace in handle context * * @return void */ public function execute() { $response = ''; $handle = $this->_request->getParam('handle'); $namespace = $this->_request->getParam('namespace'); $buttons = $this->_request->getParam('buttons', false); $this->_view->loadLayout(['default', $handle], true, true, false); $layout = $this->_view->getLayout(); $context = $this->contextFactory->create( [ 'namespace' => $namespace, 'pageLayout' => $layout ] ); $component = $this->factory->create($namespace, null, ['context' => $context]); if ($this->validateAclResource($component->getContext()->getDataProvider()->getConfigData())) { $uiComponent = $layout->getBlock($namespace); $response = $uiComponent instanceof UiComponent ? $uiComponent->toHtml() : ''; } if ($buttons) { $actionsToolbar = $layout->getBlock(ActionPool::ACTIONS_PAGE_TOOLBAR); $response .= $actionsToolbar instanceof Template ? $actionsToolbar->toHtml() : ''; } $this->_response->appendBody($response); } /** * Optionally validate ACL resource of components with a DataSource/DataProvider * * @param mixed $dataProviderConfigData * @return bool */ private function validateAclResource($dataProviderConfigData) { if (isset($dataProviderConfigData['aclResource']) && !$this->_authorization->isAllowed($dataProviderConfigData['aclResource']) ) { if (!$this->_request->isAjax()) { $this->_redirect('admin/denied'); } return false; } return true; } }