Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Handle.php
Go to the documentation of this file.
1 <?php
7 
8 use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
17 
22 class Handle extends AbstractAction implements HttpGetActionInterface
23 {
27  private $contextFactory;
28 
34  public function __construct(
35  Context $context,
37  ContextFactory $contextFactory = null
38  ) {
39  parent::__construct($context, $factory);
40  $this->contextFactory = $contextFactory
41  ?: ObjectManager::getInstance()->get(ContextFactory::class);
42  }
43 
49  public function execute()
50  {
51  $response = '';
52  $handle = $this->_request->getParam('handle');
53  $namespace = $this->_request->getParam('namespace');
54  $buttons = $this->_request->getParam('buttons', false);
55  $this->_view->loadLayout(['default', $handle], true, true, false);
56  $layout = $this->_view->getLayout();
57  $context = $this->contextFactory->create(
58  [
59  'namespace' => $namespace,
60  'pageLayout' => $layout
61  ]
62  );
63 
64  $component = $this->factory->create($namespace, null, ['context' => $context]);
65  if ($this->validateAclResource($component->getContext()->getDataProvider()->getConfigData())) {
66  $uiComponent = $layout->getBlock($namespace);
67  $response = $uiComponent instanceof UiComponent ? $uiComponent->toHtml() : '';
68  }
69 
70  if ($buttons) {
71  $actionsToolbar = $layout->getBlock(ActionPool::ACTIONS_PAGE_TOOLBAR);
72  $response .= $actionsToolbar instanceof Template ? $actionsToolbar->toHtml() : '';
73  }
74 
75  $this->_response->appendBody($response);
76  }
77 
84  private function validateAclResource($dataProviderConfigData)
85  {
86  if (isset($dataProviderConfigData['aclResource'])
87  && !$this->_authorization->isAllowed($dataProviderConfigData['aclResource'])
88  ) {
89  if (!$this->_request->isAjax()) {
90  $this->_redirect('admin/denied');
91  }
92  return false;
93  }
94 
95  return true;
96  }
97 }
$response
Definition: 404.php:11
__construct(Context $context, UiComponentFactory $factory, ContextFactory $contextFactory=null)
Definition: Handle.php:34
$handle