Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Layout Class Reference
Inheritance diagram for Layout:
AbstractResult ResultInterface

Public Member Functions

 __construct (View\Element\Template\Context $context, View\LayoutFactory $layoutFactory, View\Layout\ReaderPool $layoutReaderPool, Framework\Translate\InlineInterface $translateInline, View\Layout\BuilderFactory $layoutBuilderFactory, View\Layout\GeneratorPool $generatorPool, $isIsolated=false)
 
 getLayout ()
 
 addDefaultHandle ()
 
 getDefaultLayoutHandle ()
 
 addHandle ($handleName)
 
 addUpdate ($update)
 
 renderResult (ResponseInterface $httpResponse)
 
- Public Member Functions inherited from AbstractResult
 setHttpResponseCode ($httpCode)
 
 setHeader ($name, $value, $replace=false)
 
 setStatusHeader ($httpCode, $version=null, $phrase=null)
 
 renderResult (ResponseInterface $response)
 

Protected Member Functions

 initLayoutBuilder ()
 
 render (HttpResponseInterface $response)
 
- Protected Member Functions inherited from AbstractResult
 applyHttpHeaders (HttpResponseInterface $response)
 
 render (HttpResponseInterface $response)
 

Protected Attributes

 $layoutFactory
 
 $layoutBuilderFactory
 
 $layoutReaderPool
 
 $layout
 
 $translateInline
 
 $eventManager
 
 $request
 
- Protected Attributes inherited from AbstractResult
 $httpResponseCode
 
 $headers = []
 
 $statusHeaderCode
 
 $statusHeaderVersion
 
 $statusHeaderPhrase
 

Detailed Description

A generic layout response can be used for rendering any kind of layout So it comprises a response body from the layout elements it has and sets it to the HTTP response

@SuppressWarnings(PHPMD.CouplingBetweenObjects)

@api

Since
100.0.2

Definition at line 24 of file Layout.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( View\Element\Template\Context  $context,
View\LayoutFactory  $layoutFactory,
View\Layout\ReaderPool  $layoutReaderPool,
Framework\Translate\InlineInterface  $translateInline,
View\Layout\BuilderFactory  $layoutBuilderFactory,
View\Layout\GeneratorPool  $generatorPool,
  $isIsolated = false 
)

Constructor

Parameters
View\Element\Template\Context$context
View\LayoutFactory$layoutFactory
View\Layout\ReaderPool$layoutReaderPool
Framework\Translate\InlineInterface$translateInline
View\Layout\BuilderFactory$layoutBuilderFactory
View\Layout\GeneratorPool$generatorPool
bool$isIsolated

Definition at line 72 of file Layout.php.

80  {
81  $this->layoutFactory = $layoutFactory;
82  $this->layoutBuilderFactory = $layoutBuilderFactory;
83  $this->layoutReaderPool = $layoutReaderPool;
84  $this->eventManager = $context->getEventManager();
85  $this->request = $context->getRequest();
86  $this->translateInline = $translateInline;
87  // TODO Shared layout object will be deleted in MAGETWO-28359
88  $this->layout = $isIsolated
89  ? $this->layoutFactory->create(['reader' => $this->layoutReaderPool, 'generatorPool' => $generatorPool])
90  : $context->getLayout();
91  $this->layout->setGeneratorPool($generatorPool);
92  $this->initLayoutBuilder();
93  }

Member Function Documentation

◆ addDefaultHandle()

addDefaultHandle ( )
Returns
$this

Definition at line 118 of file Layout.php.

119  {
120  $this->addHandle($this->getDefaultLayoutHandle());
121  return $this;
122  }

◆ addHandle()

addHandle (   $handleName)
Parameters
string|string[]$handleName
Returns
$this

Definition at line 138 of file Layout.php.

139  {
140  $this->getLayout()->getUpdate()->addHandle($handleName);
141  return $this;
142  }

◆ addUpdate()

addUpdate (   $update)

Add update to merge object

Parameters
string$update
Returns
$this

Definition at line 150 of file Layout.php.

151  {
152  $this->getLayout()->getUpdate()->addUpdate($update);
153  return $this;
154  }

◆ getDefaultLayoutHandle()

getDefaultLayoutHandle ( )

Retrieve the default layout handle name for the current action

Returns
string

Definition at line 129 of file Layout.php.

130  {
131  return strtolower($this->request->getFullActionName());
132  }

◆ getLayout()

getLayout ( )

Get layout instance for current page

Returns
\Magento\Framework\View\LayoutInterface

Definition at line 110 of file Layout.php.

111  {
112  return $this->layout;
113  }

◆ initLayoutBuilder()

initLayoutBuilder ( )
protected

Create layout builder

Returns
void

Definition at line 100 of file Layout.php.

101  {
102  $this->layoutBuilderFactory->create(View\Layout\BuilderFactory::TYPE_LAYOUT, ['layout' => $this->layout]);
103  }

◆ render()

render ( HttpResponseInterface  $response)
protected

{}

Definition at line 181 of file Layout.php.

182  {
183  $output = $this->layout->getOutput();
184  $this->translateInline->processResponseBody($output);
185  $response->appendBody($output);
186  return $this;
187  }
$response
Definition: 404.php:11

◆ renderResult()

renderResult ( ResponseInterface  $httpResponse)

Render current layout

Parameters
HttpResponseInterface | ResponseInterface$httpResponse
Returns
$this

Implements ResultInterface.

Definition at line 162 of file Layout.php.

163  {
164  \Magento\Framework\Profiler::start('LAYOUT');
165  \Magento\Framework\Profiler::start('layout_render');
166 
167  $this->eventManager->dispatch('layout_render_before');
168  $this->eventManager->dispatch('layout_render_before_' . $this->request->getFullActionName());
169 
170  $this->applyHttpHeaders($httpResponse);
171  $this->render($httpResponse);
172 
173  \Magento\Framework\Profiler::stop('layout_render');
174  \Magento\Framework\Profiler::stop('LAYOUT');
175  return $this;
176  }
render(HttpResponseInterface $response)
Definition: Layout.php:181
applyHttpHeaders(HttpResponseInterface $response)

Field Documentation

◆ $eventManager

$eventManager
protected

Definition at line 54 of file Layout.php.

◆ $layout

$layout
protected

Definition at line 44 of file Layout.php.

◆ $layoutBuilderFactory

$layoutBuilderFactory
protected

Definition at line 34 of file Layout.php.

◆ $layoutFactory

$layoutFactory
protected

Definition at line 29 of file Layout.php.

◆ $layoutReaderPool

$layoutReaderPool
protected

Definition at line 39 of file Layout.php.

◆ $request

$request
protected

Definition at line 59 of file Layout.php.

◆ $translateInline

$translateInline
protected

Definition at line 49 of file Layout.php.


The documentation for this class was generated from the following file: