Skip to content

Commit 42f7e7a

Browse files
author
Francois Suter
committed
[TASK] Restore SoftReference parsing
Clean up and validate code for soft reference parsing
1 parent 3bf3993 commit 42f7e7a

File tree

3 files changed

+56
-106
lines changed

3 files changed

+56
-106
lines changed

Classes/SoftReferenceHandler.php

Lines changed: 30 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
11
<?php
2-
namespace Aoe\Linkhandler;
2+
namespace Cobweb\Linkhandler;
33

4-
/* *
5-
* This script belongs to the TYPO3 extension "linkhandler". *
6-
* *
7-
* It is free software; you can redistribute it and/or modify it under *
8-
* the terms of the GNU General Public License as published by the Free *
9-
* Software Foundation, either version 3 of the License, or (at your *
10-
* option) any later version. *
11-
* *
12-
* This script is distributed in the hope that it will be useful, but *
13-
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14-
* TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
15-
* Public License for more details. *
16-
* *
17-
* You should have received a copy of the GNU General Public License *
18-
* along with the script. *
19-
* If not, see http://www.gnu.org/licenses/gpl.html *
20-
* *
21-
* The TYPO3 project - inspiring people to share! *
22-
* */
4+
/*
5+
* This file is part of the TYPO3 CMS project.
6+
*
7+
* It is free software; you can redistribute it and/or modify it under
8+
* the terms of the GNU General Public License, either version 2
9+
* of the License, or any later version.
10+
*
11+
* For the full copyright and license information, please read the
12+
* LICENSE.txt file that was distributed with this source code.
13+
*
14+
* The TYPO3 project - inspiring people to share!
15+
*/
2316

2417
use \TYPO3\CMS\Core\Utility\GeneralUtility;
2518

