diff --git a/Classes/LinkHandler/DemandLinkHandler.php b/Classes/LinkHandler/DemandLinkHandler.php new file mode 100644 index 0000000..b962f60 --- /dev/null +++ b/Classes/LinkHandler/DemandLinkHandler.php @@ -0,0 +1,206 @@ +linkAttributes; + } + + /** + * @inheritDoc + */ + public function modifyLinkAttributes(array $fieldDefinitions) + { + return $fieldDefinitions; + } + + /** + * @inheritDoc + */ + public function initialize(AbstractLinkBrowserController $linkBrowser, $identifier, array $configuration) + { + $this->linkBrowser = $linkBrowser; + $this->view = GeneralUtility::makeInstance(StandaloneView::class); + $this->view->getRequest()->setControllerExtensionName('recordlist'); + $this->view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:demander/Resources/Private/Templates/LinkBrowser')]); + $this->view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:demander/Resources/Private/Partials/LinkBrowser')]); + $this->view->setLayoutRootPaths([GeneralUtility::getFileAbsFileName('EXT:demander/Resources/Private/Layouts/LinkBrowser')]); + } + + /** + * @inheritDoc + */ + public function canHandleLink(array $linkParts) + { + var_dump($linkParts); + } + + /** + * @inheritDoc + */ + public function formatCurrentUrl() + { + return 'demand:123?d[tablename-fieldname]=1-3'; + } + + /** + * @inheritDoc + */ + public function render(ServerRequestInterface $request) + { + $this->expandPage = (int)($request->getQueryParams()['expandPage'] ?? 0); + + GeneralUtility::makeInstance(PageRenderer::class) + ->loadRequireJsModule('TYPO3/CMS/Demander/DemandLinkHandler'); + + $tsConfig = $this->getBackendUser()->getTSConfig(); + + /** @var BrowserTreeView $pageTree */ + $pageTree = GeneralUtility::makeInstance(BrowserTreeView::class); + $pageTree->setLinkParameterProvider($this); + $pageTree->ext_showNavTitle = (bool)($tsConfig['options.']['pageTree.']['showNavTitle'] ?? false); + $pageTree->ext_showPageId = (bool)($tsConfig['options.']['pageTree.']['showPageIdWithTitle'] ?? false); + $pageTree->ext_showPathAboveMounts = (bool)($tsConfig['options.']['pageTree.']['showPathAboveMounts'] ?? false); + $pageTree->addField('nav_title'); + + $this->view->assignMultiple([ + 'expandActivePage' => $this->expandPage > 0, // TODO: Limit to pages on sites + 'tree' => $pageTree->getBrowsableTree() + ]); + + return $this->view->render('DemandLinkHandler'); + } + + /** + * @param array $values Values to be checked + * + * @return bool Returns TRUE if the given values match the currently selected item + */ + public function isCurrentlySelectedItem(array $values): bool + { + $compareToPid = $this->expandPage ?: $this->pid; + + return $compareToPid === (int)$values['pid']; + } + + /** + * Returns the URL of the current script. + * + * @return string + */ + public function getScriptUrl(): string + { + return $this->linkBrowser->getScriptUrl(); + } + + /** + * @param array $values Array of values to include into the parameters or which might influence the parameters + * + * @return string[] Array of parameters which have to be added to URLs + */ + public function getUrlParameters(array $values): array + { + $parameters = [ + 'expandPage' => isset($values['pid']) ? (int)$values['pid'] : $this->expandPage, + ]; + + return array_merge($this->linkBrowser->getUrlParameters($values), $parameters); + } + + /** + * @inheritDoc + */ + public function isUpdateSupported() + { + return false; + } + + /** + * @inheritDoc + */ + public function getBodyTagAttributes() + { + return []; + } + + /** + * Sets a DB mount and stores it in the currently defined backend user in her/his uc + */ + protected function setTemporaryDbMounts() + { + $backendUser = $this->getBackendUser(); + + // Clear temporary DB mounts + $tmpMount = GeneralUtility::_GET('setTempDBmount'); + if (isset($tmpMount)) { + $backendUser->setAndSaveSessionData('pageTree_temporaryMountPoint', (int)$tmpMount); + } + + $backendUser->initializeWebmountsForElementBrowser(); + } + + /** + * @return BackendUserAuthentication + */ + protected function getBackendUser() + { + return $GLOBALS['BE_USER']; + } + + /** + * @return LanguageService + */ + protected function getLanguageService() + { + return $GLOBALS['LANG']; + } +} diff --git a/Configuration/TCA/Overrides/pages.php b/Configuration/TCA/Overrides/pages.php new file mode 100644 index 0000000..0aa692d --- /dev/null +++ b/Configuration/TCA/Overrides/pages.php @@ -0,0 +1,10 @@ + + + +
+ + + Filtered Results + + + + diff --git a/Resources/Private/Templates/LinkBrowser/Standard/DemandLinkHandler.html b/Resources/Private/Templates/LinkBrowser/Standard/DemandLinkHandler.html new file mode 100644 index 0000000..1831e72 --- /dev/null +++ b/Resources/Private/Templates/LinkBrowser/Standard/DemandLinkHandler.html @@ -0,0 +1,18 @@ + +
+
+
+ {tree} +
+
+
+
+ +
+
+
+ diff --git a/Resources/Public/JavaScript/DemandLinkHandler.js b/Resources/Public/JavaScript/DemandLinkHandler.js new file mode 100644 index 0000000..40b3a6d --- /dev/null +++ b/Resources/Public/JavaScript/DemandLinkHandler.js @@ -0,0 +1,26 @@ +define(['jquery', 'TYPO3/CMS/Recordlist/LinkBrowser'], function($, LinkBrowser) { + 'use strict'; + + var demandLinkHandler = {}; + + demandLinkHandler.createMyLink = function() { + var val = $('.myElmeent').val(); // Example + + LinkBrowser.finalizeFunction('t3://demander?' + val); // Example + }; + + demandLinkHandler.initialize = function() { + // Catch page click + $('.t3js-pageLink').on('click', function (e) { + e.preventDefault(); + + console.log($(this).attr('href')); // TODO: Process demand configuration for selected page + }) + + // TODO: add necessary event handlers, which will propably call demandLinkHandler.createMyLink + }; + + $(demandLinkHandler.initialize); + + return demandLinkHandler; +});