Get translated child elements in TYPO3 Extbase Controller - typo3

I have the given Structure:
Root category -> First level categories-> Second level categories
The Root is fetched by the regarding repository (extended sys_category repository) and the default query setting ->setLanguageOverlayMode(true).
The first level of children is fetched in the requested language but the second level of children are only returned by the getter if I make a request in the default language.
$rootCategory (there is no translation of this element)
$rootCategory->getChildren() (returns ObjectStorage of translated objects)
$childCategory->getChildren() (returns empty ObjectStorage if language is different than default)
How do I get also all nested child elements in their translated overlay version?
This are my settings:
TypoScript:
config {
sys_language_overlay = 1
sys_language_mode = strict
}
TCA:
$newFields = [
'children' => [
'exclude' => true,
'label' => 'LLL:EXT:myext/Resources/Private/Language/locallang_db.xlf:tx_myext_domain_model_filter.children',
'config' => [
'type' => 'inline',
'foreign_table' => 'sys_category',
'foreign_field' => 'parent',
'foreign_table_where' => 'AND deleted = 0',
'maxitems' => 9999,
'behaviour' => [
'allowLanguageSynchronization' => true
],
'appearance' => [
'collapseAll' => 1,
'levelLinksPosition' => 'top',
'showSynchronizationLink' => 1,
'showPossibleLocalizationRecords' => 1,
'showAllLocalizationLink' => 1
],
],
],
];
Site config:
base: /
baseVariants: { }
disableStaticFileCache: false
errorHandling: { }
languages:
-
title: Deutsch
enabled: true
base: /
typo3Language: de
locale: de_DE.UTF-8
iso-639-1: de
websiteTitle: ''
navigationTitle: ''
hreflang: de-DE
direction: ''
flag: de
languageId: '0'
-
title: English
enabled: true
base: /en/
typo3Language: default
locale: en_UK.UTF-8
iso-639-1: en
websiteTitle: English
navigationTitle: English
hreflang: en-UK
direction: ''
fallbackType: strict
fallbacks: ''
flag: en-us-gb
languageId: '1'
-
title: French
enabled: true
base: /fr/
typo3Language: fr
locale: fr_FR.UTF-8
iso-639-1: fr
websiteTitle: French
navigationTitle: French
hreflang: fr-FR
direction: ''
fallbackType: strict
fallbacks: ''
flag: fr
languageId: '2'
rootPageId: 1
routes: { }

Related

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 language chooser issues after choosing new language

Hi in my typo3 8 website I've added a language chooser. Choosing a language works fine, content switches from german to english it works fine content switches properly.
Issue is when I click a link in english version it always falls back to the german link because /en/ is missing in the Link URL
URL in the Browser looks good the en is there, but in the navigation the URL to an page does not conatin en
I use Typo3 8 and realURL
Typoscript:
config {
sys_language_uid = 0
language = de
locale_all = de_DE.UTF-8
htmlTag_langKey = de
}
config.tx_realurl_enable = 1
[globalVar = GP:L = 1]
config {
sys_language_uid = 1
language = en
locale_all = en_US.UTF-8
htmlTag_langKey = en
}
[global]
temp.langMenu = HMENU
temp.langMenu.special = language
temp.langMenu.special.value = 0,1
temp.langMenu.1 = GMENU
temp.langMenu.1.NO {
XY = [5.w]+4, [5.h]+4
transparentColor = #17353e
backColor = #17353e
5 = IMAGE
5.file = fileadmin/design/images/flag_de.gif || fileadmin/design/images/flag_en.gif
}
temp.langMenu.1.ACT < lib.langMenu.1.NO
temp.langMenu.1.USERDEF1 < lib.langMenu.1.NO
temp.langMenu.1.USERDEF1 = 1
temp.langMenu.1.USERDEF1.5.file = fileadmin/design/images/flag_de.gif || fileadmin/design/images/flag_en.gif
temp.langMenu.1.USERDEF1.noLink = 1
RealURL Config:
<?php
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']=array (
'_DEFAULT' =>
array (
'init' =>
array (
'appendMissingSlash' => 'ifNotFile,redirect',
'emptyUrlReturnValue' => '/',
),
'pagePath' => array(
'type' => 'user',
'userFunc' => 'EXT:realurl/class.tx_realurl_advanced.php:&tx_realurl_advanced->main',
'spaceCharacter' => '-',
'languageGetVar' => 'L',
'expireDays' => 7,
'rootpage_id' => 1,
'firstHitPathCache' => 1,
),
'fileName' =>
array (
'defaultToHTMLsuffixOnPrev' => 0,
'acceptHTMLsuffix' => 1,
'index' =>
array (
'print' =>
array (
'keyValues' =>
array (
'type' => 98,
),
),
),
),
'preVars' =>
array (
0 =>
array (
'GETvar' => 'L',
'valueMap' => array(
'de' => '0',
'en' => '1',
),
'valueDefault' => 'de',
# 'noMatch' => 'bypass',
),
),
),
);
What is my fail in this case?
Thanks in Advance.
You need to add config.linkVars = L(0-1) to your Typoscript config. This will tell the TYPO3 system to pass this link parameter to each generated url.
Please note that this configuration will only apply to internal links generated by the TYPO3 system itself: For example in menues or when you link another page in the RTE. Absolutely placed links will not be affected by this configuration.
The docs: https://docs.typo3.org/typo3cms/TyposcriptReference/Setup/Config/Index.html#linkvars

