Bug #80896

TypolinkViewhelper with linkhandler ignores class attribute

Added by Kai Tallafus about 2 years ago. Updated 2 months ago.

Status:
New
Priority:
Must have
Assignee:
-
Category:
Link Handling, Site Handling & Routing
Start date:
2017-04-19
Due date:
% Done:

0%

TYPO3 Version:
8
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:
On Location Sprint

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?


Related issues

Related to TYPO3 Core - Bug #81316: linkhandler does not respect custom typolink configuration Closed 2017-05-23
Related to TYPO3 Core - Bug #81620: Linkhandler remove all attributes set in the link wizard and the template Closed 2017-06-19
Related to TYPO3 Core - Bug #81903: DatabaseRecordLinkBuilder is ignoring other settings Closed 2017-07-18
Duplicated by TYPO3 Core - Bug #82985: class in f:link.typolink ignored Closed 2017-11-13

History

#1 Updated by Benni Mack about 2 years ago

  • Target version changed from 8 LTS to next-patchlevel

#2 Updated by Georg Ringer about 2 years ago

  • Related to Bug #81316: linkhandler does not respect custom typolink configuration added

#3 Updated by Georg Ringer about 2 years ago

You can solve this by using

<a href="{f:uri.typolink(parameter:link) -> f:format.htmlspecialchars()}" class="xxx">{header}</a>

#4 Updated by Wouter Wolters over 1 year ago

  • Duplicated by Bug #82985: class in f:link.typolink ignored added

#5 Updated by Marc Hirdes over 1 year 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.

#6 Updated by Mordamir over 1 year 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.

#7 Updated by Mordamir over 1 year 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.

#8 Updated by Mordamir over 1 year 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.

#9 Updated by DANIEL Rémy over 1 year 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.

#10 Updated by DANIEL Rémy over 1 year ago

  • Related to Bug #81620: Linkhandler remove all attributes set in the link wizard and the template added

#11 Updated by DANIEL Rémy over 1 year ago

  • Related to Bug #81903: DatabaseRecordLinkBuilder is ignoring other settings added

#12 Updated by Tom Voigt about 1 year 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.

#13 Updated by Riccardo De Contardi 10 months ago

Maybe solved with #81620 ? Or am I wrong?

#14 Updated by DANIEL Rémy 10 months 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.

#15 Updated by Susanne Moog 8 months ago

  • Sprint Focus set to On Location Sprint

#16 Updated by Benni Mack 2 months ago

  • Target version changed from next-patchlevel to Candidate for patchlevel

Also available in: Atom PDF