0

I have multiple list plugins in an extbase extension. List 1 shows all objects, list 2 shows object by property a, list 3 shows objects by propery b an so on. For showing the detail view of an object, I have a show plugin, which is used by all of the list plugins.

That works so far. Now I need an breadcrumb in the show view which shows not the rootline of the detail page but the rootline of the list page, where the request came from. I tried to put the Page Uid of the list page as a GET-Parameter on the link, which calls the detail page and generate the breadcrumb with this uid in the show action.

<f:link.action pageUid="123" pluginName="myPlugin" action="show" controller="myObject"
                   arguments="{object:object,listpid:listpid}">

Now my question: Is there a way to avoid showing this parameter in the URL? Resp. can I exclude this parameter from URL-Generation. Or do I have any other opportunity to get the list pid in my show action?

Peter Kraume
  • 3,577
  • 2
  • 21
  • 39
m4a
  • 131
  • 1
  • 9

2 Answers2

1

No. Your show-action needs this information. You can use GET/POST, but you have to transfers the UID of your object in any way.

What's the problem with this parameter? If it's looking some kind of ugly, you can define a "speaking URL"...

Julian Hofmann
  • 2,081
  • 1
  • 8
  • 16
  • The Uid of the object ist not my problem. I do not want the list pid in the URL. The URL should look in this way: domain.ltd/somepath/detail/object-name/ without any additional parameter. – m4a Jul 17 '20 at 19:45
1

As Julian pointed, you need to pass that data somehow. If the only goal of sending different listpid for creating different breadcrumb and you don't want to create multiplied resources because of SEO, you can use post-form trick instead of a common link as demonstrated in another answer to send hidden params with your fake link, your HTML markup would look like this:

.inline {
  display: inline;
}

.link-button {
  background: none;
  border: none;
  color: blue;
  text-decoration: underline;
  cursor: pointer;
  font-size: 1em;
  font-family: serif;
}
.link-button:focus {
  outline: none;
}
.link-button:active {
  color:red;
}
<form method="post" action="https://domain.tld/somepath/detail/object-name/" class="inline">
  <input type="hidden" name="listpid" value="345">
  <button type="submit" name="submit_param" value="submit_value" class="link-button">
    Detail page
  </button>
</form>

So your Fluid part would look like

<form method="post" action="{f:uri.action(action:'show', arguments:{object:object})}">
    <input type="hidden" name="listpid" value="{listpid}">
    <button type="submit" name="submit_param" value="submit_value" class="link-button">
        Detail page
    </button>
</form>

and you can get it in your controller's action with

\TYPO3\CMS\Core\Utility\GeneralUtility::_POST('listpid');

SEO doubts

When we're talking about SEO issues we should consider at least two aspects. First is that one mentioned in the previous part, so avoiding duplicated content with different URLs to the same single news, and this trick resolves it, however, using this we do not generate common links which can be read by search engines.

Keeping this in mind at list one of the List views (probably no. 1 in your case, because it shows all, non-filtered items) should NOT use form workaround and render normal links with GET method.

This List should be also used as a fallback in the case when $_POST['listpid'] is unavailable, ie. because request is made from external pages, like Google, or another linking page.

Note: Actually this topic deserves separate question with tag. If someone wants to make additional research, feel free to add the conclusion in a comment and/or edit this part of my answer.


Alternative approach with JS

According to your suggestion there's another possibility, using jQuery for pure comfort, you can do it probably with vanilla JS if required. Maybe it's semi-solution for previous SEO doubts, but I'd rather not to

<!-- in HEAD section of your page if didn't include jQuery before -->
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>

<!-- add the hidden form only once at the beginning -->
<form action="" method="post" id="fakeLinkForm" style="display: none">
    <input type="text" name="listpid" value="0" id="listpidField">
    <input type="submit" name="submit_param" value="submit_value">
</form>


<!-- Your links -->
<a href="http://domain.tld/article/foo" data-listpid="123">Foo detail page (from list 123)</a><br>
<a href="http://domain.tld/article/bar" data-listpid="234">Bar detail page (from list 234)</a><br>
<a href="http://domain.tld/article/baz" data-listpid="345">Baz detail page (from list 345)</a><br>


<!-- Paste the script in the footer -->
<script>
    $("a[data-listpid]").on('click', function (e) {
        e.preventDefault();
        let $link = $(this), $form = $('#fakeLinkForm'), $field = $('#listpidField');
        $field.val($link.data('listpid'));
        $form.attr('action', $link.attr('href'));
        $form.submit();
    });
</script>
biesior
  • 55,576
  • 10
  • 125
  • 182
  • 1
    I had a similar problem with filter variables: the backlink in show view should open the list view with the same filters as before. This is real seo problem because the additional filter variables in the url would result in duplicate content. In the end i used the same approach: a seo anchor link with only the needed params for show view and a form for the actual link with all filter params as hidden fields. – lisardo Jul 19 '20 at 08:33
  • Thanks @biesior for this trick. It works, but as you described I have no common link now. Besides the problem with search engines it produces invalid html in my case, because I use the link around a teaser element with an image and text in it. Is there a trick to handle this too or should I accept the invalid html in this little case? – m4a Jul 22 '20 at 10:06
  • postscript: what do you think about hiding the fake form within my link-teaser-construct and handle the submit of the form with javascript? Then I would have valid html and a link for search engines and could transfer my parameter though. @biesior – m4a Jul 22 '20 at 10:33
  • @m4a, it's quite possible it might work, check my edit, last part ;) – biesior Jul 22 '20 at 11:42
  • @biesior In a similar way I have done this now. But what is the benefit from filling the action-attribute of the hidden form an the value-attribute of the hidden field by JS instead of setting it in the fluid template? – m4a Jul 22 '20 at 12:07
  • Assuming that you have links to different articles, if you have set it in the template you would have to create a separate form for each link with unique `id` which would just violate the DRY rule. Instead of hidden form is placed _once_ at the page beginning and just to modify its `action` right before submitting. – biesior Jul 22 '20 at 12:14