Skip to content

Commit

Permalink
Magento 2.3.2 - PWA - graphQl fetching Issue for phtml file called in…
Browse files Browse the repository at this point in the history
… static block #960
  • Loading branch information
XxXgeoXxX committed Oct 18, 2019
1 parent 0ee4cdd commit 30eebde
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 28 deletions.
29 changes: 2 additions & 27 deletions app/code/Magento/CmsGraphQl/Model/Resolver/DataProvider/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Magento\Cms\Api\Data\BlockInterface;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Widget\Model\Template\FilterEmulate;
use Magento\Framework\App\State;

/**
* Cms block data provider
Expand All @@ -28,24 +27,16 @@ class Block
*/
private $widgetFilter;

/**
* @var State
*/
private $state;

/**
* @param BlockRepositoryInterface $blockRepository
* @param FilterEmulate $widgetFilter
* @param State $state
*/
public function __construct(
BlockRepositoryInterface $blockRepository,
FilterEmulate $widgetFilter,
State $state
FilterEmulate $widgetFilter
) {
$this->blockRepository = $blockRepository;
$this->widgetFilter = $widgetFilter;
$this->state = $state;
}

/**
Expand All @@ -65,11 +56,7 @@ public function getData(string $blockIdentifier): array
);
}

$renderedContent = $this->state->emulateAreaCode(
\Magento\Framework\App\Area::AREA_FRONTEND,
[$this, 'getRenderedBlockContent'],
[$block->getContent()]
);
$renderedContent = $this->widgetFilter->filter($block->getContent());

$blockData = [
BlockInterface::BLOCK_ID => $block->getId(),
Expand All @@ -79,16 +66,4 @@ public function getData(string $blockIdentifier): array
];
return $blockData;
}

/**
* Get block data as it rendered on frontend
*
* @param string $blockContent
*
* @return string
*/
public function getRenderedBlockContent(string $blockContent) : string
{
return $this->widgetFilter->filter($blockContent);
}
}
17 changes: 16 additions & 1 deletion app/code/Magento/Widget/Model/Template/FilterEmulate.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
Expand All @@ -17,4 +17,19 @@ public function widgetDirective($construction)
{
return $this->_appState->emulateAreaCode('frontend', [$this, 'generateWidget'], [$construction]);
}

/**
* @param string $value
*
* @return string
* @throws \Exception
*/
public function filter($value) : string
{
return $this->_appState->emulateAreaCode(
\Magento\Framework\App\Area::AREA_FRONTEND,
[$this, 'parent::filter'],
[$value]
);
}
}

0 comments on commit 30eebde

Please sign in to comment.