Skip to content

Commit

Permalink
[develop]:+ Ability to add layout handles on subsequent requests
Browse files Browse the repository at this point in the history
  • Loading branch information
wpoortman committed Dec 3, 2021
1 parent 5bf73cf commit 795e9ea
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Controller/Post/Livewire.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Framework\View\Element\BlockInterface;
use Magento\Framework\View\Result\Page;
use Magewirephp\Magewire\Exception\MagewireException;
use Magewirephp\Magewire\Exception\SubsequentRequestException;
use Magewirephp\Magewire\Helper\Component as ComponentHelper;
Expand Down Expand Up @@ -83,7 +84,7 @@ public function execute(): Json

try {
$post = $this->serializer->unserialize(file_get_contents('php://input'));
$block = $this->locateWireBlock($post);
$block = $this->locateWireComponent($this->resultPageFactory->create(), $post);

$component = $this->componentHelper->extractComponentFromBlock($block);
$component->setRequest($this->httpFactory->createRequest($post)->isSubsequent(true));
Expand Down Expand Up @@ -120,16 +121,15 @@ public function execute(): Json
}

/**
* @param Page $page
* @param array $post
* @return BlockInterface
* @throws SubsequentRequestException
*/
public function locateWireBlock(array $post): BlockInterface
public function locateWireComponent(Page $page, array $post): BlockInterface
{
$resultPage = $this->resultPageFactory->create();
$resultPage->addHandle($post['fingerprint']['handle'])->initLayout();

$block = $resultPage->getLayout()->getBlock($post['fingerprint']['name']);
$page->addHandle($post['fingerprint']['handle'])->initLayout();
$block = $page->getLayout()->getBlock($post['fingerprint']['name']);

if ($block === false) {
throw new SubsequentRequestException('Magewire component does not exist');
Expand Down

0 comments on commit 795e9ea

Please sign in to comment.