88
99namespace Magefan \Blog \Block \Archive ;
1010
11- use Magefan \Blog \Block \Post \PostList \Toolbar ;
1211use Magento \Store \Model \ScopeInterface ;
1312
1413/**
1514 * Blog archive posts list
1615 */
1716class PostList extends \Magefan \Blog \Block \Post \PostList
1817{
18+ use Archive;
19+
1920 /**
2021 * Prepare posts collection
2122 * @return \Magefan\Blog\Model\ResourceModel\Post\Collection
@@ -29,37 +30,22 @@ protected function _preparePostCollection()
2930 );
3031 }
3132
32- /**
33- * Get archive month
34- * @return int
35- */
36- public function getMonth ()
37- {
38- return (int )$ this ->_coreRegistry ->registry ('current_blog_archive_month ' );
39- }
40-
41- /**
42- * Get archive year
43- * @return int
44- */
45- public function getYear ()
46- {
47- return (int )$ this ->_coreRegistry ->registry ('current_blog_archive_year ' );
48- }
49-
5033 /**
5134 * Preparing global layout
5235 *
5336 * @return $this
5437 */
5538 protected function _prepareLayout ()
5639 {
57- $ title = $ this ->_getTitle ( );
40+ $ title = $ this ->filterContent (( string ) $ this -> _getConfigValue ( ' title ' ) );
5841 $ this ->_addBreadcrumbs ($ title , 'blog_search ' );
59- $ this ->pageConfig ->getTitle ()->set ($ title );
6042
61- $ this ->pageConfig ->setKeywords ($ this ->replaceVars ($ this ->_getConfigValue ('meta_keywords ' )));
62- $ this ->pageConfig ->setDescription ($ this ->replaceVars ($ this ->_getConfigValue ('meta_description ' )));
43+ $ this ->pageConfig ->getTitle ()->set (
44+ $ this ->_getConfigValue ('meta_title ' ) ? $ this ->filterContent ($ this ->_getConfigValue ('meta_title ' )) : $ title
45+ );
46+
47+ $ this ->pageConfig ->setKeywords ($ this ->filterContent ((string )$ this ->_getConfigValue ('meta_keywords ' )));
48+ $ this ->pageConfig ->setDescription ($ this ->filterContent ((string )$ this ->_getConfigValue ('meta_description ' )));
6349
6450 if ($ this ->config ->getDisplayCanonicalTag (\Magefan \Blog \Model \Config::CANONICAL_PAGE_TYPE_ARCHIVE )) {
6551 $ month = '' ;
@@ -94,16 +80,6 @@ protected function _prepareLayout()
9480 return parent ::_prepareLayout ();
9581 }
9682
97- /**
98- * Retrieve title
99- * @return string
100- */
101- protected function _getTitle ()
102- {
103- return (string )$ this ->replaceVars ($ this ->_getConfigValue ('meta_title ' ) ?: $ this ->_getConfigValue ('title ' ));
104- }
105-
106-
10783 /**
10884 * @param $param
10985 * @return mixed
@@ -116,32 +92,4 @@ protected function _getConfigValue($param)
11692 );
11793 }
11894
119- /**
120- * @param $content
121- * @return array|mixed|string|string[]
122- */
123- private function replaceVars ($ content )
124- {
125- if (!$ content ) {
126- return '' ;
127- }
128- $ vars = ['year ' , 'month ' ];
129- $ values = [];
130- foreach ($ vars as $ var ) {
131- $ schemaVar = '{{ ' . $ var . '}} ' ;
132- if ($ content && strpos ($ content , $ schemaVar ) !== false ) {
133- switch ($ var ) {
134- case 'year ' :
135- $ values [$ var ] = date ('Y ' , strtotime ($ this ->getYear () . '-01-01 ' ));
136- break ;
137- case 'month ' :
138- $ values [$ var ] = date ('F ' , strtotime ($ this ->getYear () . '- ' . $ this ->getMonth () . '-01 ' ));
139- break ;
140- }
141- $ content = str_replace ($ schemaVar , $ values [$ var ] ?? '' , $ content );
142- }
143-
144- }
145- return $ content ;
146- }
14795}
0 commit comments