123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- /**
- * Copyright © 2015-2017 Ihor Vansach (ihor@magefan.com). All rights reserved.
- * See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
- *
- * Glory to Ukraine! Glory to the heroes!
- */
- namespace Magefan\Blog\Block\Post;
- use Magento\Store\Model\ScopeInterface;
- /**
- * Blog post view
- */
- class View extends AbstractPost
- {
- /**
- * Preparing global layout
- *
- * @return $this
- */
- protected function _prepareLayout()
- {
- $post = $this->getPost();
- if ($post) {
- $this->_addBreadcrumbs($post->getTitle(), 'blog_post');
- $this->pageConfig->addBodyClass('blog-post-' . $post->getIdentifier());
- $this->pageConfig->getTitle()->set($post->getMetaTitle());
- $this->pageConfig->setKeywords($post->getMetaKeywords());
- $this->pageConfig->setDescription($post->getMetaDescription());
- $this->pageConfig->addRemotePageAsset(
- $post->getCanonicalUrl(),
- 'canonical',
- ['attributes' => ['rel' => 'canonical']]
- );
- $pageMainTitle = $this->getLayout()->getBlock('page.main.title');
- if ($pageMainTitle) {
- $pageMainTitle->setPageTitle(
- $this->escapeHtml($post->getTitle())
- );
- }
- if ($post->getIsPreviewMode()) {
- $this->pageConfig->setRobots('NOINDEX,FOLLOW');
- }
- }
- return parent::_prepareLayout();
- }
- /**
- * Prepare breadcrumbs
- *
- * @param string $title
- * @param string $key
- * @throws \Magento\Framework\Exception\LocalizedException
- * @return void
- */
- protected function _addBreadcrumbs($title = null, $key = null)
- {
- if ($this->_scopeConfig->getValue('web/default/show_cms_breadcrumbs', ScopeInterface::SCOPE_STORE)
- && ($breadcrumbsBlock = $this->getLayout()->getBlock('breadcrumbs'))
- ) {
- $breadcrumbsBlock->addCrumb(
- 'home',
- [
- 'label' => __('Home'),
- 'title' => __('Go to Home Page'),
- 'link' => $this->_storeManager->getStore()->getBaseUrl()
- ]
- );
- $blogTitle = $this->_scopeConfig->getValue(
- 'mfblog/index_page/title',
- ScopeInterface::SCOPE_STORE
- );
- $breadcrumbsBlock->addCrumb(
- 'blog',
- [
- 'label' => __($blogTitle),
- 'title' => __($blogTitle),
- 'link' => $this->_url->getBaseUrl()
- ]
- );
- $parentCategories = [];
- $parentCategory = $this->getPost()->getParentCategory();
- while ($parentCategory ) {
- $parentCategories[] = $parentCategory;
- $parentCategory = $parentCategory->getParentCategory();
- }
- for ($i = count($parentCategories) - 1; $i >= 0; $i--) {
- $parentCategory = $parentCategories[$i];
- $breadcrumbsBlock->addCrumb('blog_parent_category_' . $parentCategory->getId(), [
- 'label' => $parentCategory->getTitle(),
- 'title' => $parentCategory->getTitle(),
- 'link' => $parentCategory->getCategoryUrl()
- ]);
- }
- $breadcrumbsBlock->addCrumb($key, [
- 'label' => $title ,
- 'title' => $title
- ]);
- }
- }
- }
|