Hi Ulrike!
cosmoblonde GmbH wrote:
My slugs are unique, as I only have a single folder containing all my records.
Yes, that's fine and I totally get, that it is annoying that you now need to take action.
However there are other users with other use cases and therefore different setups.
The URLs are generated correctly but I am not allowed to access the page due to this function in SiteAccessorTrait:
There are three angles to look at it.
- Saving a record / slug generation
- URL generation
- URL resolving
URL generation is the easiest one, so let's start here.
Generated URLs are based on the site they are generated for and use the slug stored in the database.
URL resolving is a bit trickier, but only a bit.
URLs are split into multiple parts and each part is resolved individually.
A configured PersistentAliasMapper recieves a slug and must resolve a single record UID as result.
For this to work, slugs stored in the database must be unique for the current site.
In other words: A single/distinct URL in a site must resolve to exactly one page exactly, one language and exactly one record.
How is it guaranteed that one part of the URL representing a record (the slug) is only representing one record?
It is done when generating the slug/ saving the record.
Which leads us to slug generation:
Due to how TYPO3 works in general, records are not free floating, but alwasy bound to a storage page.
This storage page has some location in the page tree.
When an editor now creates or edits a record, TYPO3 must ensure the slug is unique enough, so that
URLs (to repeat: URLs are always generated based on a site) are unique as well.
Now here comes the clue:
When
saving a record, TYPO3 must know, in which site(s) the slug is going to be used to resolve exactly one record.
This is (currently) done like that:
- When TCA eval setting for the slug field is set to "uniqueInSite", the site of the storage page is resolved and it is checked whether other records in the site of the storage page exist, which have the same slug
- When TCA eval setting is "uniqueInPid", then only slugs in the same storage folder must be unique
- When TCA eval setting is "unique", then slugs of this record type must be unique in the complete TYPO3 instance
This means:
If you have two different storage folders for e.g. news in two different sites, a news stored in site A can (is allowed to have) have the same slug as a news stored in site B, when TCA is set to "uniqeInSite".
For URL resolving this means, TYPO3 must ensure the correct news record, the one that belongs to the correct site, must be resolved.
And exactly this is what has been fixed.
You could now argue, that this should only happen, if you configure your persistent alias mapper accordingly (which is basically what ask for in this ticket).
This would mean however, that we would have two settings for the exact same thing. People with this use case, would need to configure both and need to configure both (TCA and routing config) to match.
It is true, that most of the above does not apply to your use case. From a technical and conceptual point of view, your use case is to have a global
record storage and having URLs to these records in one or more sites. The correct global configuration for that use case is to set the TCA to "unique"
As far as I understand it, the pageId checked in that function is the records PID and not the detail page PID. If this assumption is correct, then a different eval setting for the slug field will not solve this issue.
I would appreciate if you could check my assumption.
The check for the TCA setting is done here:
https://github.com/TYPO3/TYPO3.CMS/blob/cb0d4629d8c45539ee1d0fee25905a501532a0ea/typo3/sysext/core/Classes/Routing/Aspect/AspectTrait.php#L24-L30
The information whether the slug field is set to uniqueInSite is stored in a property here:
https://github.com/TYPO3/TYPO3.CMS/blob/cb0d4629d8c45539ee1d0fee25905a501532a0ea/typo3/sysext/core/Classes/Routing/Aspect/PersistedAliasMapper.php#L138
The filtering based on site you mention is only performed in the end, when TCA is set to uniqueInSite
https://github.com/TYPO3/TYPO3.CMS/blob/cb0d4629d8c45539ee1d0fee25905a501532a0ea/typo3/sysext/core/Classes/Routing/Aspect/PersistedAliasMapper.php#L240
This means, you need to change TCA to "unique" and your use case is covered with a simple configuration change, just like you desired to have.
(note though that you may still be affected by a bug in the currently released versions until this fix https://review.typo3.org/q/Ie7862b22a06996a9d7ca484a01d7a1859c8f7276 is released)
Please check whether changing TCA indeed works in your instance (like I would expect and have verified in test setups).
Thanks