TYPO3 v10 routeEnhancer generates slug but can't resolve it - typo3

I have a weird behavior in my own extension when using a slug.
The slug generator in my TCA looks like this:
'slug' => [
'label' => 'Slug',
'exclude' => 1,
'config' => [
'type' => 'slug',
'generatorOptions' => [
'fields' => ['title'],
'fieldSeparator' => '/',
'prefixParentPageSlug' => true,
'replacements' => [
'/' => '',
],
],
'fallbackCharacter' => '-',
'eval' => 'uniqueInSite',
'default' => ''
],
],
It generates the slugs correctly.
It is also persisted as expected in the database.
The routeEnhancer looks like this:
ReferenceDetail:
type: Extbase
limitToPages:
- 82
extension: reference
plugin: referencedetail
routes:
- routePath: '/{ref}'
_controller: 'Reference::show'
_arguments:
ref: reference
aspects:
ref:
type: PersistedAliasMapper
tableName: tx_reference_domain_model_reference
routeFieldName: slug
In my frontend everything looks fine. Links look like:
https://xyz.info/reference/detail/name-reference/
But when clicking on it I end up with a 404.
When I switch from routeFieldName: slug to routeFieldName: name or routeFieldName: uid it works perfectly? Has anyone an idea what might goes wrong with my slug?

Figured it out.
This issue is related to: https://forge.typo3.org/issues/91397
The objects I store are outside of my pageRoot becasue I have a multidomainsite.
Therefore you have to set 'eval' => 'unique' instead of 'eval' => 'uniqueInSite' in your TCA Slug config.

Related

get mergedProperties of sys_file_reference in tx_news

I am using TYPO3 9.5.26 with tx_news 8.5.2. I have extended sys_file_reference with my own field. I can access this fields value in my fluid templates like so:
{file.properties.tx_myext_frame}
This is tested and works fine. However in the news module this stays empty
{mediaElement.properties.tx_myext_frame}
How can I use the orginalFile properties in tx_news?
Thanks
Code I use to add the field:
typo3conf\ext\myext\ext_tables.sql
CREATE TABLE sys_file_reference (
tx_myext_frame tinyint(4) DEFAULT '0' NOT NULL,
);
typo3conf\ext\myext\Configuration\TCA\Overrides\sys_file_reference.php
// Add some fields to sys_file_reference table
$temporaryColumns = [
'tx_myext_frame' => [
'exclude' => 0,
'label' => 'LLL:EXT:myext/Resources/Private/Language/locallang_db.xlf:tx_myext_frame',
'config' => [
'type' => 'check',
'default' => '0',
]
],
];
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addFieldsToPalette(
'sys_file_reference',
'imageoverlayPalette',
'--linebreak--,tx_myext_invert,tx_myext_frame',
'after:description'
);
found the answer myself just now - so for anyone trying this use
{mediaElement.originalResource.properties.tx_myext_frame}

TYPO3 9.5: TCA type 'slug' always adds '-1' to URL

I have the following configuration in my extbase TCA configuration:
'path_segment' => array(
'exclude' => 1,
'l10n_mode' => 'mergeIfNotBlank',
'label' => 'Path Segment',
'config' => [
'type' => 'slug',
'generatorOptions' => [
'fields' => ['productname'],
'replacements' => [
'/' => '-',
'.' => '',
'®' => '',
',' => '',
'|' => '',
' ' => '-',
],
],
'fallbackCharacter' => '-',
'eval' => 'unique'
]
),
When I save, I get URLs with -1 added to the URL (f.e.g "myproduct-1" instead of just "myproduct")
I can only avoid this when clicking the Icon which is labled "Recalculate URL Segment from page title" in the List-Module when editing a record.
Our Editors do not mind much about this field and would change the URL every time they save the record.
What can I do to have this "recalculation" automatically" done? Or what am I doing wrong in my configuration?
I'm using TYPO 3 9.5.17.
You should update to 9.5.18. This behaviour is a regression:
2020-05-14 ccd6da5027 [BUGFIX] Exclude current record when checking slug's uniqueness (thanks to Xavier Perseguers)
See Release Notes.

TYPO3 9.5 slug redirect for extbase records results in PageNotFoundException

I want to be able to call blogpost entries by their slug, which is made of their title, through a routeEnhancer. The slug is generated correctly, but calling the URL results in a PageNotFoundException with the error message:
Request parameters could not be validated (&cHash empty)
And with links generated with Fluid:
<f:link.action action="show" arguments="{'blogpost': blogpost}" pageUid="{settings.ShowPid}">Weiterlesen</f:link.action>
... I get The requested page does not exist
Using TYPO3 9.5.16
Here's my config:
setup.typoscript
plugin.tx_exblog {
config {
defaultGetVars = 0
}
features {
requireCHashArgumentForActionArguments = 0
}
}
site/config.yaml
routeEnhancers:
NewsPlugin:
type: Extbase
extension: ExBlog
plugin: Show
routes:
- { routePath: '/{title}', _controller: 'Blogpost::show', _arguments: { title: blogpost } }
defaultController: 'Blogpost::teaser'
aspects:
title:
type: PersistedAliasMapper
tableName: 'tx_exblog_domain_model_blogpost'
routeFieldName: 'slug'
routeValuePrefix: '/'
TCA
'slug' => [
'label' => 'slug',
'exclude' => true,
'config' => [
'type' => 'slug',
'generatorOptions' => [
'fields' => ['title'],
'fieldSeparator' => '/',
'prefixParentPageSlug' => true,
'replacements' => [
'/' => '',
],
],
'fallbackCharacter' => '-',
'eval' => 'uniqueInSite',
],
]
ext_tables.sql
slug varchar(255) DEFAULT '' NOT NULL,
Any ideas as to what am I missing?
There was a change in TYPO3 v9.5.16 regarding eval => "uniqueInSite". Please verify if you really want to keep the blogposts unique in site. If this is the case the "pid" of the blogposts need to be within the same site. If you don't need this, just switch the eval to unique