Symfony form NumberType: This value is not valid

I have a NumberType field:
->add('numero', NumberType::class, [
'required' => true,
'attr' => [
'placeholder' => "Numéro de la carte",
],
'constraints' => [
new Assert\NotBlank(['message' => "Ce champ est obligatoire."]),
new Assert\Regex([
'pattern' => '/^[0-9]{16}$/',
'match' => true,
'message' => 'Le numéro de la carte doit être une suite de 16 chiffres.',
]),
]
])
Required as my regex said, a suite of 16 numbers. But I always got the "This value is not valid" message for more than 7 numbers. I don't know why.
You should change NumberType::class to TextType:class and it should work just fine

Spanish location for yii2-date-picker-widget

I am working on the basic template of Yii2. I use the 2amigos yii2-date-picker-widget.
Datepicker is working fine, but it keeps showing me the default language (that is English) instead of Spanish.
As you can see in the code below, the language param is set to 'es':
<?= $form->field($model, 'alta')->widget(
DatePicker::className(), [
'inline' => false,
'clientOptions' => [
'format' => 'yyyy-mm-dd',
'weekStart' => 1,
'todayBtn' => 'linked',
'clearBtn' => true,
'language' => 'es',
'autoclose' => true,
'todayHighlight' => true
]
]);?>
It seems tha the 2amigos Datepicker comes into the proper location whith:
DatePickerLanguageAsset::register($view)->js[] = 'bootstrap-datepicker.' . $this->language . '.min.js';
that means #vendor/bower/bootstrap-datepicker/dist/locales/bootstrap-datepicker.es.min.js, that is an existing file containing my desired spanish location:
!function(a){a.fn.datepicker.dates.es={days:["Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado","Domingo"],daysShort:["Dom","Lun","Mar","Mié","Jue","Vie","Sáb","Dom"],daysMin:["Do","Lu","Ma","Mi","Ju","Vi","Sa","Do"],months:["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"],monthsShort:["Ene","Feb","Mar","Abr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dic"],today:"Hoy",clear:"Borrar",weekStart:1,format:"dd/mm/yyyy"}}(jQuery);
Why this translation is not being applied?
A lot of thanks.
Your translation doesn't work because of wrong syntax, You should move Your language param from 'clientOptions' to top level array:
<?= $form->field($model, 'alta')->widget(
DatePicker::className(), [
'inline' => false,
'language' => 'es',
'clientOptions' => [
'format' => 'yyyy-mm-dd',
'weekStart' => 1,
'todayBtn' => 'linked',
'clearBtn' => true,
'autoclose' => true,
'todayHighlight' => true
]
]);?>