Bug #99887
closedTypoLink UserFunc in TypoScript seems not to work in 12
Added by Alex Kellner over 1 year ago. Updated about 1 month ago.
0%
Description
I just tried to use a UserFunc for typolink as part of a linkhandler configuration (like Torben shows it in his blog post https://www.derhansen.de/2022/01/typo3-multiple-dynamic-typolink-parameters.html).
The UserFunc is called correctly. But returning a string with a beginning A-tag does not render the link:
class TypoLink { public function createEventLink(array $content, array $config): string { return '<a href="/">'; } }
Updated by Benni Mack over 1 year ago
- Status changed from New to Needs Feedback
Hi Alex,
can you attach the TypoScript you're using?
Updated by Alex Kellner over 1 year ago
Sorry Benni,
meanwhile I switched to a TypoScript-Only solution in LUX to get linkhandler to work. Also "Local History" in PhpStorm is empty for the file.
With this issue I opened a second one with #99886 - maybe that helps you (even if the issue is a bit different).
Alex
Update I think it was exactly like Torben shows it in his blogpost like:
config { recordLinks { registration { typolink { parameter = 1 userFunc = DERHANSEN\SfEventMgt\UserFunc\TypoLink->createEventLink userFunc { eventUid = TEXT eventUid.data = field:event registrationUid = TEXT registrationUid.data = field:uid } } } } }
Updated by Benni Mack over 1 year ago
- Related to Bug #99886: Linkhandler with UserFunc - no ContentObjectRenderer available added
Updated by cosmoblonde GmbH 4 months ago
Hi,
we are experiencing the same issue for a project we are upgrading from a working LTS 11 version to 12.
It seems that the userfunc return value is not used in any way for the typolink generation.
We did double check and can confirm that our userfunc is returning a full (and valid) a-tag.
(We even tried with only returning an opening a-tag as suggested by some source)
If we comment out our userFunc line in our TS, a link is generated to the parameter pid given in our typoscript.
Therefore we assume userFunc is not working with typolink in v12.
Are there any news on this issue? Or can you at least confirm, it is an open issue?
Thank you!
Ulrike
Updated by Benni Mack 4 months ago
Hey Ulrike,
does your userFunc return a string or a LinkResult object?
Updated by cosmoblonde GmbH 4 months ago
Hey Benni,
currently we are returning a string but if it is required we can switch to a LinkResult object.
Updated by cosmoblonde GmbH 3 months ago
Hi,
any news or hints regarding this userFunc issue?
Thank you!
Ulrike
Updated by Benni Mack 3 months ago
cosmoblonde GmbH wrote in #note-7:
Hi,
any news or hints regarding this userFunc issue?
Thank you!
Ulrike
Hey Ulrike,
yes. feel free to ping me (e.g. on slack https://typo3.org/community/meet/chat-slack) so we can exchange the code, if that's ok.
Updated by cosmoblonde GmbH 3 months ago
Hey Benni,
thanks for your offer to directly communicate - I appreciate it!
In the meantime I have already found a solution for my specific problem by using the following typoscript structure:
Working TypoScript structure:
customLinkType {
typolink {
# Detail page
parameter.cObject = USER
parameter.cObject {
userFunc = Myvendor\MyExtension\UserFunc\MyClass->buildLink
item.data = field:uid
# PID used if no detail page can be found
fallback = 13
}
additionalParams.data = field:uid
additionalParams.wrap = &tx_myextension_dummy[controller]=MyController&tx_myextension_dummy[action]=show&tx_myextension_dummy[item]=|
}
forceLink = 1
}
In that working example the userFunc is "only" returning the required PID of the target page, which - for my use case - is a good and clean solution.
Nevertheless, in the non-working version we tried to generate the complete link via a userFunc, which worked until TYPO3 v11 but with version 12 the returned link is never passed on and no links appear in the frontend.
Failing TypoScript structure:
customLinkType {
typolink {
# parameter only set as dummy
parameter = 1
# additionalParams are available to the userFunc, so are used to pass the current field:uid to that function
additionalParams.data = field:uid
additionalParams.wrap = &UID=|&
userFunc = Myvendor\MyExtension\UserFunc\MyClass->buildLink
}
forceLink = 1
}
So for my example the new solution is preferable but it would be good for other use cases to be able to generate complete anchor links via a userFunc.
Thank you!
Updated by Georg Ringer 2 months ago
ยท Edited
I debugged that and it seems everything is working - once it is done right.
IMHO in this issue there are a couple of different requirements.
1st: Forcing absolute urls:
this can be achieved by using
config.recordLinks.identifier { typolink { forceAbsoluteUrl = 1 } }
2nd: alternative urls:
if using a userFunc
on the level of typolink
like
config.recordLinks.tx_news { typolink { userFunc = VENDOR\Ext\LinkHandlerTargetPageService->process } }
then this userFunc required to return an object of type
LinkResult
and not a full a tag as stated in the docs (will open a issue for that [https://github.com/TYPO3-Documentation/TYPO3CMS-Reference-Typoscript/issues/1275]). I tested this with a simple
public function process(string $content = '', array $configuration = []) { return (new LinkResult(LinkService::TYPE_URL, 'https://typo3.org')) ->withLinkText(strip_tags($content)); }
Hope that helps you
Updated by Garvin Hicking 2 months ago
Now also addressed in the Documentation: https://github.com/TYPO3-Documentation/TYPO3CMS-Reference-Typoscript/pull/1276
Updated by Georg Ringer 2 months ago
- Status changed from Needs Feedback to Resolved