Skip to content

Commit 1023edd

Browse files
committed
Added breadcrumb generation into block
1 parent 263bc61 commit 1023edd

File tree

5 files changed

+107
-2
lines changed

5 files changed

+107
-2
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"magento/magento-composer-installer": "*"
77
},
88
"type": "magento2-module",
9-
"version": "0.1.5",
9+
"version": "0.2.0",
1010
"autoload": {
1111
"files": [
1212
"src/registration.php"

src/Block/Category.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,41 @@ public function __construct(
3131
$this->postApi = $postApi;
3232
}
3333

34+
/**
35+
* override to add in breadcrumbs
36+
* @return mixed
37+
*/
38+
protected function _prepareLayout()
39+
{
40+
$title = $this->getCategory()->getTitle()->getRendered();
41+
if ($breadcrumbsBlock = $this->getLayout()->getBlock('breadcrumbs')) {
42+
$breadcrumbsBlock->addCrumb(
43+
'home',
44+
[
45+
'label' => __('Home'),
46+
'title' => __('Home'),
47+
'link' => $this->_storeManager->getStore()->getBaseUrl()
48+
]
49+
);
50+
$breadcrumbsBlock->addCrumb(
51+
'blog',
52+
[
53+
'label' => __('Blog'),
54+
'title' => __('Blog'),
55+
'link' => $this->_urlBuilder->getUrl('blog')
56+
]
57+
);
58+
$breadcrumbsBlock->addCrumb(
59+
'post',
60+
[
61+
'label' => __($title),
62+
'title' => __($title)
63+
]
64+
);
65+
}
66+
return parent::_prepareLayout();
67+
}
68+
3469
/** @return DataObject */
3570
public function getCategory()
3671
{

src/Block/Page.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,41 @@ public function __construct(
2424
$this->registry = $registry;
2525
}
2626

27+
/**
28+
* override to add in breadcrumbs
29+
* @return mixed
30+
*/
31+
protected function _prepareLayout()
32+
{
33+
$title = $this->getPage()->getTitle()->getRendered();
34+
if ($breadcrumbsBlock = $this->getLayout()->getBlock('breadcrumbs')) {
35+
$breadcrumbsBlock->addCrumb(
36+
'home',
37+
[
38+
'label' => __('Home'),
39+
'title' => __('Home'),
40+
'link' => $this->_storeManager->getStore()->getBaseUrl()
41+
]
42+
);
43+
$breadcrumbsBlock->addCrumb(
44+
'blog',
45+
[
46+
'label' => __('Blog'),
47+
'title' => __('Blog'),
48+
'link' => $this->_urlBuilder->getUrl('blog')
49+
]
50+
);
51+
$breadcrumbsBlock->addCrumb(
52+
'post',
53+
[
54+
'label' => __($title),
55+
'title' => __($title)
56+
]
57+
);
58+
}
59+
return parent::_prepareLayout();
60+
}
61+
2762
/** @return DataObject */
2863
public function getPage()
2964
{

src/Block/Post.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,41 @@ public function __construct(
3131
$this->mediaApi = $mediaApi;
3232
}
3333

34+
/**
35+
* override to add in breadcrumbs
36+
* @return mixed
37+
*/
38+
protected function _prepareLayout()
39+
{
40+
$title = $this->getPost()->getTitle()->getRendered();
41+
if ($breadcrumbsBlock = $this->getLayout()->getBlock('breadcrumbs')) {
42+
$breadcrumbsBlock->addCrumb(
43+
'home',
44+
[
45+
'label' => __('Home'),
46+
'title' => __('Home'),
47+
'link' => $this->_storeManager->getStore()->getBaseUrl()
48+
]
49+
);
50+
$breadcrumbsBlock->addCrumb(
51+
'blog',
52+
[
53+
'label' => __('Blog'),
54+
'title' => __('Blog'),
55+
'link' => $this->_urlBuilder->getUrl('blog')
56+
]
57+
);
58+
$breadcrumbsBlock->addCrumb(
59+
'post',
60+
[
61+
'label' => __($title),
62+
'title' => __($title)
63+
]
64+
);
65+
}
66+
return parent::_prepareLayout();
67+
}
68+
3469
/** @return DataObject */
3570
public function getPost()
3671
{

src/etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0"?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
3-
<module name="Skywire_WordpressApi" setup_version="0.1.5">
3+
<module name="Skywire_WordpressApi" setup_version="0.2.0">
44
</module>
55
</config>

0 commit comments

Comments
 (0)