本文整理汇总了PHP中Magento\Framework\View\Layout::createBlock方法的典型用法代码示例。如果您正苦于以下问题:PHP Layout::createBlock方法的具体用法?PHP Layout::createBlock怎么用?PHP Layout::createBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\View\Layout
的用法示例。
在下文中一共展示了Layout::createBlock方法的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: execute
/**
* Categories chooser Action (Ajax request)
*
* @return \Magento\Framework\Controller\Result\Raw
*/
public function execute()
{
$selected = $this->getRequest()->getParam('selected', '');
$isAnchorOnly = $this->getRequest()->getParam('is_anchor_only', 0);
/** @var \Magento\Widget\Block\Adminhtml\Widget\Catalog\Category\Chooser $chooser */
$chooser = $this->layout->createBlock('Magento\\Widget\\Block\\Adminhtml\\Widget\\Catalog\\Category\\Chooser')->setUseMassaction(true)->setId($this->mathRandom->getUniqueHash('categories'))->setIsAnchorOnly($isAnchorOnly)->setSelectedCategories(explode(',', $selected));
/** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
$resultRaw = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_RAW);
return $resultRaw->setContents($chooser->toHtml());
}
示例3: testGetChildBlocks
public function testGetChildBlocks()
{
$parentName = 'parent';
$childrenArray = ['block_name' => 'value1'];
$this->structureMock->expects($this->once())
->method('getChildren')
->with($this->equalTo($parentName))
->will($this->returnValue($childrenArray));
$blockMock = $this->getMockBuilder('Magento\Framework\View\Element\AbstractBlock')
->disableOriginalConstructor()
->getMockForAbstractClass();
$this->structureMock->expects($this->once())
->method('createStructuralElement')
->with(
'block_name',
\Magento\Framework\View\Layout\Element::TYPE_BLOCK,
'Magento\Framework\View\Element\AbstractBlock'
)->willReturn('block_name');
$this->generatorBlockMock->expects($this->once())->method('createBlock')->will($this->returnValue($blockMock));
$this->assertSame(
$blockMock,
$this->model->createBlock('Magento\Framework\View\Element\AbstractBlock', 'block_name', [])
);
$this->assertSame(['value1' => $blockMock], $this->model->getChildBlocks($parentName));
}
示例4: testToHtmlEmptyWebsiteShareNewCustomer
/**
* @magentoConfigFixture customer/account_share/scope 1
*/
public function testToHtmlEmptyWebsiteShareNewCustomer()
{
$block = $this->layout->createBlock('Magento\\Customer\\Block\\Adminhtml\\Edit\\Tab\\View\\Accordion');
$html = $block->toHtml();
$this->assertContains('Wishlist - 0 item(s)', $html);
$this->assertContains('Shopping Cart - 0 item(s)', $html);
}
示例5: testRenameElement
public function testRenameElement()
{
$blockName = 'block';
$expBlockName = 'block_renamed';
$containerName = 'container';
$expContainerName = 'container_renamed';
$block = $this->_layout->createBlock('Magento\\Framework\\View\\Element\\Text', $blockName);
$this->_layout->addContainer($containerName, 'Container');
$this->assertEquals($block, $this->_layout->getBlock($blockName));
$this->_layout->renameElement($blockName, $expBlockName);
$this->assertEquals($block, $this->_layout->getBlock($expBlockName));
$this->_layout->hasElement($containerName);
$this->_layout->renameElement($containerName, $expContainerName);
$this->_layout->hasElement($expContainerName);
}
示例6: createBlock
/**
* {@inheritdoc}
*/
public function createBlock($type, $name = '', array $arguments = array())
{
$pluginInfo = $this->pluginList->getNext($this->subjectType, 'createBlock');
if (!$pluginInfo) {
return parent::createBlock($type, $name, $arguments);
} else {
return $this->___callPlugins('createBlock', func_get_args(), $pluginInfo);
}
}