TYPO3 v9 Routing: How to make a part of the routePath respect the resolved value of another part?

I have an extbase extension with two models which have a 1:n relation, country and city.
The Urls should look like http://www.example.com/countryname/cityname.
Citynames are not unique in the world, e.g. there is a city called "Leipzig" in Germany and in the United States.
So i can have two URLs
http://www.example.com/germany/leipzig
http://www.example.com/united-states/leipzig
And the resolving of "leipzig" to the correct uid must respect the country part.
Is this possible with the currently provides enhancers/aspects?
If not, do you have any suggestion how to handle this cases?
routeEnhancers:
MyWebsitePi1:
type: Extbase
limitToPages: [1]
extension: Website
plugin: Pi1
routes:
- routePath: '/{country_slug}/{city_slug}'
_controller: 'City::show'
_arguments:
country_slug: 'country'
city_slug: 'city'
defaultController: 'City::list'
aspects:
country_slug:
type: PersistedAliasMapper
tableName: 'tx_mywebsite_domain_model_country'
routeFieldName: 'slug'
city_slug:
type: PersistedAliasMapper
tableName: 'tx_mywebsite_domain_model_city'
routeFieldName: 'slug'
I think a combined slug field would be the best solution here. In your TCA code, you can configure the slug to be created from multiple db fields instead of just one:
'slug' => [
'exclude' => true,
'label' => 'LLL:EXT:...',
'config' => [
'type' => 'slug',
'fallbackCharacter' => '-',
'size' => 50,
'eval' => 'uniqueInSite',
'generatorOptions' => [
'fields' => ['country', 'city'],
'fieldSeparator' => '-',
'prependSlash' => true,
'prefixParentPageSlug' => true,
'replacements' => [
'/' => '',
],
]
],
],
Instead of uniqueInSite you can also use uniqueInPid (see docs).
In the routing yml config, just read the slug field then with the PersistedAliasMapper and you are done. I have not yet tested to use a / as separator field, but - works fine.

TYPO3 - Accessing detail page of record via url GET parameter

I developed an extbase extension with list and detail view (list and show action). Without using realurl ... the link of a detail view looks like this:
domain/index.php?id=43&/?tx_abc_abc[record]=1&tx_abc_abc[action]=show&tx_abc_abc[controller]=Abc
And when I change the record id in the url I can dynamically change the content on the detail page and access the record:
domain/index.php?id=43&/?tx_abc_abc[record]=2&tx_abc_abc[action]=show&tx_abc_abc[controller]=Abc
domain/index.php?id=43&/?tx_abc_abc[record]=3&tx_abc_abc[action]=show&tx_abc_abc[controller]=Abc
domain/index.php?id=43&/?tx_abc_abc[record]=4&tx_abc_abc[action]=show&tx_abc_abc[controller]=Abc
The final goal is having a url looking like this and access the record via the GET parameter in the url:
domain/abc/?abc=1
domain/abc/?abc=2
domain/abc/?abc=3
domain/abc/?abc=4
But when activating realurl ... I cannot directly access the record if its not available in tx_realurl_urldata. Or how should the realurl setup look like?
What's the best solution for this? I have too many records (plus 2 languages) for the links to be written and always available in tx_realurl_urldata.
So my thought was to deactivate realurl for this specific extension? But how?
Or I thought to exclude the detail page in realurl_conf.php: 'excludePageIds' => 42,43 but that did not work.
I made a realurl configuration for my own extension for detail pages like this:
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl'] = [
'www.domain.ch' => [
...
],
'fixedPostVars' => [
'extYourextensionDetailConfiguration' => [
[
'GETvar' => 'tx_yourextension_abc[action]',
'noMatch' => 'bypass',
],
[
'GETvar' => 'tx_yourtextension_abc[abc]',
'lookUpTable' => [
'table' => 'tx_yourextension_domain_model_abc',
'id_field' => 'uid',
'alias_field' => 'title',
'addWhereClause' => ' AND deleted=0 AND hidden=0',
'useUniqueCache' => true,
'useUniqueCache_conf' => [
'strtolower' => true,
'spaceCharacter' => '-',
],
'enable404forInvalidAlias' => true,
],
],
],
...,
'99' => 'extYourextensionDetailConfiguration',
...,
],
...,
],
];
Where
www.domain.ch is your domain
extYourextensionDetailConfiguration is a name to use later
alias_field is the content of the segment. can be ID if you want to switch between changing the URL handmade
99 is the ID of the page with the detail view