layoutFactory = $layoutFactory; $this->layoutBuilderFactory = $layoutBuilderFactory; $this->layoutReaderPool = $layoutReaderPool; $this->eventManager = $context->getEventManager(); $this->request = $context->getRequest(); $this->translateInline = $translateInline; // TODO Shared layout object will be deleted in MAGETWO-28359 $this->layout = $isIsolated ? $this->layoutFactory->create(['reader' => $this->layoutReaderPool, 'generatorPool' => $generatorPool]) : $context->getLayout(); $this->layout->setGeneratorPool($generatorPool); $this->initLayoutBuilder(); } /** * Create layout builder * * @return void */ protected function initLayoutBuilder() { $this->layoutBuilderFactory->create(View\Layout\BuilderFactory::TYPE_LAYOUT, ['layout' => $this->layout]); } /** * Get layout instance for current page * * @return \Magento\Framework\View\Layout */ public function getLayout() { return $this->layout; } /** * @return $this */ public function addDefaultHandle() { $this->addHandle($this->getDefaultLayoutHandle()); return $this; } /** * Retrieve the default layout handle name for the current action * * @return string */ public function getDefaultLayoutHandle() { return strtolower($this->request->getFullActionName()); } /** * @param string|string[] $handleName * @return $this */ public function addHandle($handleName) { $this->getLayout()->getUpdate()->addHandle($handleName); return $this; } /** * Add update to merge object * * @param string $update * @return $this */ public function addUpdate($update) { $this->getLayout()->getUpdate()->addUpdate($update); return $this; } /** * Render current layout * * @param ResponseInterface $response * @return $this */ public function renderResult(ResponseInterface $response) { \Magento\Framework\Profiler::start('LAYOUT'); \Magento\Framework\Profiler::start('layout_render'); $this->applyHttpHeaders($response); $this->render($response); $this->eventManager->dispatch('layout_render_before'); $this->eventManager->dispatch('layout_render_before_' . $this->request->getFullActionName()); \Magento\Framework\Profiler::stop('layout_render'); \Magento\Framework\Profiler::stop('LAYOUT'); return $this; } /** * Render current layout * * @param ResponseInterface $response * @return $this */ protected function render(ResponseInterface $response) { $output = $this->layout->getOutput(); $this->translateInline->processResponseBody($output); $response->appendBody($output); return $this; } }