-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
Copy pathLayout.php
executable file
·1149 lines (1051 loc) · 30.8 KB
/
Layout.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View;
use Magento\Framework\Cache\FrontendInterface;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\Message\ManagerInterface as MessageManagerInterface;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Framework\View\Layout\Element;
use Magento\Framework\View\Layout\ScheduledStructure;
use Magento\Framework\App\State as AppState;
use Psr\Log\LoggerInterface as Logger;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\App\ObjectManager;
/**
* Layout model
*
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.TooManyFields)
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
* @SuppressWarnings(PHPMD.TooManyMethods)
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
class Layout extends \Magento\Framework\Simplexml\Config implements \Magento\Framework\View\LayoutInterface
{
/**
* Empty layout xml
*/
const LAYOUT_NODE = '<layout/>';
/**
* Layout Update module
*
* @var \Magento\Framework\View\Layout\ProcessorInterface
*/
protected $_update;
/**
* Blocks registry
*
* @var array
*/
protected $_blocks = [];
/**
* Cache of elements to output during rendering
*
* @var array
*/
protected $_output = [];
/**
* Helper blocks cache for this layout
*
* @var array
*/
protected $sharedBlocks = [];
/**
* A variable for transporting output into observer during rendering
*
* @var \Magento\Framework\DataObject
*/
protected $_renderingOutput;
/**
* Cache of generated elements' HTML
*
* @var array
*/
protected $_renderElementCache = [];
/**
* Layout structure model
*
* @var Layout\Data\Structure
*/
protected $structure;
/**
* Renderers registered for particular name
*
* @var array
*/
protected $_renderers = [];
/**
* Core event manager proxy
*
* @var \Magento\Framework\Event\ManagerInterface
*/
protected $_eventManager;
/**
* @var \Magento\Framework\View\Layout\ProcessorFactory
*/
protected $_processorFactory;
/**
* @var \Magento\Framework\Message\ManagerInterface
*/
protected $messageManager;
/**
* @var bool
*/
protected $isPrivate = false;
/**
* @var \Magento\Framework\View\Design\Theme\ResolverInterface
*/
protected $themeResolver;
/**
* @var Layout\ReaderPool
*/
protected $readerPool;
/**
* @var bool
*/
protected $cacheable;
/**
* @var \Magento\Framework\View\Layout\GeneratorPool
*/
protected $generatorPool;
/**
* @var \Magento\Framework\View\Layout\BuilderInterface
*/
protected $builder;
/**
* @var FrontendInterface
*/
protected $cache;
/**
* @var Layout\Reader\ContextFactory
*/
protected $readerContextFactory;
/**
* @var Layout\Generator\ContextFactory
*/
protected $generatorContextFactory;
/**
* @var Layout\Reader\Context
*/
protected $readerContext;
/**
* @var \Magento\Framework\App\State
*/
protected $appState;
/**
* @var \Psr\Log\LoggerInterface
*/
protected $logger;
/**
* @var SerializerInterface
*/
private $serializer;
/**
* @param Layout\ProcessorFactory $processorFactory
* @param ManagerInterface $eventManager
* @param Layout\Data\Structure $structure
* @param MessageManagerInterface $messageManager
* @param Design\Theme\ResolverInterface $themeResolver
* @param Layout\ReaderPool $readerPool
* @param Layout\GeneratorPool $generatorPool
* @param FrontendInterface $cache
* @param Layout\Reader\ContextFactory $readerContextFactory
* @param Layout\Generator\ContextFactory $generatorContextFactory
* @param \Magento\Framework\App\State $appState
* @param \Psr\Log\LoggerInterface $logger
* @param bool $cacheable
* @param SerializerInterface|null $serializer
*/
public function __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
) {
$this->_elementClass = \Magento\Framework\View\Layout\Element::class;
$this->_renderingOutput = new \Magento\Framework\DataObject();
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class);
$this->_processorFactory = $processorFactory;
$this->_eventManager = $eventManager;
$this->structure = $structure;
$this->messageManager = $messageManager;
$this->themeResolver = $themeResolver;
$this->readerPool = $readerPool;
$this->generatorPool = $generatorPool;
$this->cacheable = $cacheable;
$this->cache = $cache;
$this->readerContextFactory = $readerContextFactory;
$this->generatorContextFactory = $generatorContextFactory;
$this->appState = $appState;
$this->logger = $logger;
}
/**
* @param Layout\GeneratorPool $generatorPool
* @return $this
*/
public function setGeneratorPool(Layout\GeneratorPool $generatorPool)
{
$this->generatorPool = $generatorPool;
return $this;
}
/**
* @param Layout\BuilderInterface $builder
* @return $this
*/
public function setBuilder(Layout\BuilderInterface $builder)
{
$this->builder = $builder;
return $this;
}
/**
* Build layout blocks from generic layouts and/or page configurations
*
* @return void
*/
protected function build()
{
if (!empty($this->builder)) {
$this->builder->build();
}
}
/**
* TODO Will be eliminated in MAGETWO-28359
* @return void
*/
public function publicBuild()
{
$this->build();
}
/**
* 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
*/
public function __destruct()
{
if (isset($this->_update) && is_object($this->_update)) {
$this->_update->__destruct();
$this->_update = null;
}
$this->_blocks = [];
parent::__destruct();
}
/**
* Retrieve the layout update instance
*
* @return \Magento\Framework\View\Layout\ProcessorInterface
*/
public function getUpdate()
{
if (!$this->_update) {
$theme = $this->themeResolver->get();
$this->_update = $this->_processorFactory->create(['theme' => $theme]);
}
return $this->_update;
}
/**
* Layout xml generation
*
* @return $this
*/
public function generateXml()
{
$xml = $this->getUpdate()->asSimplexml();
$this->setXml($xml);
$this->structure->importElements([]);
return $this;
}
/**
* Create structure of elements from the loaded XML configuration
*
* @return void
*/
public function generateElements()
{
\Magento\Framework\Profiler::start(__CLASS__ . '::' . __METHOD__);
$cacheId = 'structure_' . $this->getUpdate()->getCacheId();
$result = $this->cache->load($cacheId);
if ($result) {
$data = $this->serializer->unserialize($result);
$this->getReaderContext()->getPageConfigStructure()->populateWithArray($data['pageConfigStructure']);
$this->getReaderContext()->getScheduledStructure()->populateWithArray($data['scheduledStructure']);
} else {
\Magento\Framework\Profiler::start('build_structure');
$this->readerPool->interpret($this->getReaderContext(), $this->getNode());
\Magento\Framework\Profiler::stop('build_structure');
$data = [
'pageConfigStructure' => $this->getReaderContext()->getPageConfigStructure()->__toArray(),
'scheduledStructure' => $this->getReaderContext()->getScheduledStructure()->__toArray(),
];
$this->cache->save($this->serializer->serialize($data), $cacheId, $this->getUpdate()->getHandles());
}
$generatorContext = $this->generatorContextFactory->create(
[
'structure' => $this->structure,
'layout' => $this,
]
);
\Magento\Framework\Profiler::start('generate_elements');
$this->generatorPool->process($this->getReaderContext(), $generatorContext);
\Magento\Framework\Profiler::stop('generate_elements');
$this->addToOutputRootContainers();
\Magento\Framework\Profiler::stop(__CLASS__ . '::' . __METHOD__);
}
/**
* Add parent containers to output
*
* @return $this
*/
protected function addToOutputRootContainers()
{
foreach ($this->structure->exportElements() as $name => $element) {
if ($element['type'] === Element::TYPE_CONTAINER && empty($element['parent'])) {
$this->addOutputElement($name);
}
}
return $this;
}
/**
* Get child block if exists
*
* @param string $parentName
* @param string $alias
* @return bool|\Magento\Framework\View\Element\AbstractBlock
*/
public function getChildBlock($parentName, $alias)
{
$this->build();
$name = $this->structure->getChildId($parentName, $alias);
if ($this->isBlock($name)) {
return $this->getBlock($name);
}
return false;
}
/**
* Set child element into layout structure
*
* @param string $parentName
* @param string $elementName
* @param string $alias
* @return $this
*/
public function setChild($parentName, $elementName, $alias)
{
$this->build();
$this->structure->setAsChild($elementName, $parentName, $alias);
return $this;
}
/**
* 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
*
* @param string $parentName
* @param string $childName
* @param string|int|null $offsetOrSibling
* @param bool $after
* @return void
*/
public function reorderChild($parentName, $childName, $offsetOrSibling, $after = true)
{
$this->build();
$this->structure->reorderChildElement($parentName, $childName, $offsetOrSibling, $after);
}
/**
* Remove child element from parent
*
* @param string $parentName
* @param string $alias
* @return $this
*/
public function unsetChild($parentName, $alias)
{
$this->build();
$this->structure->unsetChild($parentName, $alias);
return $this;
}
/**
* Get list of child names
*
* @param string $parentName
* @return array
*/
public function getChildNames($parentName)
{
$this->build();
return array_keys($this->structure->getChildren($parentName));
}
/**
* Get list of child blocks
*
* Returns associative array of <alias> => <block instance>
*
* @param string $parentName
* @return array
*/
public function getChildBlocks($parentName)
{
$this->build();
$blocks = [];
foreach ($this->structure->getChildren($parentName) as $childName => $alias) {
$block = $this->getBlock($childName);
if ($block) {
$blocks[$alias] = $block;
}
}
return $blocks;
}
/**
* Get child name by alias
*
* @param string $parentName
* @param string $alias
* @return bool|string
*/
public function getChildName($parentName, $alias)
{
$this->build();
return $this->structure->getChildId($parentName, $alias);
}
/**
* Find an element in layout, render it and return string with its output
*
* @param string $name
* @param bool $useCache
* @return string
*/
public function renderElement($name, $useCache = true)
{
$this->build();
if (!isset($this->_renderElementCache[$name]) || !$useCache) {
if ($this->displayElement($name)) {
$this->_renderElementCache[$name] = $this->renderNonCachedElement($name);
} else {
return $this->_renderElementCache[$name] = '';
}
}
$this->_renderingOutput->setData('output', $this->_renderElementCache[$name]);
$this->_eventManager->dispatch(
'core_layout_render_element',
['element_name' => $name, 'layout' => $this, 'transport' => $this->_renderingOutput]
);
return $this->_renderingOutput->getData('output');
}
/**
* 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
*
* @param string $name
* @return bool
*/
protected function displayElement($name)
{
$display = $this->structure->getAttribute($name, 'display');
if ($display === '' || $display === false || $display === null
|| filter_var($display, FILTER_VALIDATE_BOOLEAN)) {
return true;
}
return false;
}
/**
* Render non cached element
*
* @param string $name
* @return string
* @throws \Exception
*/
public function renderNonCachedElement($name)
{
$result = '';
try {
if ($this->isUiComponent($name)) {
$result = $this->_renderUiComponent($name);
} elseif ($this->isBlock($name)) {
$result = $this->_renderBlock($name);
} else {
$result = $this->_renderContainer($name);
}
} catch (\Exception $e) {
if ($this->appState->getMode() === AppState::MODE_DEVELOPER) {
throw $e;
}
$message = ($e instanceof LocalizedException) ? $e->getLogMessage() : $e->getMessage();
$this->logger->critical($message);
}
return $result;
}
/**
* Gets HTML of block element
*
* @param string $name
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _renderBlock($name)
{
$block = $this->getBlock($name);
return $block ? $block->toHtml() : '';
}
/**
* Gets HTML of Ui Component
*
* @param string $name
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _renderUiComponent($name)
{
$uiComponent = $this->getUiComponent($name);
return $uiComponent ? $uiComponent->toHtml() : '';
}
/**
* Gets HTML of container element
*
* @param string $name
* @return string
*/
protected function _renderContainer($name)
{
$html = '';
$children = $this->getChildNames($name);
foreach ($children as $child) {
$html .= $this->renderElement($child);
}
if ($html == '' || !$this->structure->getAttribute($name, Element::CONTAINER_OPT_HTML_TAG)) {
return $html;
}
$htmlId = $this->structure->getAttribute($name, Element::CONTAINER_OPT_HTML_ID);
if ($htmlId) {
$htmlId = ' id="' . $htmlId . '"';
}
$htmlClass = $this->structure->getAttribute($name, Element::CONTAINER_OPT_HTML_CLASS);
if ($htmlClass) {
$htmlClass = ' class="' . $htmlClass . '"';
}
$htmlTag = $this->structure->getAttribute($name, Element::CONTAINER_OPT_HTML_TAG);
$html = sprintf('<%1$s%2$s%3$s>%4$s</%1$s>', $htmlTag, $htmlId, $htmlClass, $html);
return $html;
}
/**
* Add element to parent group
*
* @param string $blockName
* @param string $parentGroupName
* @return bool
*/
public function addToParentGroup($blockName, $parentGroupName)
{
$this->build();
return $this->structure->addToParentGroup($blockName, $parentGroupName);
}
/**
* Get element names for specified group
*
* @param string $blockName
* @param string $groupName
* @return array
*/
public function getGroupChildNames($blockName, $groupName)
{
$this->build();
return $this->structure->getGroupChildNames($blockName, $groupName);
}
/**
* Check if element exists in layout structure
*
* @param string $name
* @return bool
*/
public function hasElement($name)
{
$this->build();
return $this->structure->hasElement($name);
}
/**
* Get property value of an element
*
* @param string $name
* @param string $attribute
* @return mixed
*/
public function getElementProperty($name, $attribute)
{
$this->build();
return $this->structure->getAttribute($name, $attribute);
}
/**
* Whether specified element is a block
*
* @param string $name
* @return bool
*/
public function isBlock($name)
{
$this->build();
if ($this->structure->hasElement($name)) {
return Element::TYPE_BLOCK === $this->structure->getAttribute($name, 'type');
}
return false;
}
/**
* Whether specified element is a UI Component
*
* @param string $name
* @return bool
*/
public function isUiComponent($name)
{
$this->build();
if ($this->structure->hasElement($name)) {
return Element::TYPE_UI_COMPONENT === $this->structure->getAttribute($name, 'type');
}
return false;
}
/**
* Checks if element with specified name is container
*
* @param string $name
* @return bool
*/
public function isContainer($name)
{
$this->build();
if ($this->structure->hasElement($name)) {
return Element::TYPE_CONTAINER === $this->structure->getAttribute($name, 'type');
}
return false;
}
/**
* Whether the specified element may be manipulated externally
*
* @param string $name
* @return bool
*/
public function isManipulationAllowed($name)
{
$this->build();
$parentName = $this->structure->getParentId($name);
return $parentName && $this->isContainer($parentName);
}
/**
* Save block in blocks registry
*
* @param string $name
* @param \Magento\Framework\View\Element\AbstractBlock $block
* @return $this
*/
public function setBlock($name, $block)
{
$this->_blocks[$name] = $block;
return $this;
}
/**
* Remove block from registry
*
* @param string $name
* @return $this
*/
public function unsetElement($name)
{
$this->build();
if (isset($this->_blocks[$name])) {
$this->_blocks[$name] = null;
unset($this->_blocks[$name]);
}
$this->structure->unsetElement($name);
return $this;
}
/**
* Block Factory
*
* @param string $type
* @param string $name
* @param array $arguments
* @return \Magento\Framework\View\Element\AbstractBlock
*/
public function createBlock($type, $name = '', array $arguments = [])
{
$this->build();
$name = $this->structure->createStructuralElement($name, Element::TYPE_BLOCK, $type);
$block = $this->_createBlock($type, $name, $arguments);
$block->setLayout($this);
return $block;
}
/**
* Create block and add to layout
*
* @param string $type
* @param string $name
* @param array $arguments
* @return \Magento\Framework\View\Element\AbstractBlock
*/
protected function _createBlock($type, $name, array $arguments = [])
{
/** @var \Magento\Framework\View\Layout\Generator\Block $blockGenerator */
$blockGenerator = $this->generatorPool->getGenerator(Layout\Generator\Block::TYPE);
$block = $blockGenerator->createBlock($type, $name, $arguments);
$this->setBlock($name, $block);
return $block;
}
/**
* Add a block to registry, create new object if needed
*
* @param string|\Magento\Framework\View\Element\AbstractBlock $block
* @param string $name
* @param string $parent
* @param string $alias
* @return \Magento\Framework\View\Element\AbstractBlock
*/
public function addBlock($block, $name = '', $parent = '', $alias = '')
{
$this->build();
if ($block instanceof \Magento\Framework\View\Element\AbstractBlock) {
$name = $name ?: $block->getNameInLayout();
} else {
$block = $this->_createBlock($block, $name);
}
$name = $this->structure->createStructuralElement(
$name,
Element::TYPE_BLOCK,
$name ?: get_class($block)
);
$this->setBlock($name, $block);
$block->setNameInLayout($name);
if ($parent) {
$this->structure->setAsChild($name, $parent, $alias);
}
$block->setLayout($this);
return $block;
}
/**
* Insert container into layout structure
*
* @param string $name
* @param string $label
* @param array $options
* @param string $parent
* @param string $alias
* @return void
*/
public function addContainer($name, $label, array $options = [], $parent = '', $alias = '')
{
$this->build();
$name = $this->structure->createStructuralElement($name, Element::TYPE_CONTAINER, $alias);
$options[Layout\Element::CONTAINER_OPT_LABEL] = $label;
/** @var \Magento\Framework\View\Layout\Generator\Container $containerGenerator */
$containerGenerator = $this->generatorPool->getGenerator(Layout\Generator\Container::TYPE);
$containerGenerator->generateContainer($this->structure, $name, $options);
if ($parent) {
$this->structure->setAsChild($name, $parent, $alias);
}
}
/**
* Rename element in layout and layout structure
*
* @param string $oldName
* @param string $newName
* @return bool
*/
public function renameElement($oldName, $newName)
{
$this->build();
if (isset($this->_blocks[$oldName])) {
$block = $this->_blocks[$oldName];
$this->_blocks[$oldName] = null;
unset($this->_blocks[$oldName]);
$this->_blocks[$newName] = $block;
}
$this->structure->renameElement($oldName, $newName);
return $this;
}
/**
* Retrieve all blocks from registry as array
*
* @return array
*/
public function getAllBlocks()
{
$this->build();
return $this->_blocks;
}
/**
* Get block object by name
*
* @param string $name
* @return \Magento\Framework\View\Element\AbstractBlock|bool
*/
public function getBlock($name)
{
$this->build();
if (isset($this->_blocks[$name])) {
return $this->_blocks[$name];
} else {
return false;
}
}
/**
* Get Ui Component object by name
*
* @param string $name
* @return \Magento\Framework\View\Element\AbstractBlock|bool
*/
public function getUiComponent($name)
{
return $this->getBlock($name);
}
/**
* Gets parent name of an element with specified name
*
* @param string $childName
* @return bool|string
*/
public function getParentName($childName)
{
$this->build();
return $this->structure->getParentId($childName);
}
/**
* Get element alias by name
*
* @param string $name
* @return bool|string
*/
public function getElementAlias($name)
{
$this->build();
return $this->structure->getChildAlias($this->structure->getParentId($name), $name);
}
/**
* Add an element to output
*
* @param string $name
* @return $this
*/
public function addOutputElement($name)
{
$this->_output[$name] = $name;
return $this;
}
/**
* Remove an element from output
*
* @param string $name
* @return $this
*/
public function removeOutputElement($name)
{
if (isset($this->_output[$name])) {
unset($this->_output[$name]);
}
return $this;
}
/**
* Get all blocks marked for output
*
* @return string
*/
public function getOutput()
{
$this->build();
$out = '';
foreach ($this->_output as $name) {
$out .= $this->renderElement($name);
}
return $out;
}
/**
* Retrieve messages block
*
* @return \Magento\Framework\View\Element\Messages
*/
public function getMessagesBlock()
{
$this->build();
$block = $this->getBlock('messages');
if ($block) {
return $block;
}
return $this->createBlock(\Magento\Framework\View\Element\Messages::class, 'messages');
}
/**
* Get block singleton
*
* @param string $type
* @return \Magento\Framework\App\Helper\AbstractHelper
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getBlockSingleton($type)
{
if (empty($type)) {
throw new \Magento\Framework\Exception\LocalizedException(
new \Magento\Framework\Phrase('Invalid block type')
);
}
if (!isset($this->sharedBlocks[$type])) {
$this->sharedBlocks[$type] = $this->createBlock($type);
}
return $this->sharedBlocks[$type];
}
/**
* @param string $namespace
* @param string $staticType
* @param string $dynamicType
* @param string $type
* @param string $template