本文整理汇总了PHP中Magento\Framework\View\Result\Page::getLayout方法的典型用法代码示例。如果您正苦于以下问题:PHP Page::getLayout方法的具体用法?PHP Page::getLayout怎么用?PHP Page::getLayout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\View\Result\Page
的用法示例。
在下文中一共展示了Page::getLayout方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testInitProductLayout
/**
* @magentoAppIsolation enabled
* @magentoAppArea frontend
*/
public function testInitProductLayout()
{
$uniqid = uniqid();
/** @var $product \Magento\Catalog\Model\Product */
$product = $this->objectManager->create('Magento\\Catalog\\Model\\Product');
$product->setTypeId(\Magento\Catalog\Model\Product\Type::DEFAULT_TYPE)->setId(99)->setUrlKey($uniqid);
/** @var $objectManager \Magento\TestFramework\ObjectManager */
$objectManager = $this->objectManager;
$objectManager->get('Magento\\Framework\\Registry')->register('product', $product);
$this->_helper->initProductLayout($this->page, $product);
/** @var \Magento\Framework\View\Page\Config $pageConfig */
$pageConfig = $this->objectManager->get('Magento\\Framework\\View\\Page\\Config');
$bodyClass = $pageConfig->getElementAttribute(\Magento\Framework\View\Page\Config::ELEMENT_TYPE_BODY, \Magento\Framework\View\Page\Config::BODY_ATTRIBUTE_CLASS);
$this->assertContains("product-{$uniqid}", $bodyClass);
$handles = $this->page->getLayout()->getUpdate()->getHandles();
$this->assertContains('catalog_product_view_type_simple', $handles);
}
示例2: getLayout
/**
* {@inheritdoc}
*/
public function getLayout()
{
$pluginInfo = $this->pluginList->getNext($this->subjectType, 'getLayout');
if (!$pluginInfo) {
return parent::getLayout();
} else {
return $this->___callPlugins('getLayout', func_get_args(), $pluginInfo);
}
}
示例3: initProductLayout
/**
* Init layout for viewing product page
*
* @param \Magento\Framework\View\Result\Page $resultPage
* @param \Magento\Catalog\Model\Product $product
* @param null|\Magento\Framework\Object $params
* @return \Magento\Catalog\Helper\Product\View
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function initProductLayout(ResultPage $resultPage, $product, $params = null)
{
$settings = $this->_catalogDesign->getDesignSettings($product);
$pageConfig = $resultPage->getConfig();
if ($settings->getCustomDesign()) {
$this->_catalogDesign->applyCustomDesign($settings->getCustomDesign());
}
// Apply custom page layout
if ($settings->getPageLayout()) {
$pageConfig->setPageLayout($settings->getPageLayout());
}
$urlSafeSku = rawurlencode($product->getSku());
// Load default page handles and page configurations
if ($params && $params->getBeforeHandles()) {
foreach ($params->getBeforeHandles() as $handle) {
$resultPage->addPageLayoutHandles(['id' => $product->getId(), 'sku' => $urlSafeSku, 'type' => $product->getTypeId()], $handle);
}
}
$resultPage->addPageLayoutHandles(['id' => $product->getId(), 'sku' => $urlSafeSku, 'type' => $product->getTypeId()]);
if ($params && $params->getAfterHandles()) {
foreach ($params->getAfterHandles() as $handle) {
$resultPage->addPageLayoutHandles(['id' => $product->getId(), 'sku' => $urlSafeSku, 'type' => $product->getTypeId()], $handle);
}
}
// Apply custom layout update once layout is loaded
$update = $resultPage->getLayout()->getUpdate();
$layoutUpdates = $settings->getLayoutUpdates();
if ($layoutUpdates) {
if (is_array($layoutUpdates)) {
foreach ($layoutUpdates as $layoutUpdate) {
$update->addUpdate($layoutUpdate);
}
}
}
$currentCategory = $this->_coreRegistry->registry('current_category');
$controllerClass = $this->_request->getFullActionName();
if ($controllerClass != 'catalog-product-view') {
$pageConfig->addBodyClass('catalog-product-view');
}
$pageConfig->addBodyClass('product-' . $product->getUrlKey());
if ($currentCategory instanceof \Magento\Catalog\Model\Category) {
$pageConfig->addBodyClass('categorypath-' . $this->categoryUrlPathGenerator->getUrlPath($currentCategory))->addBodyClass('category-' . $currentCategory->getUrlKey());
}
return $this;
}
示例4: getBreadcrumbs
/**
* Get Breadcrumbs for current controller action
*
* @param \Magento\Framework\View\Result\Page $resultPage
* @return void
*/
public function getBreadcrumbs(\Magento\Framework\View\Result\Page $resultPage)
{
$breadcrumbs = $resultPage->getLayout()->getBlock('breadcrumbs');
$breadcrumbs->addCrumb('home', ['label' => __('Home'), 'title' => __('Go to Home Page'), 'link' => $this->_storeManager->getStore()->getBaseUrl()]);
$breadcrumbs->addCrumb('cms_page', ['label' => __('Order Information'), 'title' => __('Order Information')]);
}
示例5: prepareAndRender
/**
* Prepares product view page - inits layout and all needed stuff
*
* $params can have all values as $params in \Magento\Catalog\Helper\Product - initProduct().
* Plus following keys:
* - 'buy_request' - \Magento\Framework\DataObject holding buyRequest to configure product
* - 'specify_options' - boolean, whether to show 'Specify options' message
* - 'configure_mode' - boolean, whether we're in Configure-mode to edit product configuration
*
* @param \Magento\Framework\View\Result\Page $resultPage
* @param int $productId
* @param \Magento\Framework\App\Action\Action $controller
* @param null|\Magento\Framework\DataObject $params
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @return \Magento\Catalog\Helper\Product\View
*/
public function prepareAndRender(ResultPage $resultPage, $productId, $controller, $params = null)
{
/**
* Remove default action handle from layout update to avoid its usage during processing of another action,
* It is possible that forwarding to another action occurs, e.g. to 'noroute'.
* Default action handle is restored just before the end of current method.
*/
$defaultActionHandle = $resultPage->getDefaultLayoutHandle();
$handles = $resultPage->getLayout()->getUpdate()->getHandles();
if (in_array($defaultActionHandle, $handles)) {
$resultPage->getLayout()->getUpdate()->removeHandle($resultPage->getDefaultLayoutHandle());
}
if (!$controller instanceof \Magento\Catalog\Controller\Product\View\ViewInterface) {
throw new \Magento\Framework\Exception\LocalizedException(__('Bad controller interface for showing product'));
}
// Prepare data
$productHelper = $this->_catalogProduct;
if (!$params) {
$params = new \Magento\Framework\DataObject();
}
// Standard algorithm to prepare and render product view page
$product = $productHelper->initProduct($productId, $controller, $params);
if (!$product) {
throw new \Magento\Framework\Exception\NoSuchEntityException(__('Product is not loaded'));
}
$buyRequest = $params->getBuyRequest();
if ($buyRequest) {
$productHelper->prepareProductOptions($product, $buyRequest);
}
if ($params->hasConfigureMode()) {
$product->setConfigureMode($params->getConfigureMode());
}
$this->_eventManager->dispatch('catalog_controller_product_view', ['product' => $product]);
$this->_catalogSession->setLastViewedProductId($product->getId());
if (in_array($defaultActionHandle, $handles)) {
$resultPage->addDefaultHandle();
}
$this->initProductLayout($resultPage, $product, $params);
return $this;
}
示例6: getLayout
/**
* Retrieve current layout object
*
* @return \Magento\Framework\View\LayoutInterface
*/
public function getLayout()
{
return $this->page->getLayout();
}