-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Introduce ContentObjectFetcher
Solution is forward-compatible with v13 which does not allow reading content object renderer from ConfigurationManager.
- Loading branch information
1 parent
e64c897
commit b03c966
Showing
5 changed files
with
100 additions
and
15 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
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,46 @@ | ||
<?php | ||
namespace FluidTYPO3\Flux\Utility; | ||
|
||
/* | ||
* This file is part of the FluidTYPO3/Flux project under GPLv2 or later. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.md file that was distributed with this source code. | ||
*/ | ||
|
||
use TYPO3\CMS\Core\Http\ServerRequest; | ||
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; | ||
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; | ||
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; | ||
|
||
class ContentObjectFetcher | ||
{ | ||
public static function resolve(?ConfigurationManagerInterface $configurationManager = null): ?ContentObjectRenderer | ||
{ | ||
$contentObject = null; | ||
$request = $configurationManager !== null && method_exists($configurationManager, 'getRequest') | ||
? $configurationManager->getRequest() | ||
: ($GLOBALS['TYPO3_REQUEST'] ?? null); | ||
|
||
if ($request && $configurationManager === null) { | ||
$contentObject = static::resolveFromRequest($request); | ||
} | ||
|
||
if ($contentObject === null) { | ||
if ($configurationManager !== null && method_exists($configurationManager, 'getContentObject')) { | ||
$contentObject = $configurationManager->getContentObject(); | ||
} else { | ||
$contentObject = static::resolveFromRequest($request); | ||
} | ||
} | ||
|
||
return $contentObject; | ||
} | ||
|
||
protected static function resolveFromRequest(ServerRequest $request): ?ContentObjectRenderer | ||
{ | ||
/** @var TypoScriptFrontendController $controller */ | ||
$controller = $request->getAttribute('frontend.controller'); | ||
return $controller instanceof TypoScriptFrontendController ? $controller->cObj : null; | ||
} | ||
} |
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
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
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