Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Data Structures | Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Layout Class Reference
Inheritance diagram for Layout:
Config LayoutInterface Proxy Page Layout

Data Structures

class  ElementTest
 
class  MergeTest
 

Public Member Functions

 __construct (Layout\ProcessorFactory $processorFactory, ManagerInterface $eventManager, Layout\Data\Structure $structure, MessageManagerInterface $messageManager, Design\Theme\ResolverInterface $themeResolver, Layout\ReaderPool $readerPool, Layout\GeneratorPool $generatorPool, FrontendInterface $cache, Layout\Reader\ContextFactory $readerContextFactory, Layout\Generator\ContextFactory $generatorContextFactory, AppState $appState, Logger $logger, $cacheable=true, SerializerInterface $serializer=null)
 
 setGeneratorPool (Layout\GeneratorPool $generatorPool)
 
 setBuilder (Layout\BuilderInterface $builder)
 
 publicBuild ()
 
 __destruct ()
 
 getUpdate ()
 
 generateXml ()
 
 generateElements ()
 
 getChildBlock ($parentName, $alias)
 
 setChild ($parentName, $elementName, $alias)
 
 reorderChild ($parentName, $childName, $offsetOrSibling, $after=true)
 
 unsetChild ($parentName, $alias)
 
 getChildNames ($parentName)
 
 getChildBlocks ($parentName)
 
 getChildName ($parentName, $alias)
 
 renderElement ($name, $useCache=true)
 
 renderNonCachedElement ($name)
 
 addToParentGroup ($blockName, $parentGroupName)
 
 getGroupChildNames ($blockName, $groupName)
 
 hasElement ($name)
 
 getElementProperty ($name, $attribute)
 
 isBlock ($name)
 
 isUiComponent ($name)
 
 isContainer ($name)
 
 isManipulationAllowed ($name)
 
 setBlock ($name, $block)
 
 unsetElement ($name)
 
 createBlock ($type, $name='', array $arguments=[])
 
 addBlock ($block, $name='', $parent='', $alias='')
 
 renameElement ($oldName, $newName)
 
 getAllBlocks ()
 
 getBlock ($name)
 
 getUiComponent ($name)
 
 getParentName ($childName)
 
 getElementAlias ($name)
 
 addOutputElement ($name)
 
 removeOutputElement ($name)
 
 getOutput ()
 
 getMessagesBlock ()
 
 getBlockSingleton ($type)
 
 addAdjustableRenderer ($namespace, $staticType, $dynamicType, $type, $template, $data=[])
 
 getRendererOptions ($namespace, $staticType, $dynamicType)
 
 initMessages ($messageGroups=[])
 
 isCacheable ()
 
 isPrivate ()
 
 setIsPrivate ($isPrivate=true)
 
 getReaderContext ()
 
- Public Member Functions inherited from Config
 __construct ($sourceData=null)
 
 setXml (Element $node)
 
 getNode ($path=null)
 
 getXpath ($xpath)
 
 getXmlString ()
 
 loadFile ($filePath)
 
 loadString ($string)
 
 loadDom (\DOMNode $dom)
 
 setNode ($path, $value, $overwrite=true)
 
 applyExtends ()
 
 processFileData ($text)
 
 extend (Config $config, $overwrite=true)
 
 __destruct ()
 
- Public Member Functions inherited from LayoutInterface
 addContainer ($name, $label, array $options=[], $parent='', $alias='')
 

Data Fields

const LAYOUT_NODE = '<layout/>'
 

Protected Member Functions

 build ()
 
 addToOutputRootContainers ()
 
 displayElement ($name)
 
 _renderBlock ($name)
 
 _renderUiComponent ($name)
 
 _renderContainer ($name, $useCache=true)
 
 _prepareMessageGroup ($messageGroups)
 
 getXml ()
 
- Protected Member Functions inherited from Config
 getXml ()
 

Protected Attributes

 $_update
 
 $_blocks = []
 
 $_output = []
 
 $sharedBlocks = []
 
 $_renderingOutput
 
 $_renderElementCache = []
 
 $structure
 
 $_renderers = []
 
 $_eventManager
 
 $_processorFactory
 
 $messageManager
 
 $isPrivate = false
 
 $themeResolver
 
 $readerPool
 
 $cacheable
 
 $generatorPool
 
 $builder
 
 $cache
 
 $readerContextFactory
 
 $generatorContextFactory
 
 $readerContext
 
 $appState
 
 $logger
 
