本文整理汇总了PHP中Magento\Framework\View\LayoutInterface::getBlock方法的典型用法代码示例。如果您正苦于以下问题:PHP LayoutInterface::getBlock方法的具体用法?PHP LayoutInterface::getBlock怎么用?PHP LayoutInterface::getBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\View\LayoutInterface
的用法示例。
在下文中一共展示了LayoutInterface::getBlock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setGoogleAnalyticsOnOrderSuccessPageView
/**
* Add order information into GA block to render on checkout success pages
*
* @param EventObserver $observer
* @return void
*/
public function setGoogleAnalyticsOnOrderSuccessPageView(EventObserver $observer)
{
$orderIds = $observer->getEvent()->getOrderIds();
if (empty($orderIds) || !is_array($orderIds)) {
return;
}
$block = $this->_layout->getBlock('google_analytics');
if ($block) {
$block->setOrderIds($orderIds);
}
}
示例2: execute
/**
* Add order information into GA block to render on checkout success pages
*
* @param EventObserver $observer
* @return void
*/
public function execute(EventObserver $observer)
{
$orderIds = $observer->getEvent()->getOrderIds();
if (empty($orderIds) || !is_array($orderIds)) {
return;
}
$block = $this->_layout->getBlock('magepal_gtm_datalayer');
if ($block) {
$block->setOrderIds($orderIds);
}
}
示例3: getReviewButtonTemplate
/**
* Get template for button in order review page if HSS method was selected
*
* @param string $name template name
* @param string $block buttons block name
* @return string
*/
public function getReviewButtonTemplate($name, $block)
{
$quote = $this->_checkoutSession->getQuote();
if ($quote) {
$payment = $quote->getPayment();
if ($payment && in_array($payment->getMethod(), $this->_hssMethods)) {
return $name;
}
}
$blockObject = $this->_layout->getBlock($block);
if ($blockObject) {
return $blockObject->getTemplate();
}
return '';
}
示例4: getToolbar
/**
* Return button parent block
*
* @param \Magento\Framework\View\Element\AbstractBlock $context
* @param string $region
* @return \Magento\Backend\Block\Template
*/
protected function getToolbar(\Magento\Framework\View\Element\AbstractBlock $context, $region)
{
$parent = null;
if (!$region || $region == 'header' || $region == 'footer') {
$parent = $context;
} elseif ($region == 'toolbar') {
$parent = $this->layout->getBlock('page.actions.toolbar');
} else {
$parent = $this->layout->getBlock($region);
}
if ($parent) {
return $parent;
}
return $context;
}
示例5: testGridContainsMassactionColumn
public function testGridContainsMassactionColumn()
{
$this->_layout->getBlock('admin.test.grid')->toHtml();
$gridMassactionColumn = $this->_layout->getBlock('admin.test.grid')->getColumnSet()->getChildBlock('massaction');
$this->assertNotNull($gridMassactionColumn, 'Massaction column does not exist in the grid column set');
$this->assertInstanceOf('Magento\\Backend\\Block\\Widget\\Grid\\Column', $gridMassactionColumn, 'Massaction column is not an instance of \\Magento\\Backend\\Block\\Widget\\Column');
}
示例6: testInitProductLayout
/**
* @magentoAppIsolation enabled
* @magentoAppArea frontend
*/
public function testInitProductLayout()
{
$uniqid = uniqid();
/** @var $product \Magento\Catalog\Model\Product */
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
$product->setTypeId(\Magento\Catalog\Model\Product\Type::DEFAULT_TYPE)->setId(99)->setUrlKey($uniqid);
/** @var $objectManager \Magento\TestFramework\ObjectManager */
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$objectManager->get('Magento\\Framework\\Registry')->register('product', $product);
$this->_helper->initProductLayout($product, $this->_controller);
$rootBlock = $this->_layout->getBlock('root');
$this->assertInstanceOf('Magento\\Theme\\Block\\Html', $rootBlock);
$this->assertContains("product-{$uniqid}", $rootBlock->getBodyClass());
$handles = $this->_layout->getUpdate()->getHandles();
$this->assertContains('catalog_product_view_type_simple', $handles);
}
示例7: getBlockHtml
/**
* Retrieve block html
*
* @param string $name
* @return string
*/
public function getBlockHtml($name)
{
$block = $this->_layout->getBlock($name);
if ($block) {
return $block->toHtml();
}
return '';
}
示例8: getUiElementView
/**
* Get UI Element View
*
* @param string $uiElementName
* @return UiComponentInterface
* @throws \InvalidArgumentException
*/
public function getUiElementView($uiElementName)
{
/** @var UiComponentInterface $view */
$view = $this->layout->getBlock($uiElementName);
if (!$view instanceof UiComponentInterface) {
throw new \InvalidArgumentException(sprintf('UI Element "%s" must implement \\Magento\\Framework\\View\\Element\\UiComponentInterface', $uiElementName));
}
return $view;
}
示例9: getProductPriceHtml
/**
* Return HTML block with product price
*
* @param \Magento\Catalog\Model\Product $product
* @return string
*/
public function getProductPriceHtml(\Magento\Catalog\Model\Product $product)
{
$price = '';
/** @var \Magento\Framework\Pricing\Render $priceRender */
$priceRender = $this->layout->getBlock('product.price.render.default');
if (!$priceRender) {
$priceRender = $this->layout->createBlock('Magento\\Framework\\Pricing\\Render', 'product.price.render.default', ['data' => ['price_render_handle' => 'catalog_product_prices']]);
}
if ($priceRender) {
$price = $priceRender->render('wishlist_configured_price', $product, ['zone' => \Magento\Framework\Pricing\Render::ZONE_ITEM_LIST]);
}
return $price;
}
示例10: fire
/**
* Run all methods declared in persistent configuration
*
* @return $this
*/
public function fire()
{
foreach ($this->collectInstancesToEmulate() as $type => $elements) {
if (!is_array($elements)) {
continue;
}
foreach ($elements as $info) {
switch ($type) {
case 'blocks':
$this->fireOne($info, $this->_layout->getBlock($info['name_in_layout']));
break;
}
}
}
return $this;
}
示例11: getCurrentPageLayout
/**
* Retrieve current applied page layout
*
* @return \Magento\Framework\Object|boolean
*/
public function getCurrentPageLayout()
{
if ($this->_layout->getBlock('root') && $this->_layout->getBlock('root')->getLayoutCode()) {
return $this->_config->getPageLayout($this->_layout->getBlock('root')->getLayoutCode());
}
// All loaded handles
$handles = $this->_layout->getUpdate()->getHandles();
// Handles used in page layouts
$pageLayoutHandles = $this->_config->getPageLayoutHandles();
// Applied page layout handles
$appliedHandles = array_intersect($handles, $pageLayoutHandles);
if (empty($appliedHandles)) {
return false;
}
$currentHandle = array_pop($appliedHandles);
$layoutCode = array_search($currentHandle, $pageLayoutHandles, true);
return $this->_config->getPageLayout($layoutCode);
}
示例12: testGetJs
public function testGetJs()
{
$expected = uniqid();
$this->_layout->getBlock('child')->setJs($expected);
$this->assertEquals($expected, $this->_block->getJs());
}
示例13: _applyAccountLinksPersistentData
/**
* Emulate 'account links' block with persistent data
*
* @return void
*/
protected function _applyAccountLinksPersistentData()
{
if (!$this->_layout->getBlock('header.additional')) {
$this->_layout->addBlock('Magento\\Persistent\\Block\\Header\\Additional', 'header.additional');
}
}
示例14: getBlock
/**
* Obtain block object
*
* @param string $name
* @return \Magento\Framework\View\Element\AbstractBlock
*/
public function getBlock($name)
{
return $this->layout->getBlock($name);
}
示例15: _getElementPath
/**
* @param string $nameElement
* @param LayoutInterface $layout
*
* @return null|string
*/
protected function _getElementPath(LayoutInterface $layout, $nameElement)
{
$parentName = $layout->getParentName($nameElement);
if (!$parentName) {
return null;
}
$parentBlock = $layout->getBlock($parentName);
$pathName = $parentBlock ? $parentName : "[{$parentName}]";
$path = isset($parentName) && $parentName !== false ? $this->_getElementPath($layout, $parentName) : null;
return isset($path) ? $path . " / " . $pathName : $pathName;
}