Skip to content
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

[WIP][FEATURE] Link builder with demand selection #4

Draft
wants to merge 1 commit into
base: ui_conf
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
206 changes: 206 additions & 0 deletions Classes/LinkHandler/DemandLinkHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
<?php

declare(strict_types=1);


namespace Pixelant\Demander\LinkHandler;


use Pixelant\PxaProductManager\Backend\Tree\BrowserTreeView;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\CMS\Recordlist\Controller\AbstractLinkBrowserController;
use TYPO3\CMS\Recordlist\LinkHandler\AbstractLinkHandler;
use TYPO3\CMS\Recordlist\LinkHandler\LinkHandlerInterface;
use TYPO3\CMS\Recordlist\Tree\View\LinkParameterProviderInterface;

/**
* Link handler for page links with preset demand
*/
class DemandLinkHandler implements
LinkHandlerInterface,
LinkParameterProviderInterface
{
/**
* Available additional link attributes
*
* 'rel' only works in RTE, still we have to declare support for it.
*
* @var string[]
*/
protected $linkAttributes = ['target', 'title', 'class', 'params', 'rel'];

/**
* @var \TYPO3\CMS\Fluid\View\StandaloneView
*/
protected $view;

/**
* @var int
*/
protected int $expandPage = 0;

/**
* @var int
*/
protected int $pid = 0;

/**
* @inheritDoc
*/
public function getLinkAttributes()
{
return $this->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'];
}
}
10 changes: 10 additions & 0 deletions Configuration/TCA/Overrides/pages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

(function ()
{
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::registerPageTSConfigFile(
'demander',
'Configuration/TSconfig/Page/linkHandler.tsconfig',
'Filtered Results Link Handler (Demand)'
);
})();
9 changes: 9 additions & 0 deletions Configuration/TSconfig/Page/linkHandler.tsconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

TCEMAIN.linkHandler.demander {
handler = Pixelant\Demander\LinkHandler\DemandLinkHandler
label = LLL:EXT:demander/Resources/Private/Language/locallang_be.xlf:linkHandler.label
configuration {

}
scanAfter = page
}
11 changes: 11 additions & 0 deletions Resources/Private/Language/locallang_be.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<xliff version="1.0">
<file source-language="en" datatype="plaintext" original="messages" date="2021-01-11T13:00:00Z" product-name="demander">
<header/>
<body>
<trans-unit id="linkHandler.label" xml:space="preserve">
<source>Filtered Results</source>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<div class="element-browser-panel element-browser-main">
<div class="element-browser-main-sidebar">
<div class="element-browser-body">
<f:format.raw>{tree}</f:format.raw>
</div>
</div>
<div class="element-browser-main-content">
<div class="element-browser-body">
<div class="link-browser-section">
<f:if condition="{expandActivePage}">
ddd
</f:if>
</div>
</div>
</div>
</div>
</html>
26 changes: 26 additions & 0 deletions Resources/Public/JavaScript/DemandLinkHandler.js
Original file line number Diff line number Diff line change
@@ -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;
});