0
votes

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?

2

2 Answers

1
votes

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"...

1
votes

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>