Bug #80896
closedTypolinkViewhelper with linkhandler ignores class attribute
Added by Kai Tallafus over 7 years ago. Updated almost 2 years ago.
100%
Description
Linkhandler TypoScript definition:
config.recordLinks.products { forceLink = 0 typolink { parameter = 9 additionalParams.data = field:uid additionalParams.wrap = &tx_product_productlist[product]=|&tx_product_productlist[action]=show ATagParams.data = parameters : allParams useCacheHash = 1 } }
Fluidtemplate:
<f:link.typolink parameter="{teaser.primaryLink}" class="btn btn-yellow">....</f:link.typolink>
Output:
<a href="...">...</a>
How are we supposed to output such links with different classes?
ATagParams.data = parameters : allParams helps with links set and styled from RTE, but how can different classes be passed from typolink viewhelper?
Updated by Benni Mack over 7 years ago
- Target version changed from 8 LTS to next-patchlevel
Updated by Georg Ringer about 7 years ago
- Related to Bug #81316: linkhandler does not respect custom typolink configuration added
Updated by Georg Ringer about 7 years ago
You can solve this by using
<a href="{f:uri.typolink(parameter:link) -> f:format.htmlspecialchars()}" class="xxx">{header}</a>
Updated by Wouter Wolters almost 7 years ago
- Has duplicate Bug #82985: class in f:link.typolink ignored added
Updated by Marc Hirdes over 6 years ago
Any news on this topic?
<a href="{f:uri.typolink(parameter:link) -> f:format.htmlspecialchars()}" class="xxx">{header}</a>
Is no workaround in any case. If the link has already a target, title etc. this would be ignored in this case.
Updated by Mordamir over 6 years ago
I dont know how to create a patch, so i post code which fixed it for me. I added the following code to TypolinkViewhelper.php at line 150.
if (strpos($typolinkConfiguration['url'], '&')) { // Separate additional params from url. uid needs to be in url, so we need to $pos = strpos($typolinkConfiguration['url'], '?') + 1; $url = substr($typolinkConfiguration['url'], 0, $pos); $query = substr($typolinkConfiguration['url'], $pos); parse_str($query, $params); $typolinkConfiguration['url'] = $url + 'uid=' + $params['uid']; unset($params['uid']); $typolinkConfiguration['additionalParams'].= '&' . http_build_query($params); }
It basically looks into the url part of typolinkConfiguration for an ampersand, and if found, adds all additional query parameters to the 'additionalParams' section of the link configuration. Because the uid parameter needs to be part of the url section, the uid is handled separately.
Maybe the more correct place would be the decode function of the TypoLinkCodecService.
Updated by Mordamir over 6 years ago
Sorry, my code diddnt fix the issue. The class is now appied correctly, but the generated link is not. I think this is because the t3://record?identifier=tx_news&uid=... cannot be resolved if i move the uid in the first place.
Updated by Mordamir over 6 years ago
The probleme here is that DatabaseRecordLinkHandler ignores any settings from the $conf-array, because it uses the configuration from config.recordLinks.
It should somehow mix the config.recordLinks with the data from $conf, but it seems this is not a trivial task. Its not clear what parameters should be overwritten or appended. $target should be overwritten, but $class could be overwritten or appended. And mixing aTagParams would be a mess.
Updated by Rémy DANIEL over 6 years ago
Hello
A workaround:
<f:link.typolink parameter="123" additionalAttributes="{class:'some-class'}">
additionalAttributes will not be overriden by linkhandler config, but parameter will be.
Updated by Rémy DANIEL over 6 years ago
- Related to Bug #81620: Linkhandler remove all attributes set in the link wizard and the template added
Updated by Rémy DANIEL over 6 years ago
- Related to Bug #81903: DatabaseRecordLinkBuilder is ignoring other settings added
Updated by Tom Voigt over 6 years ago
DANIEL Rémy wrote:
Hello
A workaround:
[...]additionalAttributes will not be overriden by linkhandler config, but parameter will be.
This is not working. I just tested it to get a class into the link like this:
<f:link.typolink parameter="{link}" additionalAttributes="{class: 'class', data-test: 'test'}" title="{rondellItem.header}">Test</f:link.typolink>
Links without linkhandler are correct. Links with the linkhandler do not have any class or other attribute. Testet on TYPO3 8.7.13.
Updated by Riccardo De Contardi about 6 years ago
Maybe solved with #81620 ? Or am I wrong?
Updated by Rémy DANIEL almost 6 years ago
Riccardo De Contardi wrote:
Maybe solved with #81620 ? Or am I wrong?
#81620 solves part of the issue.
But, it remains an edgecase.
TLDR;
always put the page uid directly in the typolink parameter
, not in parameter.
Context
- A typolink is make from a Fluid VH : <f:link.typolink parameter="{linkValue}" class="btn btn-small">{linkLabel}</f:link.typolink>
- In the Fluid template, {linkValue}
contains t3://record?identifier=rss&uid=416
Not working TS config:
config.recordLinks.rss { typolink { parameter.data = field:uid useCacheHash = 1 } }
Working TS config:
config.recordLinks.rss { typolink { parameter = {field:uid} parameter.insertData = 1 useCacheHash = 1 } }
Explanation:
In both cases, DatabaseRecordLinkBuilder
receives t3://record?identifier=rss&uid=416 - "btn btn-small"
as typolink parameter.
In both cases, DatabaseRecordLinkBuilder
builds a typolink configuration (result from a merge of the typolink parameter and the TS config), and call ContentObjectRenderer->typolink
function.
But...
In the former, ContentObjectRenderer->typolink
receives this:
parameter = - - "btn btn-small" parameter.data = field.uid
Here, stdWrap overrides the whole paremeter value, and the part
- "btn btn-small"
of the typolink config is lost.
In the latter, ContentObjectRenderer->typolink
receives this:
parameter = {field:uid} - "btn btn-small btn-outline-white" parameter.insertData = 1
Here, stdWrap replaces
{field:uid}
, and the typolink config is complete: 416 - "btn btn-small"
Conclusion
I don't think this is a bug: with #81620, a typolink configuration is now correctly merged from the Fluid VH to the linkhandler configuration.
But the linkhandler TS config must be very carefully wrote.
Regards.
Updated by Susanne Moog almost 6 years ago
- Sprint Focus set to On Location Sprint
Updated by Benni Mack over 5 years ago
- Target version changed from next-patchlevel to Candidate for patchlevel
Updated by Susanne Moog over 4 years ago
- Sprint Focus deleted (
On Location Sprint)
Updated by Benni Mack over 4 years ago
- Status changed from New to Closed
Hey,
thanks for the detailled explanation, I will close this issue now. If you still feel there is more work to do, let me know, and I will re-open the ticket.
Updated by Felix Nagel over 2 years ago
- Precedes Bug #90404: Linkhandler removes all attributes set in fluid viewhelper if parameter uses stdWrap added
Updated by Felix Nagel over 2 years ago
In specific cases, this bug is still an issue. See https://forge.typo3.org/issues/90404
Updated by Gerrit Code Review over 2 years ago
- Status changed from New to Under Review
Patch set 1 for branch 10.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/74534
Updated by Gerrit Code Review over 2 years ago
Patch set 2 for branch 10.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/74534
Updated by Gerrit Code Review over 2 years ago
Patch set 1 for branch 11.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/74576
Updated by Gerrit Code Review over 2 years ago
Patch set 2 for branch 11.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/74576
Updated by Gerrit Code Review over 2 years ago
Patch set 3 for branch 11.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/74576
Updated by Gerrit Code Review over 2 years ago
Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/74620
Updated by Gerrit Code Review about 2 years ago
Patch set 2 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/74620
Updated by Gerrit Code Review about 2 years ago
Patch set 3 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/74620
Updated by Gerrit Code Review about 2 years ago
Patch set 4 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/74620
Updated by Felix Nagel about 2 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset e4cc573a0ad08dfe52548e02a7eb91f7af1b461d.
Updated by Gerrit Code Review about 2 years ago
- Status changed from Resolved to Under Review
Patch set 4 for branch 11.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/74576
Updated by Gerrit Code Review about 2 years ago
Patch set 5 for branch 11.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/74576
Updated by Felix Nagel about 2 years ago
- Status changed from Under Review to Resolved
Applied in changeset e16fd7cba61d0f732592f40d3886ec1a2493b248.
Updated by Philipp Kitzberger about 2 years ago
Upgrading to 11.5.11 seems to be breaking the returnLast
feature:
link = TEXT link.typolink.parameter.field = header_link link.typolink.returnLast = url
header_link
contains "https://www.example.org _blank" is my example.
With 11.5.10 the result is https://www.example.org
With 11.5.11 the result is https://www.example.org _blank
Updated by Benni Mack about 2 years ago
Philipp Kitzberger wrote in #note-35:
Upgrading to 11.5.11 seems to be breaking the
returnLast
feature:
[...]
header_link
contains "https://www.example.org _blank" is my example.With 11.5.10 the result is https://www.example.org
With 11.5.11 the result is https://www.example.org _blank
Hey Philipp,
thanks for this important hint. I will open a new ticket for this
Updated by Benni Mack about 2 years ago
- Related to Bug #97869: typolink with returnLast returns also more information than just the URL added
Updated by Oliver Hader about 2 years ago
- Related to Bug #98065: TypoScript image file link with target _blank added
Updated by Christian Kuhn about 2 years ago
- Related to Bug #98108: Regression with nested parameter for typolink added
Updated by Benni Mack almost 2 years ago
- Status changed from Resolved to Closed