本文整理汇总了PHP中Magento\Framework\View\Layout::getAllBlocks方法的典型用法代码示例。如果您正苦于以下问题:PHP Layout::getAllBlocks方法的具体用法?PHP Layout::getAllBlocks怎么用?PHP Layout::getAllBlocks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\View\Layout
的用法示例。
在下文中一共展示了Layout::getAllBlocks方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _buildEntries
protected function _buildEntries(&$entries, $block, $alias, $level)
{
$blocks = $this->_layout->getAllBlocks();
$extras = array();
$extras[] = count($block->getChild()) ? count($block->getChild()) : "-";
$extras[] = $block->getType();
if ($block->getType() === 'cms/block') {
$extras[] = $block->getBlockId();
} elseif ($block->getType() == 'cms/page') {
$extras[] = $block->getPage()->getIdentifier();
} elseif ($template = $block->getTemplate()) {
$extras[] = $template;
} else {
$extras[] = '-';
}
$extras[] = get_class($block);
// sprintf("$offset%s %s\n", $alias, $this->_colorize($extraString, self::COLOR_DARK_GRAY))
$name = $block->getNameInLayout();
$entry = array('name' => $name, 'alias' => $alias, 'level' => $level, 'extras' => $extras);
$profileName = "BLOCK: {$name}";
if (isset($this->timers[$profileName])) {
$entry['time'] = $this->timers[$profileName]['sum'] * 1000;
}
$entries[] = $entry;
foreach ($block->getChild() as $alias => $childBlock) {
$this->_buildEntries($entries, $childBlock, $alias, $level + 1);
}
}
示例2: testRenameElement
public function testRenameElement()
{
$oldName = 'old_name';
$newName = 'new_name';
$blockMock = $this->getMockBuilder('Magento\\Framework\\View\\Element\\AbstractBlock')->disableOriginalConstructor()->getMockForAbstractClass();
$this->structureMock->expects($this->once())->method('renameElement')->with($this->equalTo($oldName), $this->equalTo($newName))->will($this->returnSelf());
$this->assertSame($this->model, $this->model->setBlock($oldName, $blockMock));
$this->assertSame($this->model, $this->model->renameElement($oldName, $newName));
$this->assertSame([$newName => $blockMock], $this->model->getAllBlocks());
}
示例3: testGenerateGetAllBlocks
/**
* A smoke test for generating elements
*
* See sophisticated tests at \Magento\Framework\View\LayoutDirectivesTest
* @see \Magento\Framework\View\LayoutDirectivesTest
* @magentoAppIsolation enabled
*/
public function testGenerateGetAllBlocks()
{
$this->_layout->setXml(simplexml_load_string('<layout>
<block class="Magento\\Framework\\View\\Element\\Text" name="block1">
<block class="Magento\\Framework\\View\\Element\\Text"/>
</block>
<block class="Magento\\Framework\\View\\Element\\Text" template="test" ttl="360"/>
<block class="Magento\\Framework\\View\\Element\\Text"/>
</layout>', 'Magento\\Framework\\View\\Layout\\Element'));
$this->assertEquals([], $this->_layout->getAllBlocks());
$this->_layout->generateElements();
$expected = ['block1', 'block1_schedule_block0', 'schedule_block1', 'schedule_block2'];
$this->assertSame($expected, array_keys($this->_layout->getAllBlocks()));
$child = $this->_layout->getBlock('block1_schedule_block0');
$this->assertSame($this->_layout->getBlock('block1'), $child->getParentBlock());
$this->assertEquals('test', $this->_layout->getBlock('schedule_block1')->getData('template'));
$this->assertEquals('360', $this->_layout->getBlock('schedule_block1')->getData('ttl'));
$this->assertFalse($this->_layout->getBlock('nonexisting'));
}
示例4: afterGetOutput
/**
* Retrieve all identities from blocks for further cache invalidation
*
* @param \Magento\Framework\View\Layout $subject
* @param mixed $result
* @return mixed
*/
public function afterGetOutput(\Magento\Framework\View\Layout $subject, $result)
{
if ($this->layout->isCacheable() && $this->config->isEnabled()) {
$tags = array();
foreach ($this->layout->getAllBlocks() as $block) {
if ($block instanceof \Magento\Framework\View\Block\IdentityInterface) {
$isEsiBlock = $block->getTtl() > 0;
$isVarnish = $this->config->getType() == \Magento\PageCache\Model\Config::VARNISH;
if ($isVarnish && $isEsiBlock) {
continue;
}
$tags = array_merge($tags, $block->getIdentities());
}
}
$tags = array_unique($tags);
$this->response->setHeader('X-Magento-Tags', implode(',', $tags));
}
return $result;
}
示例5: afterGetOutput
/**
* Set X-Cache-Tags header with all the Magento Cache Tags so
* they can be purged by the CloudFlare API
*
* @param \Magento\Framework\View\Layout $subject
* @param $result
* @return mixed
*/
public function afterGetOutput(\Magento\Framework\View\Layout $subject, $result)
{
if (!$subject->isCacheable() || !$this->config->isEnabled()) {
return $result;
}
$tags = [];
foreach ($subject->getAllBlocks() as $block) {
if ($block->getIdentities() !== null) {
$tags = array_merge($tags, $block->getIdentities());
}
}
$tags = array_unique($tags);
$this->cacheTagsUtil->setCloudFlareCacheTagsResponseHeader($this->response, $tags);
return $result;
}
示例6: getAllBlocks
/**
* {@inheritdoc}
*/
public function getAllBlocks()
{
$pluginInfo = $this->pluginList->getNext($this->subjectType, 'getAllBlocks');
if (!$pluginInfo) {
return parent::getAllBlocks();
} else {
return $this->___callPlugins('getAllBlocks', func_get_args(), $pluginInfo);
}
}