-
Notifications
You must be signed in to change notification settings - Fork 2
[FEATURE] Display templates that have been rendered due this request #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
KamiYang
wants to merge
10
commits into
develop
Choose a base branch
from
fluid-templates
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
12ce2be
[TASK] Introduce templates submodule with dummy output
KamiYang 57dfdda
[TASK] Display templates that have been rendered due this request
KamiYang 6a2497a
[FEATURE] Add Template fetching via ajax and google code prettify hig…
KamiYang 7756e13
[FEATURE] Change return type and fix markdown link usage
KamiYang 47ee192
[FEATURE] Introduce test for ajax controller
KamiYang 18d1e3d
[FEATURE] Introduce templates module test
KamiYang 6fd6fd2
[FEATURE] Add test for getContent and remove unused method
KamiYang bec48f8
[FEATURE] Adjust test to use mock instead of GeneralUtility
KamiYang d4123e1
[FEATURE] Add test for correctly fetching template file content
KamiYang 3e58ff6
[FEATURE] Introduce TemplatePathsTest
KamiYang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,62 @@ | ||
| <?php | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Psychomieze\AdminpanelExtended\Controller; | ||
|
|
||
| /* | ||
| * This file is part of the TYPO3 Adminpanel Initiative. | ||
| * | ||
| * For the full copyright and license information, please read the | ||
| * LICENSE file that was distributed with this source code. | ||
| */ | ||
|
|
||
| use Psr\Http\Message\ServerRequestInterface; | ||
| use Psr\Log\LoggerAwareInterface; | ||
| use Psr\Log\LoggerAwareTrait; | ||
| use Psychomieze\AdminpanelExtended\Modules\Fluid\Templates; | ||
| use Psychomieze\AdminpanelExtended\Service\ModuleDataService; | ||
| use TYPO3\CMS\Adminpanel\ModuleApi\ModuleData; | ||
| use TYPO3\CMS\Core\Http\JsonResponse; | ||
| use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
|
||
| class TemplatesAjaxController implements LoggerAwareInterface | ||
| { | ||
| use LoggerAwareTrait; | ||
|
|
||
| public function getData(ServerRequestInterface $request): JsonResponse | ||
| { | ||
| $queryParams = $request->getQueryParams(); | ||
| $templateId = (string)($queryParams['templateId'] ?? ''); | ||
| $requestId = (string)($queryParams['requestId'] ?? ''); | ||
| $this->validateParameters($templateId, $requestId); | ||
| $moduleData = GeneralUtility::makeInstance(ModuleDataService::class) | ||
| ->getModuleDataByRequestId(Templates::class, $requestId); | ||
| $templateData = []; | ||
| $statusCode = 404; | ||
|
|
||
| if ($moduleData instanceof ModuleData) { | ||
| $templateRecord = $moduleData['templates'][$templateId] ?? null; | ||
KamiYang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (is_array($templateRecord)) { | ||
| $absTemplatePath = GeneralUtility::getFileAbsFileName($templateRecord['path']); | ||
| if (GeneralUtility::isAllowedAbsPath($absTemplatePath) && file_exists($absTemplatePath)) { | ||
| $content = file_get_contents($absTemplatePath); | ||
| $statusCode = 200; | ||
| $templateData['templateId'] = $templateId; | ||
| $templateData['template'] = $content; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return new JsonResponse($templateData, $statusCode); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Returning type |
||
| } | ||
|
|
||
| private function validateParameters(string $templateId, string $requestId): void | ||
| { | ||
| if (!$templateId || !$requestId) { | ||
| throw new \InvalidArgumentException( | ||
| 'Missing parameters, templateId and requestId need to be set.', | ||
| 1561386190 | ||
| ); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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,97 @@ | ||
| <?php | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Psychomieze\AdminpanelExtended\Modules\Fluid; | ||
|
|
||
| /* | ||
| * This file is part of the TYPO3 Adminpanel Initiative. | ||
| * | ||
| * For the full copyright and license information, please read the | ||
| * LICENSE file that was distributed with this source code. | ||
| */ | ||
|
|
||
| use TYPO3\CMS\Core\Core\Environment; | ||
| use TYPO3\CMS\Core\Log\LogLevel; | ||
| use TYPO3\CMS\Core\Log\LogManager; | ||
| use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
| use TYPO3\CMS\Core\Utility\StringUtility; | ||
|
|
||
| class TemplatePaths extends \TYPO3\CMS\Fluid\View\TemplatePaths | ||
| { | ||
| /** | ||
| * @var \TYPO3\CMS\Core\Log\Logger | ||
| */ | ||
| private $logger; | ||
|
|
||
| /** | ||
| * @param array|string|NULL $packageNameOrArray | ||
| */ | ||
| public function __construct($packageNameOrArray = null) | ||
| { | ||
| parent::__construct($packageNameOrArray); | ||
|
|
||
| $this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); | ||
| } | ||
|
|
||
| /** | ||
| * Attempts to resolve an absolute filename | ||
| * of a template (i.e. `templateRootPaths`) | ||
| * using a controller name, action and format. | ||
| * | ||
| * Works _backwards_ through template paths in | ||
| * order to achieve an "overlay"-type behavior | ||
| * where the last paths added are the first to | ||
| * be checked and the first path added acts as | ||
| * fallback if no other paths have the file. | ||
| * | ||
| * If the file does not exist in any path, | ||
| * including fallback path, `NULL` is returned. | ||
| * | ||
| * Path configurations filled from TypoScript | ||
| * is automatically recorded in the right | ||
| * order (see `fillFromTypoScriptArray`), but | ||
| * when manually setting the paths that should | ||
| * be checked, you as user must be aware of | ||
| * this reverse behavior (which you should | ||
| * already be, given that it is the same way | ||
| * TypoScript path configurations work). | ||
| * | ||
| * @param string $controller | ||
| * @param string $action | ||
| * @param string $format | ||
| * @return string|NULL | ||
| * @api | ||
| */ | ||
| public function resolveTemplateFileForControllerAndActionAndFormat($controller, $action, $format = null): ?string | ||
| { | ||
| $templateName = parent::resolveTemplateFileForControllerAndActionAndFormat( | ||
| $controller, | ||
| $action, | ||
| $format | ||
| ); | ||
|
|
||
| if (is_string($templateName)) { | ||
| if (StringUtility::beginsWith($templateName, Environment::getExtensionsPath())) { | ||
| $path = str_replace(Environment::getExtensionsPath().DIRECTORY_SEPARATOR, 'EXT:', $templateName); | ||
| } elseif (StringUtility::beginsWith($templateName, Environment::getFrameworkBasePath())) { | ||
| $path = str_replace(Environment::getFrameworkBasePath().DIRECTORY_SEPARATOR, 'EXT:', $templateName); | ||
| } | ||
|
|
||
| $format = $format ?? $this->getFormat(); | ||
| $identifier = uniqid("template-{$controller}-{$action}-{$format}-", false); | ||
|
|
||
| $this->logger->log( | ||
| LogLevel::DEBUG, | ||
| $identifier, | ||
| [ | ||
| 'path' => $path ?? $templateName, | ||
| 'controller' => $controller, | ||
| 'action' => $action, | ||
| 'format' => $format, | ||
| ] | ||
| ); | ||
| } | ||
|
|
||
| return $templateName; | ||
| } | ||
| } |
This file contains hidden or 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,135 @@ | ||
| <?php | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Psychomieze\AdminpanelExtended\Modules\Fluid; | ||
|
|
||
| /* | ||
| * This file is part of the TYPO3 Adminpanel Initiative. | ||
| * | ||
| * For the full copyright and license information, please read the | ||
| * LICENSE file that was distributed with this source code. | ||
| */ | ||
|
|
||
| use Psr\Http\Message\ServerRequestInterface; | ||
| use TYPO3\CMS\Adminpanel\Log\InMemoryLogWriter; | ||
| use TYPO3\CMS\Adminpanel\ModuleApi\AbstractSubModule; | ||
| use TYPO3\CMS\Adminpanel\ModuleApi\ContentProviderInterface; | ||
| use TYPO3\CMS\Adminpanel\ModuleApi\DataProviderInterface; | ||
| use TYPO3\CMS\Adminpanel\ModuleApi\ModuleData; | ||
| use TYPO3\CMS\Adminpanel\ModuleApi\ResourceProviderInterface; | ||
| use TYPO3\CMS\Backend\Routing\UriBuilder; | ||
| use TYPO3\CMS\Core\Log\LogRecord; | ||
| use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
| use TYPO3\CMS\Fluid\View\StandaloneView; | ||
|
|
||
| /** | ||
| * Fluid templates submodule | ||
| */ | ||
| class Templates extends AbstractSubModule implements ContentProviderInterface, DataProviderInterface, ResourceProviderInterface | ||
| { | ||
| /** | ||
| * Identifier for this module, | ||
| * for example "preview" or "cache" | ||
| * | ||
| * @return string | ||
| */ | ||
| public function getIdentifier(): string | ||
| { | ||
| return 'psychomieze_fluid_templates'; | ||
| } | ||
|
|
||
| /** | ||
| * Module label | ||
| * | ||
| * @return string | ||
| */ | ||
| public function getLabel(): string | ||
| { | ||
| return $this->getLanguageService()->sL( | ||
| 'LLL:EXT:adminpanel_extended/Resources/Private/Language/locallang_fluid.xlf:submodule.templates.label' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Main method for content generation of an admin panel module. | ||
| * Return content as HTML. For modules implementing the DataProviderInterface | ||
| * the "ModuleData" object is automatically filled with the stored data - if | ||
| * no data is given a "fresh" ModuleData object is injected. | ||
| * | ||
| * @param \TYPO3\CMS\Adminpanel\ModuleApi\ModuleData $data | ||
| * @return string | ||
| */ | ||
| public function getContent(ModuleData $data): string | ||
| { | ||
| $view = GeneralUtility::makeInstance(StandaloneView::class); | ||
|
|
||
| $view->setTemplatePathAndFilename('EXT:adminpanel_extended/Resources/Private/Templates/Fluid/Templates.html'); | ||
| $view->assignMultiple($data->getArrayCopy()); | ||
| $url = GeneralUtility::makeInstance(UriBuilder::class)->buildUriFromRoute( | ||
| 'ajax_adminPanelExtended_templateData', | ||
| ['requestId' => $data['requestId']] | ||
KamiYang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ); | ||
| $view->assign('templateDataUri', $url); | ||
|
|
||
| return $view->render(); | ||
| } | ||
|
|
||
| /** | ||
| * @param \Psr\Http\Message\ServerRequestInterface $request | ||
| * @return \TYPO3\CMS\Adminpanel\ModuleApi\ModuleData | ||
| */ | ||
| public function getDataToStore(ServerRequestInterface $request): ModuleData | ||
| { | ||
| $log = InMemoryLogWriter::$log; | ||
| /** @var LogRecord[] $templateRecords */ | ||
| $templateRecords = array_filter( | ||
| $log, | ||
| static function (LogRecord $entry) { | ||
| return $entry->getComponent() === 'Psychomieze.AdminpanelExtended.Modules.Fluid.TemplatePaths'; | ||
| } | ||
| ); | ||
|
|
||
| $templates = []; | ||
|
|
||
| foreach ($templateRecords as $logRecord) { | ||
| $templates[$logRecord->getMessage()] = $logRecord->getData(); | ||
| } | ||
|
|
||
| $templates = array_unique($templates, SORT_REGULAR); | ||
|
|
||
| return new ModuleData([ | ||
| 'templates' => $templates, | ||
| 'requestId' => $request->getAttribute('adminPanelRequestId') | ||
| ]); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a string array with javascript files that will be rendered after the module | ||
| * | ||
| * Example: return ['EXT:adminpanel/Resources/Public/JavaScript/Modules/Edit.js']; | ||
| * | ||
| * @return array | ||
| */ | ||
| public function getJavaScriptFiles(): array | ||
| { | ||
| return [ | ||
| 'EXT:adminpanel_extended/Resources/Public/JavaScript/Templates.js', | ||
| 'EXT:adminpanel_extended/Resources/Public/JavaScript/vendor/prettify.js', | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * Returns a string array with css files that will be rendered after the module | ||
| * | ||
| * Example: return ['EXT:adminpanel/Resources/Public/JavaScript/Modules/Edit.css']; | ||
| * | ||
| * @return array | ||
| */ | ||
| public function getCssFiles(): array | ||
| { | ||
| return [ | ||
| 'EXT:adminpanel_extended/Resources/Public/Css/Templates.css', | ||
| 'EXT:adminpanel_extended/Resources/Public/Css/vendor/desert.css' | ||
| ]; | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,29 @@ | ||
| <html xmlns:f="https://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true"> | ||
| <f:if condition="{templates}"> | ||
| <f:then> | ||
| <table class="typo3-adminPanel-table typo3-adminPanel-table-debug"> | ||
| <thead> | ||
| <tr> | ||
| <th scope="col" class="typo3-adminPanel-table-cell-key">Path</th> | ||
| <th scope="col">Controller</th> | ||
| <th scope="col">Action</th> | ||
| <th scope="col">Format</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| <f:for each="{templates}" key="identifier" as="data"> | ||
| <tr> | ||
| <th scope="row" class="typo3-adminPanel-table-cell-key"> | ||
| <a href="#" data-typo3-role="template-link" data-typo3-ajax-url="{templateDataUri}&templateId={identifier}" data-typo3-template-id="{identifier}">{data.path}</a> | ||
| </th> | ||
| <td>{data.controller}</td> | ||
| <td>{data.action}</td> | ||
| <td>{data.format}</td> | ||
| </tr> | ||
| </f:for> | ||
| </tbody> | ||
| </table> | ||
| </f:then> | ||
| <f:else>No templates</f:else> | ||
| </f:if> | ||
| </html> |
This file contains hidden or 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,28 @@ | ||
| /* | ||
| * This file is part of the TYPO3 Adminpanel Initiative. | ||
| * | ||
| * For the full copyright and license information, please read the | ||
| * LICENSE file that was distributed with this source code. | ||
| */ | ||
| #TSFE_ADMIN_PANEL_FORM.typo3-kidjls9dksoje.typo3-adminPanel pre.prettyprint { | ||
| background-color: #333; | ||
| } | ||
| #TSFE_ADMIN_PANEL_FORM.typo3-kidjls9dksoje.typo3-adminPanel pre.prettyprint *{ | ||
| white-space: pre; | ||
| } | ||
| #TSFE_ADMIN_PANEL_FORM.typo3-kidjls9dksoje.typo3-adminPanel pre.prettyprint li.L0, | ||
| #TSFE_ADMIN_PANEL_FORM.typo3-kidjls9dksoje.typo3-adminPanel pre.prettyprint li.L1, | ||
| #TSFE_ADMIN_PANEL_FORM.typo3-kidjls9dksoje.typo3-adminPanel pre.prettyprint li.L2, | ||
| #TSFE_ADMIN_PANEL_FORM.typo3-kidjls9dksoje.typo3-adminPanel pre.prettyprint li.L3, | ||
| #TSFE_ADMIN_PANEL_FORM.typo3-kidjls9dksoje.typo3-adminPanel pre.prettyprint li.L5, | ||
| #TSFE_ADMIN_PANEL_FORM.typo3-kidjls9dksoje.typo3-adminPanel pre.prettyprint li.L6, | ||
| #TSFE_ADMIN_PANEL_FORM.typo3-kidjls9dksoje.typo3-adminPanel pre.prettyprint li.L7, | ||
| #TSFE_ADMIN_PANEL_FORM.typo3-kidjls9dksoje.typo3-adminPanel pre.prettyprint li.L8 { | ||
| list-style-type: decimal; | ||
| } | ||
| #TSFE_ADMIN_PANEL_FORM.typo3-kidjls9dksoje.typo3-adminPanel pre.prettyprint ol.linenums { | ||
| padding-left: 40px; | ||
| margin-top: 0; | ||
| margin-bottom: 0; | ||
| color: #AEAEAE; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
getDatahas a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.