本文整理汇总了PHP中Magento\Framework\View\Layout::getBlock方法的典型用法代码示例。如果您正苦于以下问题:PHP Layout::getBlock方法的具体用法?PHP Layout::getBlock怎么用?PHP Layout::getBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\View\Layout
的用法示例。
在下文中一共展示了Layout::getBlock方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCreateBlockSuccess
public function testCreateBlockSuccess()
{
$blockMock = $this->getMockBuilder('Magento\\Framework\\View\\Element\\AbstractBlock')->disableOriginalConstructor()->getMockForAbstractClass();
$this->_blockFactoryMock->expects($this->once())->method('createBlock')->will($this->returnValue($blockMock));
$this->_model->createBlock('type', 'blockname', array());
$this->assertInstanceOf('Magento\\Framework\\View\\Element\\AbstractBlock', $this->_model->getBlock('blockname'));
}
示例2: testCreateBlockSuccess
public function testCreateBlockSuccess()
{
$blockMock = $this->getMockBuilder('Magento\\Framework\\View\\Element\\AbstractBlock')->disableOriginalConstructor()->getMockForAbstractClass();
$this->structureMock->expects($this->once())->method('createStructuralElement')->with('blockname', \Magento\Framework\View\Layout\Element::TYPE_BLOCK, 'type')->willReturn('blockname');
$this->generatorBlockMock->expects($this->once())->method('createBlock')->will($this->returnValue($blockMock));
$this->model->createBlock('type', 'blockname', []);
$this->assertInstanceOf('Magento\\Framework\\View\\Element\\AbstractBlock', $this->model->getBlock('blockname'));
$this->assertFalse($this->model->getBlock('not_exist'));
}
示例3: testGetBlock
public function testGetBlock()
{
$this->assertFalse($this->_layout->getBlock('test'));
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\Layout')->createBlock('Magento\\Framework\\View\\Element\\Text');
$this->_layout->setBlock('test', $block);
$this->assertSame($block, $this->_layout->getBlock('test'));
}
示例4: getBlockExtras
public function getBlockExtras($name, $data)
{
if (isset($data['type'])) {
$extras[] = $data['type'];
}
$block = $this->_layout->getBlock($name);
if ($block) {
if ($block instanceof \Magento\Cms\Block\Block) {
$extras[] = $block->getBlockId();
}
if ($block instanceof \Magento\Cms\Block\Page) {
$extras[] = $block->getPage()->getIdentifier();
}
if ($block instanceof \Magento\Framework\View\Element\Template) {
$extras[] = $block->getTemplate();
}
$extras[] = $block->getType();
}
return $extras;
}
示例5: buildEntries
protected function buildEntries(MagentoLayout $layout, &$structure, $name = 'root', $alias = '', $level = 0)
{
if (!isset($structure[$name])) {
return [];
}
$instance = $layout->getBlock($name);
$block = $structure[$name];
$entries = [];
$entries[] = ['level' => $level, 'name' => $name, 'alias' => $alias, 'type' => $block['type'], 'label' => isset($block['label']) ? $block['label'] : '', 'extra' => array_filter(['htmlTag' => isset($block['htmlTag']) ? $block['htmlTag'] : '', 'htmlId' => isset($block['htmlId']) ? $block['htmlId'] : '', 'htmlClass' => isset($block['htmlClass']) ? $block['htmlClass'] : '', 'template' => $instance ? $instance->getTemplate() : ''])];
if (isset($block['children'])) {
foreach ($block['children'] as $child => $alias) {
$entries = array_merge($entries, $this->buildEntries($layout, $structure, $child, $alias, $level + 1));
}
}
return $entries;
}
示例6: getBlock
/**
* {@inheritdoc}
*/
public function getBlock($name)
{
$pluginInfo = $this->pluginList->getNext($this->subjectType, 'getBlock');
if (!$pluginInfo) {
return parent::getBlock($name);
} else {
return $this->___callPlugins('getBlock', func_get_args(), $pluginInfo);
}
}