Skip to content

Commit

Permalink
Use original route for '*' in getUrl during ajax paging
Browse files Browse the repository at this point in the history
Resolves #56
  • Loading branch information
Vinai committed Jul 1, 2021
1 parent 98f42da commit f8ee249
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Controller/Adminhtml/Ajax/Paging.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function __construct(
public function execute()
{
try {
$this->setOrigRoute($this->request);
$result = [
'grid_html' => $this->gridBlockRenderer->renderGrid($this->request->getParam('gridName', '')),
'message' => null,
Expand All @@ -57,4 +58,20 @@ public function execute()

return $json;
}

private function setOrigRoute(RequestInterface $request): void
{
if ($request instanceof \Magento\Framework\App\Request\Http) {
$origRoute = explode('/', $request->getParam('origRoute', ''));
if ($origRoute[0] ?? false) {
$request->setRouteName($origRoute[0]);
}
if ($origRoute[1] ?? false) {
$request->setControllerName($origRoute[1]);
}
if ($origRoute[2] ?? false) {
$request->setActionName($origRoute[2]);
}
}
}
}
18 changes: 18 additions & 0 deletions Controller/Ajax/Paging.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Hyva\Admin\Model\GridBlockRenderer;
use Magento\Framework\App\ActionInterface;
use Magento\Framework\App\Request\Http;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Controller\Result\JsonFactory as JsonResultFactory;

Expand Down Expand Up @@ -33,6 +34,7 @@ public function __construct(RequestInterface $request, GridBlockRenderer $gridBl

public function execute()
{
$this->setOrigRoute($this->request);
try {
$result = [
'grid_html' => $this->gridBlockRenderer->renderGrid($this->request->getParam('gridName', '')),
Expand All @@ -49,4 +51,20 @@ public function execute()

return $json;
}

private function setOrigRoute(RequestInterface $request): void
{
if ($request instanceof \Magento\Framework\App\Request\Http) {
$origRoute = explode('/', $request->getParam('origRoute', ''));
if ($origRoute[0] ?? false) {
$request->setRouteName($origRoute[0]);
}
if ($origRoute[1] ?? false) {
$request->setControllerName($origRoute[1]);
}
if ($origRoute[2] ?? false) {
$request->setActionName($origRoute[2]);
}
}
}
}
9 changes: 9 additions & 0 deletions ViewModel/HyvaGrid/Navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Hyva\Admin\ViewModel\HyvaGrid;

use Magento\Framework\HTTP\PhpEnvironment\Request as HttpRequest;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\LayoutInterface;
use function array_column as pick;
Expand Down Expand Up @@ -226,6 +227,7 @@ private function buildAjaxUrl(string $route, array $params): string
{
$nonNsQueryParams = filter([
'ajax' => $this->isAjaxEnabled() ? '1' : null,
'origRoute' => $this->getCurrentRoute(),
'gridName' => $this->isAjaxEnabled() ? $this->gridName : null,
]);
return $this->buildUrl($route, $params, $nonNsQueryParams);
Expand Down Expand Up @@ -507,4 +509,11 @@ public function getHtml(): string

return $renderer->toHtml();
}

private function getCurrentRoute(): string
{
return ($this->request instanceof HttpRequest ? $this->request->getRouteName() : '') . '/' .
$this->request->getControllerName() . '/' .
$this->request->getActionName();
}
}

0 comments on commit f8ee249

Please sign in to comment.