Get site config from request attribute in middleware
This commit is contained in:
+2
-43
@@ -2,31 +2,6 @@
|
||||
|
||||
namespace EP\EpProducts\Middleware;
|
||||
|
||||
/***************************************************************
|
||||
*
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2019 Björn Fromme <[email protected]>, dreipunktnull
|
||||
*
|
||||
* All rights reserved
|
||||
*
|
||||
* This script is part of the TYPO3 project. The TYPO3 project is
|
||||
* free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The GNU General Public License can be found at
|
||||
* http://www.gnu.org/copyleft/gpl.html.
|
||||
*
|
||||
* This script is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* This copyright notice MUST APPEAR in all copies of the script!
|
||||
***************************************************************/
|
||||
|
||||
use EP\EpProducts\Service\FilterService;
|
||||
use EP\EpProducts\Service\FilterSettingsEncoder;
|
||||
use EP\EpProducts\Traits\DbConnectionTrait;
|
||||
@@ -35,12 +10,9 @@ use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\MiddlewareInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
|
||||
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
|
||||
use TYPO3\CMS\Core\Http\NormalizedParams;
|
||||
use TYPO3\CMS\Core\Http\RedirectResponse;
|
||||
use TYPO3\CMS\Core\Site\SiteFinder;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Object\ObjectManager;
|
||||
|
||||
class StaticSearchParamsMiddleware implements MiddlewareInterface
|
||||
{
|
||||
@@ -82,11 +54,7 @@ class StaticSearchParamsMiddleware implements MiddlewareInterface
|
||||
return $handler->handle($request);
|
||||
}
|
||||
|
||||
/** @var \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager */
|
||||
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
|
||||
|
||||
/** @var \EP\EpProducts\Service\FilterService $filterService */
|
||||
$filterService = $objectManager->get(FilterService::class);
|
||||
$filterService = GeneralUtility::makeInstance(FilterService::class);
|
||||
|
||||
$filterSettings = $filterService->getFilterSettingsFromStaticSearchParams($row);
|
||||
$filterSettingsEncoder = new FilterSettingsEncoder();
|
||||
@@ -95,18 +63,9 @@ class StaticSearchParamsMiddleware implements MiddlewareInterface
|
||||
$searchPageUid = GeneralUtility::makeInstance(ExtensionConfiguration::class)
|
||||
->get('ep_products', 'searchPageUid');
|
||||
|
||||
/** @var SiteFinder $siteFinder */
|
||||
$siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
|
||||
try {
|
||||
$site = $siteFinder->getSiteByPageId((int)$searchPageUid);
|
||||
}
|
||||
catch (SiteNotFoundException $exception) {
|
||||
return $handler->handle($request);
|
||||
}
|
||||
|
||||
$site = $request->getAttribute('site');
|
||||
$redirectUri = $site->getRouter()->generateUri($searchPageUid, ['f' => $encodedFilterSettings]);
|
||||
|
||||
return new RedirectResponse($redirectUri, self::REDIRECT_RESPONSE_CODE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user