-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for translation not working in graphql
- Loading branch information
1 parent
bc80aa8
commit 9b3b3f6
Showing
2 changed files
with
102 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
/** | ||
* ScandiPWA_CmsGraphQl | ||
* | ||
* @category Scandiweb | ||
* @package ScandiPWA_CmsGraphQl | ||
* @copyright Copyright (c) 2022 Scandiweb, Ltd (https://scandiweb.com) | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace ScandiPWA\CmsGraphQl\Plugin; | ||
|
||
use Exception; | ||
use Magento\Framework\App\Area; | ||
use Magento\Framework\App\FrontControllerInterface; | ||
use Magento\Framework\App\AreaList; | ||
use Magento\Framework\App\RequestInterface; | ||
use Magento\Framework\App\State; | ||
use Magento\Framework\Exception\LocalizedException; | ||
use ScandiPWA\PersistedQuery\Plugin\PersistedQuery; | ||
|
||
/** | ||
* Class InitGraphQlTranslations | ||
* | ||
* A fix for https://github.com/magento/magento2/issues/31351 | ||
* | ||
* @see \Magento\Framework\App\Action\Plugin\Design | ||
* @see \Magento\Webapi\Controller\Soap | ||
* @package ScandiPWA\CmsGraphQl\Plugin | ||
*/ | ||
class InitGraphQlTranslations | ||
{ | ||
/** | ||
* Application | ||
* | ||
* @var AreaList | ||
*/ | ||
protected $areaList; | ||
|
||
/** | ||
* State | ||
* | ||
* @var State | ||
*/ | ||
protected $appState; | ||
|
||
/** | ||
* @param AreaList $areaList | ||
* @param State $appState | ||
*/ | ||
public function __construct( | ||
AreaList $areaList, | ||
State $appState | ||
) { | ||
$this->areaList = $areaList; | ||
$this->appState = $appState; | ||
} | ||
|
||
/** | ||
* @param FrontControllerInterface $subject | ||
* @param RequestInterface $request | ||
* | ||
* @return void | ||
* @throws Exception | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function beforeDispatch( | ||
FrontControllerInterface $subject, | ||
RequestInterface $request | ||
) { | ||
$area = $this->areaList->getArea($this->appState->getAreaCode()); | ||
if ($area) { | ||
$area->load(Area::PART_TRANSLATE); | ||
} | ||
} | ||
|
||
/** | ||
* @param PersistedQuery $subject | ||
* @param RequestInterface $request | ||
* @return void | ||
* @throws LocalizedException | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function beforeProcessRequest( | ||
PersistedQuery $subject, | ||
RequestInterface $request | ||
) { | ||
$area = $this->areaList->getArea($this->appState->getAreaCode()); | ||
if ($area) { | ||
$area->load(Area::PART_TRANSLATE); | ||
} | ||
} | ||
} |
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