2619
/**
27-
* This class will be called by the signal slot dispatcher in the SoftReferenceIndex.
20+
* Class called by the signal slot dispatcher in the SoftReferenceIndex.
2821
*
2922
* @author Michael Klapper <[email protected]>>
3023
* @author Alexander Stehlik <[email protected]>
@@ -54,64 +47,53 @@ public function getTypoLinkParts($linkHandlerFound, $finalTagParts, $linkHandler
5447
}
5548

5649
/**
57-
* Will be called by the SoftReferenceIndex signal slot for updating the given SoftReference information.
50+
* Updates the soft reference information.
5851
*
5952
* @param bool $linkHandlerFound Set this to TRUE in the returning array to tell the parent class that we succeeded.
60-
* @param array $tLP TypoLink properties.
53+
* @param array $typolinkProperties TypoLink properties.
6154
* @param string $content The content to process.
6255
* @param array $elements Reference to the array of elements to be modified with substitution / information entries.
63-
* @param string $idx Index value of the found element - user to make unique but stable tokenID
64-
* @param string $tokenID Unique identifyer for a link of an record
56+
* @param string $index Index value of the found element - user to make unique but stable tokenID
57+
* @param string $tokenID Unique identifier for a link to a record
6558
* @param \TYPO3\CMS\Core\Database\SoftReferenceIndex $softReferenceIndex
6659
* @return array
6760
*/
6861
public function setTypoLinkPartsElement(
6962
$linkHandlerFound,
70-
$tLP,
63+
$typolinkProperties,
7164
$content,
7265
$elements,
73-
$idx,
66+
$index,
7467
$tokenID,
7568
$softReferenceIndex
7669
) {
7770

78-
if ($tLP['LINK_TYPE'] === 'linkhandler') {
79-
80-
$linkInfo = $this->getTabHandlerFactory()->getLinkInfoArrayFromMatchingHandler($tLP['url']);
71+
if ($typolinkProperties['LINK_TYPE'] === 'linkhandler') {
8172

82-
if (count($linkInfo)) {
83-
$content = $this->setTypoLinkPartsElementForLinkhandler($linkInfo, $elements, $idx, $tokenID, $content);
84-
$linkHandlerFound = true;
85-
}
73+
$content = $this->setTypoLinkPartsElementForLinkhandler($typolinkProperties['url'], $elements, $index, $tokenID, $content);
74+
$linkHandlerFound = true;
8675
}
8776

88-
return array($linkHandlerFound, $tLP, $content, $elements, $idx, $tokenID, $softReferenceIndex);
89-
}
90-
91-
/**
92-
* @return \Aoe\Linkhandler\Browser\TabHandlerFactory
93-
*/
94-
protected function getTabHandlerFactory()
95-
{
96-
return GeneralUtility::makeInstance('Aoe\\Linkhandler\\Browser\\TabHandlerFactory');
77+
return array($linkHandlerFound, $typolinkProperties, $content, $elements, $index, $tokenID, $softReferenceIndex);
9778
}
9879

9980
/**
10081
* Generates the SoftReferenceIndex data.
10182
*
102-
* @param array $linkInfo Link information provied by the matching tab handler.
83+
* @param string $url Raw URL pointing to a DB record (format will be "record:key:table:uid"
10384
* @param string $content The content to process.
10485
* @param array $elements Reference to the array of elements to be modified with substitution / information entries.
105-
* @param string $idx Index value of the found element - user to make unique but stable tokenID
86+
* @param string $index Index value of the found element - user to make unique but stable tokenID
10687
* @param string $tokenID Unique identifyer for a link of an record
10788
* @return string
10889
*/
109-
protected function setTypoLinkPartsElementForLinkhandler($linkInfo, &$elements, $idx, $tokenID, $content)
90+
protected function setTypoLinkPartsElementForLinkhandler($url, &$elements, $index, $tokenID, $content)
11091
{
11192

112-
$elements[$tokenID . ':' . $idx]['subst'] = array(
93+
$referenceParts = explode(':', $url);
94+
$elements[$tokenID . ':' . $index]['subst'] = array(
11395
'type' => 'db',
114-
'recordRef' => $linkInfo['recordTable'] . ':' . $linkInfo['recordUid'],
96+
'recordRef' => $referenceParts[2] . ':' . $referenceParts[3],
11597
'tokenID' => $tokenID,
11698
'tokenValue' => $content
11799
);

README.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,28 @@ In this case we want the `returnLast = url` parameter to be merged with the defa
129129
rendering configuration. With the `mergeWithLinkhandlerConfiguration = 1` we tell
130130
"linkhandler" to do just that.
131131

132+
## Hooks
133+
134+
A single hook is provided. It can be used to manipulate most of the data from
135+
the `\Cobweb\Linkhandler\TypolinkHandler` class before the typolink is actually
136+
generated. An example usage could be to change the link target pid dynamically
137+
based on some values from the record being linked to.
138+
139+
Hook usage should be declared in an extension's `ext_localconf.php`file:
140+
141+
```
142+
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkhandler']['generateLink'][] = '\Foo\Bar\MyParameterProcessor';
143+
```
144+
145+
The declared class must implement interface `\Cobweb\Linkhandler\ProcessLinkParameterInterface`.
146+
It can use the many getters and setters of `\Cobweb\Linkhandler\TypolinkHandler`
147+
to read and write data.
148+
149+
## Soft reference handling
150+
151+
Extension "linkhandler" provides a soft reference parser which will pick any
152+
record being linked to and update the system references accordingly.
153+
132154
## Tips & Tricks
133155

134156
### Link browser width
@@ -150,23 +172,6 @@ RTE {
150172
}
151173
```
152174

153-
## Hooks
154-
155-
A single hook is provided. It can be used to manipulate most of the data from
156-
the `\Cobweb\Linkhandler\TypolinkHandler` class before the typolink is actually
157-
generated. An example usage could be to change the link target pid dynamically
158-
based on some values from the record being linked to.
159-
160-
Hook usage should be declared in an extension's `ext_localconf.php`file:
161-
162-
```
163-
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkhandler']['generateLink'][] = '\Foo\Bar\MyParameterProcessor';
164-
```
165-
166-
The declared class must implement interface `\Cobweb\Linkhandler\ProcessLinkParameterInterface`.
167-
It can use the many getters and setters of `\Cobweb\Linkhandler\TypolinkHandler`
168-
to read and write data.
169-
170175

171176
**TODO: all the feature below are untested with TYPO3 CMS 7 LTS. Some may even have been removed during the cleanup but could be introduced again.**
172177

@@ -195,8 +200,3 @@ mod.linkvalidator {
195200

196201
For this additional option to work this pending TYPO3 patch is required: https://review.typo3.org/#/c/26499/ (Provide TSConfig to link checkers).
197202
There is a TYPO3 6.2 fork that already implements the required patches (and some more) at Github: https://github.com/Intera/TYPO3.CMS
198-
199-
200-
### Additional goodies
201-
202-
* SoftReference handling using signal slots, TYPO3 patch pending: https://review.typo3.org/27746/

ext_localconf.php

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,12 @@
66
// Add typolink handler for "record" links
77
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['typolinkLinkHandler']['record'] = 'Cobweb\\Linkhandler\\TypolinkHandler';
88

9-
/*
10-
// Register hooks
11-
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/rtehtmlarea/mod3/class.tx_rtehtmlarea_browse_links.php']['extendJScode'][] = 'Aoe\\Linkhandler\\Browser\\BrowseLinksHook';
12-
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/rtehtmlarea/mod3/class.tx_rtehtmlarea_browse_links.php']['browseLinksHook'][] = 'Aoe\\Linkhandler\\Browser\\ElementBrowserHook';
13-
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['browseLinksHook'][] = 'Aoe\\Linkhandler\\Browser\\ElementBrowserHook';
14-
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['getTable'][] = 'Aoe\\Linkhandler\\Browser\\RecordListHook';
15-
169
// Register signal slots
1710
/** @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher */
18-
/*
19-
$signalSlotDispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher');
20-
$signalSlotDispatcher->connect('TYPO3\\CMS\\Core\\Database\\SoftReferenceIndex', 'getTypoLinkParts', 'Aoe\\Linkhandler\\SoftReferenceHandler', 'getTypoLinkParts', FALSE);
21-
$signalSlotDispatcher->connect('TYPO3\\CMS\\Core\\Database\\SoftReferenceIndex', 'setTypoLinkPartsElement', 'Aoe\\Linkhandler\\SoftReferenceHandler', 'setTypoLinkPartsElement', FALSE);
22-
23-
$linkhandlerExtConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['linkhandler']);
24-
25-
if (
26-
is_array($linkhandlerExtConf)
27-
&& $linkhandlerExtConf['includeDefaultTsConfig']
28-
) {
29-
if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('tt_news')) {
30-
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('
31-
<INCLUDE_TYPOSCRIPT: source="FILE: EXT:linkhandler/Configuration/TypoScript/tt_news/setup.txt">
32-
mod.tx_linkhandler.tx_tt_news_news < plugin.tx_linkhandler.tx_tt_news_news
33-
RTE.default.tx_linkhandler.tx_tt_news_news < plugin.tx_linkhandler.tx_tt_news_news
34-
');
35-
}
36-
37-
if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('news')) {
38-
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('
39-
<INCLUDE_TYPOSCRIPT: source="FILE: EXT:linkhandler/Configuration/TypoScript/news/setup.txt">
40-
mod.tx_linkhandler.tx_news_news < plugin.tx_linkhandler.tx_news_news
41-
RTE.default.tx_linkhandler.tx_news_news < plugin.tx_linkhandler.tx_news_news
42-
');
43-
}
44-
}
11+
$signalSlotDispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class);
12+
$signalSlotDispatcher->connect('TYPO3\\CMS\\Core\\Database\\SoftReferenceIndex', 'getTypoLinkParts', 'Cobweb\\Linkhandler\\SoftReferenceHandler', 'getTypoLinkParts', FALSE);
13+
$signalSlotDispatcher->connect('TYPO3\\CMS\\Core\\Database\\SoftReferenceIndex', 'setTypoLinkPartsElement', 'Cobweb\\Linkhandler\\SoftReferenceHandler', 'setTypoLinkPartsElement', FALSE);
4514

15+
/*
4616
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkvalidator']['checkLinks']['tx_linkhandler'] = 'Aoe\\Linkhandler\\Linkvalidator\\LinkhandlerLinkType';
47-
48-
unset($linkhandlerExtConf);
4917
*/

0 commit comments

Comments
 (0)