This repository has been archived by the owner on Jun 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #179 from afirlejczyk/bugfix/set-store-in-cms-rebuild
Emulate store when rebuilding cms block and pages #77.
- Loading branch information
Showing
8 changed files
with
196 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ | |
|
||
## Unreleased | ||
|
||
### Fixed | ||
- Emulate store when rebuilding cms block and pages. | ||
|
||
|
||
## [1.8.3] (2019.12.19) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/module-vsbridge-indexer-cms/Model/Indexer/DataProvider/Block/ContentData.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php declare(strict_types = 1); | ||
/** | ||
* @package Divante\VsbridgeIndexerCms | ||
* @author Agata Firlejczyk <afirlejczyk@divante.pl> | ||
* @copyright 2019 Divante Sp. z o.o. | ||
* @license See LICENSE_DIVANTE.txt for license details. | ||
*/ | ||
|
||
namespace Divante\VsbridgeIndexerCms\Model\Indexer\DataProvider\Block; | ||
|
||
use Divante\VsbridgeIndexerCms\Model\Indexer\DataProvider\CmsContentFilter; | ||
use Divante\VsbridgeIndexerCore\Api\DataProviderInterface; | ||
|
||
/** | ||
* Class ContentData | ||
*/ | ||
class ContentData implements DataProviderInterface | ||
{ | ||
/** | ||
* @var CmsContentFilter | ||
*/ | ||
private $cmsContentFilter; | ||
|
||
/** | ||
* ContentData constructor. | ||
* | ||
* @param CmsContentFilter $cmsContentFilter | ||
*/ | ||
public function __construct(CmsContentFilter $cmsContentFilter) | ||
{ | ||
$this->cmsContentFilter = $cmsContentFilter; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function addData(array $indexData, $storeId) | ||
{ | ||
return $this->cmsContentFilter->filter($indexData, $storeId, 'block'); | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
src/module-vsbridge-indexer-cms/Model/Indexer/DataProvider/CmsContentFilter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php declare(strict_types = 1); | ||
/** | ||
* @package Divante\VsbridgeIndexerCms | ||
* @author Agata Firlejczyk <afirlejczyk@divante.pl> | ||
* @copyright 2019 Divante Sp. z o.o. | ||
* @license See LICENSE_DIVANTE.txt for license details. | ||
*/ | ||
|
||
namespace Divante\VsbridgeIndexerCms\Model\Indexer\DataProvider; | ||
|
||
use Divante\VsbridgeIndexerCms\Api\ContentProcessorInterface; | ||
use Magento\Cms\Model\Template\FilterProvider; | ||
use Magento\Framework\App\Area; | ||
use Magento\Framework\App\AreaList; | ||
use Magento\Store\Model\App\Emulation; | ||
|
||
/** | ||
* Class AbstractContentData | ||
*/ | ||
class CmsContentFilter | ||
{ | ||
/** | ||
* @var \Magento\Cms\Model\Template\FilterProvider | ||
*/ | ||
private $filterProvider; | ||
|
||
/** | ||
* @var AreaList | ||
*/ | ||
private $areaList; | ||
|
||
/** | ||
* @var Emulation | ||
*/ | ||
private $appEmulation; | ||
|
||
/** | ||
* @var ContentProcessorInterface | ||
*/ | ||
private $contentProcessor; | ||
|
||
/** | ||
* CmsBlock constructor. | ||
* | ||
* @param AreaList $areaList | ||
* @param Emulation $emulation | ||
* @param ContentProcessorInterface $contentProcessor | ||
* @param FilterProvider $filterProvider | ||
*/ | ||
public function __construct( | ||
AreaList $areaList, | ||
Emulation $emulation, | ||
ContentProcessorInterface $contentProcessor, | ||
FilterProvider $filterProvider | ||
) { | ||
$this->areaList = $areaList; | ||
$this->appEmulation = $emulation; | ||
$this->filterProvider = $filterProvider; | ||
$this->contentProcessor = $contentProcessor; | ||
} | ||
|
||
/** | ||
* @param array $indexData | ||
* @param int $storeId | ||
* @param string $type | ||
* | ||
* @return array | ||
* @throws Exception | ||
*/ | ||
public function filter(array $indexData, int $storeId, string $type) | ||
{ | ||
$this->appEmulation->startEnvironmentEmulation($storeId); | ||
$this->areaList->getArea(Area::AREA_FRONTEND)->load(Area::PART_DESIGN); | ||
$templateFilter = $this->geTemplateFilter($type)->setStoreId($storeId); | ||
|
||
foreach ($indexData as &$cms) { | ||
$cms['content'] = $this->contentProcessor->parse($templateFilter, $cms['content']); | ||
} | ||
|
||
$this->appEmulation->stopEnvironmentEmulation(); | ||
|
||
return $indexData; | ||
} | ||
|
||
/** | ||
* @param string $type | ||
* | ||
* @return \Magento\Framework\Filter\Template | ||
*/ | ||
private function geTemplateFilter(string $type): \Magento\Framework\Filter\Template | ||
{ | ||
return $type === 'block' ? $this->filterProvider->getBlockFilter() : $this->filterProvider->getPageFilter(); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/module-vsbridge-indexer-cms/Model/Indexer/DataProvider/Page/ContentData.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php declare(strict_types = 1); | ||
/** | ||
* @package Divante\VsbridgeIndexerCms | ||
* @author Agata Firlejczyk <afirlejczyk@divante.pl> | ||
* @copyright 2019 Divante Sp. z o.o. | ||
* @license See LICENSE_DIVANTE.txt for license details. | ||
*/ | ||
|
||
namespace Divante\VsbridgeIndexerCms\Model\Indexer\DataProvider\Page; | ||
|
||
use Divante\VsbridgeIndexerCms\Model\Indexer\DataProvider\CmsContentFilter; | ||
use Divante\VsbridgeIndexerCore\Api\DataProviderInterface; | ||
|
||
/** | ||
* Class ContentData | ||
*/ | ||
class ContentData implements DataProviderInterface | ||
{ | ||
/** | ||
* @var CmsContentFilter | ||
*/ | ||
private $cmsContentFilter; | ||
|
||
/** | ||
* ContentData constructor. | ||
* | ||
* @param CmsContentFilter $cmsContentFilter | ||
*/ | ||
public function __construct(CmsContentFilter $cmsContentFilter) | ||
{ | ||
$this->cmsContentFilter = $cmsContentFilter; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function addData(array $indexData, $storeId) | ||
{ | ||
return $this->cmsContentFilter->filter($indexData, $storeId, 'page'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters