Skip to content
This repository has been archived by the owner on Jun 14, 2023. It is now read-only.

[FEATURE] Allow multiple use of a record table #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
46 changes: 25 additions & 21 deletions Classes/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,21 @@ public function main($linkText, array $typoLinkConfiguration, $linkHandlerKeywor

// extract link params like "target", "css-class" or "title"
$additionalLinkParameters = str_replace($linkHandlerKeyword . ':' . $linkHandlerValue, '', $linkParameters);
list ($recordTableName, $recordUid) = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(':', $linkHandlerValue);
if (substr_count($linkHandlerValue, ':') == 2) {
list ($recordActionName, $recordTableName, $recordUid) = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(':', $linkHandlerValue);
} else {
list ($recordTableName, $recordUid) = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(':', $linkHandlerValue);
$recordActionName = $recordTableName;
}

$recordArray = $this->getCurrentRecord($recordTableName, $recordUid);
if ($this->isRecordLinkable($recordTableName, $typoScriptConfiguration, $recordArray)) {
if ($this->isRecordLinkable($recordActionName, $typoScriptConfiguration, $recordArray)) {

$this->localContentObject = clone $contentObjectRenderer;
$this->localContentObject->start($recordArray, '');
$typoScriptConfiguration[$recordTableName . '.']['parameter'] .= $additionalLinkParameters;
$typoScriptConfiguration[$recordActionName . '.']['parameter'] .= $additionalLinkParameters;

$currentLinkConfigurationArray = $this->mergeTypoScript($typoScriptConfiguration, $typoLinkConfiguration, $recordTableName);
$currentLinkConfigurationArray = $this->mergeTypoScript($typoScriptConfiguration, $typoLinkConfiguration, $recordActionName);

// build the full link to the record
$generatedLink = $this->localContentObject->typoLink($linkText, $currentLinkConfigurationArray);
Expand All @@ -79,21 +84,21 @@ public function main($linkText, array $typoLinkConfiguration, $linkHandlerKeywor
/**
* Indicate that the requested link can be created or not.
*
* @param string $recordTableName The name of database table
* @param array $typoScriptConfiguration Global defined TypoScript configuration for the linkHandler
* @param array $recordArray Requested record to link to it
* @param string $recordActionName The name of configuration action
* @param array $typoScriptConfiguration Global defined TypoScript cofiguration for the linkHandler
* @param array $recordArray Requested record to link to it
* @access protected
* @return bool
*/
protected function isRecordLinkable($recordTableName, array $typoScriptConfiguration, array $recordArray) {
protected function isRecordLinkable($recordActionName, array $typoScriptConfiguration, array $recordArray) {
$isLinkable = FALSE;

// record type link configuration available
if (is_array($typoScriptConfiguration) && array_key_exists($recordTableName . '.', $typoScriptConfiguration)) {
if (is_array($typoScriptConfiguration) && array_key_exists($recordActionName . '.', $typoScriptConfiguration)) {
if (
(is_array($recordArray) && !empty($recordArray)) // record available
||
((int) $typoScriptConfiguration[$recordTableName . '.']['forceLink'] === 1) // if the record are hidden ore something else, force link generation
((int) $typoScriptConfiguration[$recordActionName . '.']['forceLink'] === 1) // if the record are hidden ore someting else, force link generation
) {
$isLinkable = TRUE;
}
Expand Down Expand Up @@ -156,24 +161,23 @@ protected function updateParentLastTypoLinkMember(\TYPO3\CMS\Frontend\ContentObj
/**
* Merge all TypoScript for the typoLink from the global and local defined settings.
*
* @param array $linkConfigurationArray Global defined TypoScript cofiguration for the linkHandler
* @param array $typoLinkConfigurationArray Local typolink TypoScript configuration for current link
* @param string $recordTableName The name of database table
* @param array $linkConfigurationArray Global defined TypoScript cofiguration for the linkHandler
* @param array $typoLinkConfigurationArray Local typolink TypoScript configuration for current link
* @param string $recordActionName The name of database table
* @access protected
* @return array
*/
protected function mergeTypoScript(array $linkConfigurationArray , array $typoLinkConfigurationArray, $recordTableName) {

// pre-compile the "additionalParams"
$linkConfigurationArray[$recordTableName . '.']['additionalParams'] = $this->localContentObject->stdWrap($linkConfigurationArray[$recordTableName . '.']['additionalParams'], $linkConfigurationArray[$recordTableName . '.']['additionalParams.']);
unset($linkConfigurationArray[$recordTableName . '.']['additionalParams.']);
protected function mergeTypoScript(array $linkConfigurationArray , array $typoLinkConfigurationArray, $recordActionName) {
// precompile the "additionalParams"
$linkConfigurationArray[$recordActionName . '.']['additionalParams'] = $this->localContentObject->stdWrap($linkConfigurationArray[$recordActionName . '.']['additionalParams'], $linkConfigurationArray[$recordActionName . '.']['additionalParams.']);
unset($linkConfigurationArray[$recordActionName . '.']['additionalParams.']);

// merge recursive the "additionalParams" from "$typoScriptConfiguration" with the "$typoLinkConfigurationArray"
if ( array_key_exists('additionalParams', $typoLinkConfigurationArray) ) {
$typoLinkConfigurationArray['additionalParams'] = \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl(
'',
\TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule(
\TYPO3\CMS\Core\Utility\GeneralUtility::explodeUrl2Array($linkConfigurationArray[$recordTableName . '.']['additionalParams']),
\TYPO3\CMS\Core\Utility\GeneralUtility::explodeUrl2Array($linkConfigurationArray[$recordActionName . '.']['additionalParams']),
\TYPO3\CMS\Core\Utility\GeneralUtility::explodeUrl2Array($typoLinkConfigurationArray['additionalParams'])
)
);
Expand All @@ -186,9 +190,9 @@ protected function mergeTypoScript(array $linkConfigurationArray , array $typoLi
if (array_key_exists('parameter.', $typoLinkConfigurationArray)) {
unset($typoLinkConfigurationArray['parameter.']);
}
$linkConfigurationArray[$recordTableName . '.'] = array_merge($linkConfigurationArray[$recordTableName . '.'], $typoLinkConfigurationArray);
$linkConfigurationArray[$recordActionName . '.'] = array_merge($typoLinkConfigurationArray, $linkConfigurationArray[$recordActionName . '.']);
}

return $linkConfigurationArray[$recordTableName . '.'];
return $linkConfigurationArray[$recordActionName . '.'];
}
}
5 changes: 3 additions & 2 deletions Classes/Record/ElementBrowserRecordList.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,13 @@ public function linkWrapItems($table, $uid, $title, $row) {

$title = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordTitle($table, $row, FALSE, TRUE);

$action = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('act');
if (@$this->browselistObj->mode === 'rte') {
//used in RTE mode:
$aOnClick = 'return link_spec(\'' . $this->linkHandler . ':' . $table . ':' . $uid . '\');';
$aOnClick = 'return link_spec(\'' . $this->linkHandler . ':' . $action . ':' . $table . ':' . $uid . '\');';
} else {
//used in wizard mode
$aOnClick = 'return link_folder(\'' . $this->linkHandler . ':' . $table . ':' . $uid . '\');';
$aOnClick = 'return link_folder(\'' . $this->linkHandler . ':' . $action . ':' . $table . ':' . $uid . '\');';
}

return '<a href="#" onclick="' . $aOnClick . '">' . $title . $currentImage . '</a>';
Expand Down
9 changes: 7 additions & 2 deletions Classes/RecordTab.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,18 @@ public function __construct(\TYPO3\CMS\Recordlist\Browser\ElementBrowser $browse
*/
static public function getLinkBrowserInfoArray($href, $tabsConfig) {
$info = array();
list($currentHandler, $table, $uid) = explode(':', $href);
if (substr_count($href, ':') === 3) {
list($currentHandler, $action, $table, $uid) = explode(':', $href);
} else {
list($currentHandler, $table, $uid) = explode(':', $href);
$action = $table;
}

// check the linkhandler TSConfig and find out which config is responsible for the current table:
foreach ($tabsConfig as $key => $tabConfig) {

if ($currentHandler == 'record' || $currentHandler == $tabConfig['overwriteHandler']) {
if ($table == $tabConfig['listTables']) {
if ($key === $action) {
$info['act'] = $key;
}
}
Expand Down