- Protected Attributes inherited from Config
 $_xml = null
 
 $_elementClass = \Magento\Framework\Simplexml\Element::class
 
 $_xpathExtends = "//*[@extends]"
 

Detailed Description

Layout model

@SuppressWarnings(PHPMD.ExcessiveClassComplexity) @SuppressWarnings(PHPMD.CouplingBetweenObjects) @SuppressWarnings(PHPMD.TooManyFields) @SuppressWarnings(PHPMD.ExcessivePublicCount) @SuppressWarnings(PHPMD.TooManyMethods) @SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 28 of file Layout.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( Layout\ProcessorFactory  $processorFactory,
ManagerInterface  $eventManager,
Layout\Data\Structure  $structure,
MessageManagerInterface  $messageManager,
Design\Theme\ResolverInterface  $themeResolver,
Layout\ReaderPool  $readerPool,
Layout\GeneratorPool  $generatorPool,
FrontendInterface  $cache,
Layout\Reader\ContextFactory  $readerContextFactory,
Layout\Generator\ContextFactory  $generatorContextFactory,
AppState  $appState,
Logger  $logger,
  $cacheable = true,
SerializerInterface  $serializer = null 
)
Parameters
Layout\ProcessorFactory$processorFactory
ManagerInterface$eventManager
Layout\Data\Structure$structure
MessageManagerInterface$messageManager
Design\Theme\ResolverInterface$themeResolver
Layout\ReaderPool$readerPool
Layout\GeneratorPool$generatorPool
FrontendInterface$cache
Layout\Reader\ContextFactory$readerContextFactory
Layout\Generator\ContextFactory$generatorContextFactory
\Magento\Framework\App\State$appState
\Psr\Log\LoggerInterface$logger
bool$cacheable
SerializerInterface | null$serializer

Definition at line 190 of file Layout.php.

205  {
206  $this->_elementClass = \Magento\Framework\View\Layout\Element::class;
207  $this->_renderingOutput = new \Magento\Framework\DataObject();
208  $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class);
209 
210  $this->_processorFactory = $processorFactory;
211  $this->_eventManager = $eventManager;
212  $this->structure = $structure;
213  $this->messageManager = $messageManager;
214  $this->themeResolver = $themeResolver;
215  $this->readerPool = $readerPool;
216  $this->generatorPool = $generatorPool;
217  $this->cacheable = $cacheable;
218  $this->cache = $cache;
219  $this->readerContextFactory = $readerContextFactory;
220  $this->generatorContextFactory = $generatorContextFactory;
221  $this->appState = $appState;
222  $this->logger = $logger;
223  }
$processorFactory
Definition: 404.php:9

◆ __destruct()

__destruct ( )

Cleanup circular references between layout & blocks

Destructor should be called explicitly in order to work around the PHP bug https://bugs.php.net/bug.php?id=62468

Definition at line 272 of file Layout.php.

273  {
274  if (isset($this->_update) && is_object($this->_update)) {
275  $this->_update->__destruct();
276  $this->_update = null;
277  }
278  $this->_blocks = [];
279  parent::__destruct();
280  }

Member Function Documentation

◆ _prepareMessageGroup()

_prepareMessageGroup (   $messageGroups)
protected

Validate message groups

Parameters
array$messageGroups
Returns
array

Definition at line 1079 of file Layout.php.

