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

Public Member Functions

 __construct (\Magento\Framework\View\LayoutInterface $layout, RequestInterface $request, ResponseInterface $response, \Magento\Framework\Config\ScopeInterface $configScope, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Framework\View\Result\PageFactory $pageFactory, ActionFlag $actionFlag)
 
 getPage ()
 
 getLayout ()
 
 loadLayout ($handles=null, $generateBlocks=true, $generateXml=true, $addActionHandles=true)
 
 getDefaultLayoutHandle ()
 
 addActionLayoutHandles ()
 
 addPageLayoutHandles (array $parameters=[], $defaultHandle=null)
 
 loadLayoutUpdates ()
 
 generateLayoutXml ()
 
 generateLayoutBlocks ()
 
 renderLayout ($output='')
 
 setIsLayoutLoaded ($value)
 
 isLayoutLoaded ()
 

Protected Attributes

 $_layout
 
 $_configScope
 
 $_eventManager
 
 $page
 
 $_actionFlag
 
 $_response
 
 $_request
 
 $_isLayoutLoaded = false
 

Detailed Description

Definition at line 8 of file View.php.

Constructor & Destructor Documentation

◆ __construct()

Parameters
\Magento\Framework\View\LayoutInterface$layout
RequestInterface$request
ResponseInterface$response
\Magento\Framework\Config\ScopeInterface$configScope
\Magento\Framework\Event\ManagerInterface$eventManager
\Magento\Framework\View\Result\PageFactory$pageFactory
ActionFlag$actionFlag

Definition at line 59 of file View.php.

67  {
68  $this->_layout = $layout;
69  $this->_request = $request;
70  $this->_response = $response;
71  $this->_configScope = $configScope;
72  $this->_eventManager = $eventManager;
73  $this->_actionFlag = $actionFlag;
74  $this->page = $pageFactory->create(true);
75  }
$response
Definition: 404.php:11

Member Function Documentation

◆ addActionLayoutHandles()

addActionLayoutHandles ( )

Add layout handle by full controller action name

Returns
$this

Implements ViewInterface.

Definition at line 145 of file View.php.

146  {
147  $this->getLayout()->getUpdate()->addHandle($this->getDefaultLayoutHandle());
148  return $this;
149  }

◆ addPageLayoutHandles()

addPageLayoutHandles ( array  $parameters = [],
  $defaultHandle = null 
)

Add layout updates handles associated with the action page

Parameters
array | null$parameterspage parameters
string | null$defaultHandle
Returns
bool

Implements ViewInterface.

Definition at line 158 of file View.php.

159  {
160  return $this->page->addPageLayoutHandles($parameters, $defaultHandle);
161  }

◆ generateLayoutBlocks()

generateLayoutBlocks ( )

Generate layout blocks

Returns
$this

Implements ViewInterface.

Definition at line 190 of file View.php.

191  {
192  $this->page->getConfig()->publicBuild();
193  return $this;
194  }

◆ generateLayoutXml()

generateLayoutXml ( )

Generate layout xml

Returns
$this

Implements ViewInterface.

Definition at line 179 of file View.php.

180  {
181  $this->page->getConfig()->publicBuild();
182  return $this;
183  }

◆ getDefaultLayoutHandle()

getDefaultLayoutHandle ( )

Retrieve the default layout handle name for the current action

Returns
string

Implements ViewInterface.

Definition at line 135 of file View.php.

136  {
137  return $this->page->getDefaultLayoutHandle();
138  }

◆ getLayout()

getLayout ( )

Retrieve current layout object

Returns
\Magento\Framework\View\LayoutInterface

Implements ViewInterface.

Definition at line 92 of file View.php.

93  {
94  return $this->page->getLayout();
95  }

◆ getPage()

getPage ( )

Retrieve current page object

Returns
\Magento\Framework\View\Result\Page

Implements ViewInterface.

Definition at line 82 of file View.php.

83  {
84  return $this->page;
85  }

◆ isLayoutLoaded()

isLayoutLoaded ( )

Returns is layout loaded

Returns
bool

Implements ViewInterface.

Definition at line 244 of file View.php.

245  {
246  return $this->_isLayoutLoaded;
247  }

◆ loadLayout()

loadLayout (   $handles = null,
  $generateBlocks = true,
  $generateXml = true,
  $addActionHandles = true 
)

{Load layout by handles(s)

Parameters
string | null | bool$handles
bool$generateBlocks
bool$generateXml
bool$addActionHandles
Returns
ViewInterface
Exceptions
}

Implements ViewInterface.

Definition at line 100 of file View.php.

101  {
102  if ($this->_isLayoutLoaded) {
103  throw new \RuntimeException('Layout must be loaded only once.');
104  }
105  // if handles were specified in arguments load them first
106  if (!empty($handles)) {
107  $this->getLayout()->getUpdate()->addHandle($handles);
108  }
109 
110  if ($addActionHandles) {
111  // add default layout handles for this action
112  $this->page->initLayout();
113  }
114  $this->loadLayoutUpdates();
115 
116  if (!$generateXml) {
117  return $this;
118  }
119  $this->generateLayoutXml();
120 
121  if (!$generateBlocks) {
122  return $this;
123  }
124  $this->generateLayoutBlocks();
125  $this->_isLayoutLoaded = true;
126 
127  return $this;
128  }

◆ loadLayoutUpdates()

loadLayoutUpdates ( )

Load layout updates

Returns
$this

Implements ViewInterface.

Definition at line 168 of file View.php.

169  {
170  $this->page->getConfig()->publicBuild();
171  return $this;
172  }

◆ renderLayout()

renderLayout (   $output = '')

Rendering layout

Parameters
string$output
Returns
$this

Implements ViewInterface.

Definition at line 202 of file View.php.

203  {
204  if ($this->_actionFlag->get('', 'no-renderLayout')) {
205  return $this;
206  }
207 
208  \Magento\Framework\Profiler::start('LAYOUT');
209 
210  \Magento\Framework\Profiler::start('layout_render');
211 
212  if ('' !== $output) {
213  $this->getLayout()->addOutputElement($output);
214  }
215 
216  $this->_eventManager->dispatch('controller_action_layout_render_before');
217  $this->_eventManager->dispatch(
218  'controller_action_layout_render_before_' . $this->_request->getFullActionName()
219  );
220 
221  $this->page->renderResult($this->_response);
222  \Magento\Framework\Profiler::stop('layout_render');
223 
224  \Magento\Framework\Profiler::stop('LAYOUT');
225  return $this;
226  }

◆ setIsLayoutLoaded()

setIsLayoutLoaded (   $value)

Set isLayoutLoaded flag

Parameters
bool$value
Returns
void

Implements ViewInterface.

Definition at line 234 of file View.php.

235  {
236  $this->_isLayoutLoaded = $value;
237  }
$value
Definition: gender.phtml:16

Field Documentation

◆ $_actionFlag

$_actionFlag
protected

Definition at line 33 of file View.php.

◆ $_configScope

$_configScope
protected

Definition at line 18 of file View.php.

◆ $_eventManager

$_eventManager
protected

Definition at line 23 of file View.php.

◆ $_isLayoutLoaded

$_isLayoutLoaded = false
protected

Definition at line 48 of file View.php.

◆ $_layout

$_layout
protected

Definition at line 13 of file View.php.

◆ $_request

$_request
protected

Definition at line 43 of file View.php.

◆ $_response

$_response
protected

Definition at line 38 of file View.php.

◆ $page

$page
protected

Definition at line 28 of file View.php.


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