1080  {
1081  if (!is_array($messageGroups)) {
1082  $messageGroups = [$messageGroups];
1083  } elseif (empty($messageGroups)) {
1084  $messageGroups[] = $this->messageManager->getDefaultGroup();
1085  }
1086  return $messageGroups;
1087  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

◆ _renderBlock()

_renderBlock (   $name)
protected

Gets HTML of block element

Parameters
string$name
Returns
string
Exceptions

Definition at line 554 of file Layout.php.

555  {
556  $block = $this->getBlock($name);
557  return $block ? $block->toHtml() : '';
558  }
$block
Definition: block.php:8
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ _renderContainer()

_renderContainer (   $name,
  $useCache = true 
)
protected

Gets HTML of container element

Parameters
string$name
bool$useCache
Returns
string

Definition at line 580 of file Layout.php.

581  {
582  $html = '';
583  $children = $this->getChildNames($name);
584  foreach ($children as $child) {
585  $html .= $this->renderElement($child, $useCache);
586  }
587  if ($html == '' || !$this->structure->getAttribute($name, Element::CONTAINER_OPT_HTML_TAG)) {
588  return $html;
589  }
590 
591  $htmlId = $this->structure->getAttribute($name, Element::CONTAINER_OPT_HTML_ID);
592  if ($htmlId) {
593  $htmlId = ' id="' . $htmlId . '"';
594  }
595 
596  $htmlClass = $this->structure->getAttribute($name, Element::CONTAINER_OPT_HTML_CLASS);
597  if ($htmlClass) {
598  $htmlClass = ' class="' . $htmlClass . '"';
599  }
600 
601  $htmlTag = $this->structure->getAttribute($name, Element::CONTAINER_OPT_HTML_TAG);
602 
603  $html = sprintf('<%1$s%2$s%3$s>%4$s</%1$s>', $htmlTag, $htmlId, $htmlClass, $html);
604 
605  return $html;
606  }
renderElement($name, $useCache=true)
Definition: Layout.php:483
getChildNames($parentName)
Definition: Layout.php:436
$children
Definition: actions.phtml:11
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ _renderUiComponent()

_renderUiComponent (   $name)
protected

Gets HTML of Ui Component

Parameters
string$name
Returns
string
Exceptions

Definition at line 567 of file Layout.php.

568  {
569  $uiComponent = $this->getUiComponent($name);
570  return $uiComponent ? $uiComponent->toHtml() : '';
571  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ addAdjustableRenderer()

addAdjustableRenderer (   $namespace,
  $staticType,
  $dynamicType,
  $type,
  $template,
  $data = [] 
)
Parameters
string$namespace
string$staticType
string$dynamicType
string$type
string$template
array$data
Returns
$this

Definition at line 1003 of file Layout.php.

1004  {
1005  $this->_renderers[$namespace][$staticType][$dynamicType] = [
1006  'type' => $type,
1007  'template' => $template,
1008  'data' => $data,
1009  ];
1010  return $this;
1011  }
$type
Definition: item.phtml:13
$template
Definition: export.php:12

◆ addBlock()

addBlock (   $block,
  $name = '',
  $parent = '',
  $alias = '' 
)

Add a block to registry, create new object if needed

Parameters
string | \Magento\Framework\View\Element\AbstractBlock$block
string$name
string$parent
string$alias
Returns
\Magento\Framework\View\Element\AbstractBlock

Implements LayoutInterface.

Definition at line 790 of file Layout.php.

791  {
792  $this->build();
793  if ($block instanceof \Magento\Framework\View\Element\AbstractBlock) {
794  $name = $name ?: $block->getNameInLayout();
795  } else {
796  $block = $this->_createBlock($block, $name);
797  }
798  $name = $this->structure->createStructuralElement(
799  $name,
801  $name ?: get_class($block)
802  );
803  $this->setBlock($name, $block);
804  $block->setNameInLayout($name);
805  if ($parent) {
806  $this->structure->setAsChild($name, $parent, $alias);
807  }
808  $block->setLayout($this);
809  return $block;
810  }
setBlock($name, $block)
Definition: Layout.php:724
$block
Definition: block.php:8
if(!trim($html)) $alias
Definition: details.phtml:20
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ addOutputElement()

addOutputElement (   $name)

Add an element to output

Parameters
string$name
Returns
$this

Implements LayoutInterface.

Definition at line 924 of file Layout.php.

925  {
926  $this->_output[$name] = $name;
927  return $this;
928  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ addToOutputRootContainers()

addToOutputRootContainers ( )
protected

Add parent containers to output

Returns
$this

Definition at line 355 of file Layout.php.

356  {
357  foreach ($this->structure->exportElements() as $name => $element) {
358  if ($element['type'] === Element::TYPE_CONTAINER && empty($element['parent'])) {
359  $this->addOutputElement($name);
360  }
361  }
362  return $this;
363  }
if(!isset($_GET['name'])) $name
Definition: log.php:14
$element
Definition: element.phtml:12

◆ addToParentGroup()

addToParentGroup (   $blockName,
  $parentGroupName 
)

Add element to parent group

Parameters
string$blockName
string$parentGroupName
Returns
bool

Implements LayoutInterface.

Definition at line 615 of file Layout.php.

616  {
617  $this->build();
618  return $this->structure->addToParentGroup($blockName, $parentGroupName);
619  }

◆ build()

build ( )
protected

Build layout blocks from generic layouts and/or page configurations

Returns
void

Definition at line 250 of file Layout.php.

251  {
252  if (!empty($this->builder)) {
253  $this->builder->build();
254  }
255  }

◆ createBlock()

createBlock (   $type,
  $name = '',
array  $arguments = [] 
)

Block Factory

Parameters
string$type
string$name
array$arguments
Returns
\Magento\Framework\View\Element\AbstractBlock

Implements LayoutInterface.

Definition at line 755 of file Layout.php.

756  {
757  $this->build();
758  $name = $this->structure->createStructuralElement($name, Element::TYPE_BLOCK, $type);
759  $block = $this->_createBlock($type, $name, $arguments);
760  $block->setLayout($this);
761  return $block;
762  }
$block
Definition: block.php:8
$type
Definition: item.phtml:13
$arguments
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ displayElement()

displayElement (   $name)
protected

Define whether to display element Display if 'display' attribute is absent (false, null) or equal true ('1', true, 'true') In any other cases - do not display

Parameters
string$name
Returns
bool

Definition at line 509 of file Layout.php.

510  {
511  $display = $this->structure->getAttribute($name, 'display');
512  if ($display === '' || $display === false || $display === null
513  || filter_var($display, FILTER_VALIDATE_BOOLEAN)) {
514  return true;
515  }
516  return false;
517  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ generateElements()

generateElements ( )

Create structure of elements from the loaded XML configuration

Returns
void

Implements LayoutInterface.

Definition at line 314 of file Layout.php.

315  {
316  \Magento\Framework\Profiler::start(__CLASS__ . '::' . __METHOD__);
317  $cacheId = 'structure_' . $this->getUpdate()->getCacheId();
318  $result = $this->cache->load($cacheId);
319  if ($result) {
320  $data = $this->serializer->unserialize($result);
321  $this->getReaderContext()->getPageConfigStructure()->populateWithArray($data['pageConfigStructure']);
322  $this->getReaderContext()->getScheduledStructure()->populateWithArray($data['scheduledStructure']);
323  } else {
324  \Magento\Framework\Profiler::start('build_structure');
325  $this->readerPool->interpret($this->getReaderContext(), $this->getNode());
326  \Magento\Framework\Profiler::stop('build_structure');
327 
328  $data = [
329  'pageConfigStructure' => $this->getReaderContext()->getPageConfigStructure()->__toArray(),
330  'scheduledStructure' => $this->getReaderContext()->getScheduledStructure()->__toArray(),
331  ];
332  $this->cache->save($this->serializer->serialize($data), $cacheId, $this->getUpdate()->getHandles());
333  }
334 
335  $generatorContext = $this->generatorContextFactory->create(
336  [
337  'structure' => $this->structure,
338  'layout' => $this,
339  ]
340  );
341 
342  \Magento\Framework\Profiler::start('generate_elements');
343  $this->generatorPool->process($this->getReaderContext(), $generatorContext);
344  \Magento\Framework\Profiler::stop('generate_elements');
345 
346  $this->addToOutputRootContainers();
347  \Magento\Framework\Profiler::stop(__CLASS__ . '::' . __METHOD__);
348  }

◆ generateXml()

generateXml ( )

Layout xml generation

Returns
$this

Implements LayoutInterface.

Definition at line 301 of file Layout.php.

302  {
303  $xml = $this->getUpdate()->asSimplexml();
304  $this->setXml($xml);
305  $this->structure->importElements([]);
306  return $this;
307  }

◆ getAllBlocks()

getAllBlocks ( )

Retrieve all blocks from registry as array

Returns
array

Implements LayoutInterface.

Definition at line 861 of file Layout.php.

862  {
863  $this->build();
864  return $this->_blocks;
865  }

◆ getBlock()

getBlock (   $name)

Get block object by name

Parameters
string$name
Returns
\Magento\Framework\View\Element\AbstractBlock|bool

Implements LayoutInterface.

Definition at line 873 of file Layout.php.

874  {
875  $this->build();
876  if (isset($this->_blocks[$name])) {
877  return $this->_blocks[$name];
878  } else {
879  return false;
880  }
881  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ getBlockSingleton()

getBlockSingleton (   $type)

Get block singleton

Parameters
string$type
Returns
\Magento\Framework\App\Helper\AbstractHelper
Exceptions

Implements LayoutInterface.

Definition at line 981 of file Layout.php.

982  {
983  if (empty($type)) {
984  throw new \Magento\Framework\Exception\LocalizedException(
985  new \Magento\Framework\Phrase('Invalid block type')
986  );
987  }
988  if (!isset($this->sharedBlocks[$type])) {
989  $this->sharedBlocks[$type] = $this->createBlock($type);
990  }
991  return $this->sharedBlocks[$type];
992  }
$type
Definition: item.phtml:13
createBlock($type, $name='', array $arguments=[])
Definition: Layout.php:755

◆ getChildBlock()

getChildBlock (   $parentName,
  $alias 
)

Get child block if exists

Parameters
string$parentName
string$alias
Returns
bool|\Magento\Framework\View\Element\AbstractBlock

Implements LayoutInterface.

Definition at line 372 of file Layout.php.

373  {
374  $this->build();
375  $name = $this->structure->getChildId($parentName, $alias);
376  if ($this->isBlock($name)) {
377  return $this->getBlock($name);
378  }
379  return false;
380  }
if(!trim($html)) $alias
Definition: details.phtml:20
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ getChildBlocks()

getChildBlocks (   $parentName)

Get list of child blocks

Returns associative array of <alias> => <block instance>="">

Parameters
string$parentName
Returns
array

Implements LayoutInterface.

Definition at line 450 of file Layout.php.

451  {
452  $this->build();
453  $blocks = [];
454  foreach ($this->structure->getChildren($parentName) as $childName => $alias) {
455  $block = $this->getBlock($childName);
456  if ($block) {
457  $blocks[$alias] = $block;
458  }
459  }
460  return $blocks;
461  }
$block
Definition: block.php:8
if(!trim($html)) $alias
Definition: details.phtml:20

◆ getChildName()

getChildName (   $parentName,
  $alias 
)

Get child name by alias

Parameters
string$parentName
string$alias
Returns
bool|string

Implements LayoutInterface.

Definition at line 470 of file Layout.php.

471  {
472  $this->build();
473  return $this->structure->getChildId($parentName, $alias);
474  }
if(!trim($html)) $alias
Definition: details.phtml:20

◆ getChildNames()

getChildNames (   $parentName)

Get list of child names

Parameters
string$parentName
Returns
array

Implements LayoutInterface.

Definition at line 436 of file Layout.php.

437  {
438  $this->build();
439  return array_keys($this->structure->getChildren($parentName));
440  }

◆ getElementAlias()

getElementAlias (   $name)

Get element alias by name

Parameters
string$name
Returns
bool|string

Implements LayoutInterface.

Definition at line 912 of file Layout.php.

913  {
914  $this->build();
915  return $this->structure->getChildAlias($this->structure->getParentId($name), $name);
916  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ getElementProperty()

getElementProperty (   $name,
  $attribute 
)

Get property value of an element

Parameters
string$name
string$attribute
Returns
mixed

Implements LayoutInterface.

Definition at line 653 of file Layout.php.

654  {
655  $this->build();
656  return $this->structure->getAttribute($name, $attribute);
657  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ getGroupChildNames()

getGroupChildNames (   $blockName,
  $groupName 
)

Get element names for specified group

Parameters
string$blockName
string$groupName
Returns
array

Implements LayoutInterface.

Definition at line 628 of file Layout.php.

629  {
630  $this->build();
631  return $this->structure->getGroupChildNames($blockName, $groupName);
632  }

◆ getMessagesBlock()

getMessagesBlock ( )

Retrieve messages block

Returns
\Magento\Framework\View\Element\Messages

Implements LayoutInterface.

Definition at line 964 of file Layout.php.

965  {
966  $this->build();
967  $block = $this->getBlock('messages');
968  if ($block) {
969  return $block;
970  }
971  return $this->createBlock(\Magento\Framework\View\Element\Messages::class, 'messages');
972  }
$block
Definition: block.php:8
createBlock($type, $name='', array $arguments=[])
Definition: Layout.php:755

◆ getOutput()

getOutput ( )

Get all blocks marked for output

Returns
string

Implements LayoutInterface.

Definition at line 949 of file Layout.php.

950  {
951  $this->build();
952  $out = '';
953  foreach ($this->_output as $name) {
954  $out .= $this->renderElement($name);
955  }
956  return $out;
957  }
renderElement($name, $useCache=true)
Definition: Layout.php:483
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ getParentName()

getParentName (   $childName)

Gets parent name of an element with specified name

Parameters
string$childName
Returns
bool|string

Implements LayoutInterface.

Definition at line 900 of file Layout.php.

901  {
902  $this->build();
903  return $this->structure->getParentId($childName);
904  }

◆ getReaderContext()

getReaderContext ( )

Getter and lazy loader for reader context

Returns
Layout\Reader\Context

Definition at line 1141 of file Layout.php.

1142  {
1143  if (!$this->readerContext) {
1144  $this->readerContext = $this->readerContextFactory->create();
1145  }
1146  return $this->readerContext;
1147  }

◆ getRendererOptions()

getRendererOptions (   $namespace,
  $staticType,
  $dynamicType 
)
Parameters
string$namespace
string$staticType
string$dynamicType
Returns
array|null

Definition at line 1019 of file Layout.php.

1020  {
1021  if (!isset($this->_renderers[$namespace])) {
1022  return null;
1023  }
1024  if (!isset($this->_renderers[$namespace][$staticType])) {
1025  return null;
1026  }
1027  if (!isset($this->_renderers[$namespace][$staticType][$dynamicType])) {
1028  return null;
1029  }
1030  return $this->_renderers[$namespace][$staticType][$dynamicType];
1031  }

◆ getUiComponent()

getUiComponent (   $name)

Get Ui Component object by name

Parameters
string$name
Returns
\Magento\Framework\View\Element\AbstractBlock|bool

Definition at line 889 of file Layout.php.

890  {
891  return $this->getBlock($name);
892  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ getUpdate()

getUpdate ( )

Retrieve the layout update instance

Returns
\Magento\Framework\View\Layout\ProcessorInterface

Implements LayoutInterface.

Definition at line 287 of file Layout.php.

288  {
289  if (!$this->_update) {
290  $theme = $this->themeResolver->get();
291  $this->_update = $this->_processorFactory->create(['theme' => $theme]);
292  }
293  return $this->_update;
294  }
$theme

◆ getXml()

getXml ( )
protected

Getter and lazy loader for xml element

Returns
\Magento\Framework\Simplexml\Element

Definition at line 1128 of file Layout.php.

1129  {
1130  if (!$this->_xml) {
1131  $this->setXml(simplexml_load_string(self::LAYOUT_NODE, $this->_elementClass));
1132  }
1133  return $this->_xml;
1134  }

◆ hasElement()

hasElement (   $name)

Check if element exists in layout structure

Parameters
string$name
Returns
bool

Implements LayoutInterface.

Definition at line 640 of file Layout.php.

641  {
642  $this->build();
643  return $this->structure->hasElement($name);
644  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ initMessages()

initMessages (   $messageGroups = [])

Init messages by message storage(s), loading and adding messages to layout messages block

Parameters
string | array$messageGroups
Returns
void
Exceptions

Definition at line 1063 of file Layout.php.

1064  {
1065  $this->build();
1066  foreach ($this->_prepareMessageGroup($messageGroups) as $group) {
1067  $block = $this->getMessagesBlock();
1068  $block->addMessages($this->messageManager->getMessages(true, $group));
1069  $block->addStorageType($group);
1070  }
1071  }
$group
Definition: sections.phtml:16
$block
Definition: block.php:8
_prepareMessageGroup($messageGroups)
Definition: Layout.php:1079

◆ isBlock()

isBlock (   $name)

Whether specified element is a block

Parameters
string$name
Returns
bool

Implements LayoutInterface.

Definition at line 665 of file Layout.php.

666  {
667  $this->build();
668  if ($this->structure->hasElement($name)) {
669  return Element::TYPE_BLOCK === $this->structure->getAttribute($name, 'type');
670  }
671  return false;
672  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ isCacheable()

isCacheable ( )

Check is exists non-cacheable layout elements

Returns
bool

Implements LayoutInterface.

Definition at line 1094 of file Layout.php.

1095  {
1096  $this->build();
1097  $cacheableXml = !(bool)count($this->getXml()->xpath('//' . Element::TYPE_BLOCK . '[@cacheable="false"]'));
1098  return $this->cacheable && $cacheableXml;
1099  }

◆ isContainer()

isContainer (   $name)

Checks if element with specified name is container

Parameters
string$name
Returns
bool

Implements LayoutInterface.

Definition at line 695 of file Layout.php.

696  {
697  $this->build();
698  if ($this->structure->hasElement($name)) {
699  return Element::TYPE_CONTAINER === $this->structure->getAttribute($name, 'type');
700  }
701  return false;
702  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ isManipulationAllowed()

isManipulationAllowed (   $name)

Whether the specified element may be manipulated externally

Parameters
string$name
Returns
bool

Implements LayoutInterface.

Definition at line 710 of file Layout.php.

711  {
712  $this->build();
713  $parentName = $this->structure->getParentId($name);
714  return $parentName && $this->isContainer($parentName);
715  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ isPrivate()

isPrivate ( )

Check is exists non-cacheable layout elements

Returns
bool

Definition at line 1106 of file Layout.php.

1107  {
1108  return $this->isPrivate;
1109  }

◆ isUiComponent()

isUiComponent (   $name)

Whether specified element is a UI Component

Parameters
string$name
Returns
bool

Definition at line 680 of file Layout.php.

681  {
682  $this->build();
683  if ($this->structure->hasElement($name)) {
684  return Element::TYPE_UI_COMPONENT === $this->structure->getAttribute($name, 'type');
685  }
686  return false;
687  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ publicBuild()

publicBuild ( )

TODO Will be eliminated in MAGETWO-28359

Returns
void

Definition at line 261 of file Layout.php.

262  {
263  $this->build();
264  }

◆ removeOutputElement()

removeOutputElement (   $name)

Remove an element from output

Parameters
string$name
Returns
$this

Implements LayoutInterface.

Definition at line 936 of file Layout.php.

937  {
938  if (isset($this->_output[$name])) {
939  unset($this->_output[$name]);
940  }
941  return $this;
942  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ renameElement()

renameElement (   $oldName,
  $newName 
)

Rename element in layout and layout structure

Parameters
string$oldName
string$newName
Returns
bool

Implements LayoutInterface.

Definition at line 842 of file Layout.php.

843  {
844  $this->build();
845  if (isset($this->_blocks[$oldName])) {
846  $block = $this->_blocks[$oldName];
847  $this->_blocks[$oldName] = null;
848  unset($this->_blocks[$oldName]);
849  $this->_blocks[$newName] = $block;
850  }
851  $this->structure->renameElement($oldName, $newName);
852 
853  return $this;
854  }
$block
Definition: block.php:8

◆ renderElement()

renderElement (   $name,
  $useCache = true 
)

Find an element in layout, render it and return string with its output

Parameters
string$name
bool$useCache
Returns
string

Implements LayoutInterface.

Definition at line 483 of file Layout.php.

484  {
485  $this->build();
486  if (!isset($this->_renderElementCache[$name]) || !$useCache) {
487  if ($this->displayElement($name)) {
488  $this->_renderElementCache[$name] = $this->renderNonCachedElement($name);
489  } else {
490  return $this->_renderElementCache[$name] = '';
491  }
492  }
493  $this->_renderingOutput->setData('output', $this->_renderElementCache[$name]);
494  $this->_eventManager->dispatch(
495  'core_layout_render_element',
496  ['element_name' => $name, 'layout' => $this, 'transport' => $this->_renderingOutput]
497  );
498  return $this->_renderingOutput->getData('output');
499  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ renderNonCachedElement()

renderNonCachedElement (   $name)

Render non cached element

Parameters
string$name
Returns
string
Exceptions

Definition at line 526 of file Layout.php.

527  {
528  $result = '';
529  try {
530  if ($this->isUiComponent($name)) {
531  $result = $this->_renderUiComponent($name);
532  } elseif ($this->isBlock($name)) {
533  $result = $this->_renderBlock($name);
534  } else {
535  $result = $this->_renderContainer($name, false);
536  }
537  } catch (\Exception $e) {
538  if ($this->appState->getMode() === AppState::MODE_DEVELOPER) {
539  throw $e;
540  }
541  $message = ($e instanceof LocalizedException) ? $e->getLogMessage() : $e->getMessage();
542  $this->logger->critical($message);
543  }
544  return $result;
545  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
_renderContainer($name, $useCache=true)
Definition: Layout.php:580
$message
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ reorderChild()

reorderChild (   $parentName,
  $childName,
  $offsetOrSibling,
  $after = true 
)

Reorder a child of a specified element

If $offsetOrSibling is null, it will put the element to the end If $offsetOrSibling is numeric (integer) value, it will put the element after/before specified position Otherwise – after/before specified sibling

Parameters
string$parentName
string$childName
string | int | null$offsetOrSibling
bool$after
Returns
void

Implements LayoutInterface.

Definition at line 410 of file Layout.php.

411  {
412  $this->build();
413  $this->structure->reorderChildElement($parentName, $childName, $offsetOrSibling, $after);
414  }

◆ setBlock()

setBlock (   $name,
  $block 
)

Save block in blocks registry

Parameters
string$name
\Magento\Framework\View\Element\AbstractBlock$block
Returns
$this

Implements LayoutInterface.

Definition at line 724 of file Layout.php.

725  {
726  $this->_blocks[$name] = $block;
727  return $this;
728  }
$block
Definition: block.php:8
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ setBuilder()

setBuilder ( Layout\BuilderInterface  $builder)
Parameters
Layout\BuilderInterface$builder
Returns
$this

Definition at line 239 of file Layout.php.

240  {
241  $this->builder = $builder;
242  return $this;
243  }

◆ setChild()

setChild (   $parentName,
  $elementName,
  $alias 
)

Set child element into layout structure

Parameters
string$parentName
string$elementName
string$alias
Returns
$this

Implements LayoutInterface.

Definition at line 390 of file Layout.php.

391  {
392  $this->build();
393  $this->structure->setAsChild($elementName, $parentName, $alias);
394  return $this;
395  }
if(!trim($html)) $alias
Definition: details.phtml:20
$elementName
Definition: gallery.phtml:10

◆ setGeneratorPool()

setGeneratorPool ( Layout\GeneratorPool  $generatorPool)
Parameters
Layout\GeneratorPool$generatorPool
Returns
$this

Definition at line 229 of file Layout.php.

230  {
231  $this->generatorPool = $generatorPool;
232  return $this;
233  }

◆ setIsPrivate()

setIsPrivate (   $isPrivate = true)

Mark layout as private

Parameters
bool$isPrivate
Returns
Layout

Definition at line 1117 of file Layout.php.

1118  {
1119  $this->isPrivate = (bool)$isPrivate;
1120  return $this;
1121  }

◆ unsetChild()

unsetChild (   $parentName,
  $alias 
)

Remove child element from parent

Parameters
string$parentName
string$alias
Returns
$this

Implements LayoutInterface.

Definition at line 423 of file Layout.php.

424  {
425  $this->build();
426  $this->structure->unsetChild($parentName, $alias);
427  return $this;
428  }
if(!trim($html)) $alias
Definition: details.phtml:20

◆ unsetElement()

unsetElement (   $name)

Remove block from registry

Parameters
string$name
Returns
$this

Implements LayoutInterface.

Definition at line 736 of file Layout.php.

737  {
738  $this->build();
739  if (isset($this->_blocks[$name])) {
740  $this->_blocks[$name] = null;
741  unset($this->_blocks[$name]);
742  }
743  $this->structure->unsetElement($name);
744  return $this;
745  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

Field Documentation

◆ $_blocks

$_blocks = []
protected

Definition at line 48 of file Layout.php.

◆ $_eventManager

$_eventManager
protected

Definition at line 97 of file Layout.php.

◆ $_output

$_output = []
protected

Definition at line 55 of file Layout.php.

◆ $_processorFactory

$_processorFactory
protected

Definition at line 102 of file Layout.php.

◆ $_renderElementCache

$_renderElementCache = []
protected

Definition at line 76 of file Layout.php.

◆ $_renderers

$_renderers = []
protected

Definition at line 90 of file Layout.php.

◆ $_renderingOutput

$_renderingOutput
protected

Definition at line 69 of file Layout.php.

◆ $_update

$_update
protected

Definition at line 41 of file Layout.php.

◆ $appState

$appState
protected

Definition at line 162 of file Layout.php.

◆ $builder

$builder
protected

Definition at line 137 of file Layout.php.

◆ $cache

$cache
protected

Definition at line 142 of file Layout.php.

◆ $cacheable

$cacheable
protected

Definition at line 127 of file Layout.php.

◆ $generatorContextFactory

$generatorContextFactory
protected

Definition at line 152 of file Layout.php.

◆ $generatorPool

$generatorPool
protected

Definition at line 132 of file Layout.php.

◆ $isPrivate

$isPrivate = false
protected

Definition at line 112 of file Layout.php.

◆ $logger

$logger
protected

Definition at line 167 of file Layout.php.

◆ $messageManager

$messageManager
protected

Definition at line 107 of file Layout.php.

◆ $readerContext

$readerContext
protected

Definition at line 157 of file Layout.php.

◆ $readerContextFactory

$readerContextFactory
protected

Definition at line 147 of file Layout.php.

◆ $readerPool

$readerPool
protected

Definition at line 122 of file Layout.php.

◆ $sharedBlocks

$sharedBlocks = []
protected

Definition at line 62 of file Layout.php.

◆ $structure

$structure
protected

Definition at line 83 of file Layout.php.

◆ $themeResolver

$themeResolver
protected

Definition at line 117 of file Layout.php.

◆ LAYOUT_NODE

const LAYOUT_NODE = '<layout/>'

Empty layout xml

Definition at line 34 of file Layout.php.


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