TYPO3 TCA select list in backend user language - typo3

I build an extension that can assign a tag to an object, this is a 1:n relation to the object and the tag gets selected from a list that a simple editor cannot edit.
the admin has to supply the tags and the translations for every tag, so I was able to limit the list to the items in the default language with this TCA:
'tag' => [
'exclude' => 1,
'label' => 'tag',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => [
['none' , 0]
],
'foreign_table' => 'tx_myextension_domain_model_tags',
'foreign_table_where' => ' AND tx_myextension_domain_model_tags.sys_language_uid IN (-1, 0)',
'MM' => 'tx_myextension_object_tags_mm',
'maxitems' => 1,
'multiple' => 0,
'default' => 0,
],
],
but rather than the default language IN (-1, 0) i'd like to display the list in the selected language for the backend user = ###BE_user_language_uid###... is this possible ?

You can use ###REC_FIELD_sys_language_uid### to access the sys_language_uid field of the current record.
However it is not possible to use the language of the backend user, because frontend translation has nothing to do with backend localization.

Related

TYPO3 Prefill text field in my own extension

I need to save the IP address of a user who fills out my form.
I have tried to do it like this:
'userip' => [
'exclude' => true,
'label' => 'LLL:EXT:myExtension/Resources/Private/Language/locallang_db.xlf:tx_myextension_domain_model_myextension.userip',
'config' => [
'type' => 'input',
'size' => 30,
'eval' => 'trim',
'default' => '12345'.$_SERVER["REMOTE_ADDR"]
]
],
But that doesn't work. What would be the right way?
$_SERVER["REMOTE_ADDR"] is not available in TCA cause this is BE related stuff.
Use the setter from the model, setUserip($_SERVER["REMOTE_ADDR"]), in your createAction() or initializeCreateAction() to save the value in DB.

TYPO3 TCA l10n_mode exclude and MM relations

in TYPO3 v10.4.9 when I use the following tx_csdummy_domain_model_product.php TCA
'items' => [
'l10n_mode' => 'exclude',
'config' => [
'type' => 'select',
'renderType' => 'selectMultipleSideBySide',
'foreign_table' => 'tx_csdummy_domain_model_item',
'foreign_table_where' => ' AND (tx_csdummy_domain_model_item.sys_language_uid IN (0,-1)) ORDER BY title ASC',
'MM' => 'tx_csdummy_product_item_mm',
]
],
],
and in the tx_csdummy_domain_model_item.php TCA
'products' => [
'l10n_mode' => 'exclude',
'config' => [
'type' => 'select',
'renderType' => 'selectMultipleSideBySide',
'foreign_table' => 'tx_csdummy_domain_model_product',
'foreign_table_where' => ' AND (tx_csdummy_domain_model_product.sys_language_uid IN (0,-1)) ORDER BY title ASC',
'MM' => 'tx_csdummy_product_item_mm',
'MM_opposite_field' => 'items',
]
],
],
it works in the default language as it should. But when I have both sites translated, something goes wrong.
For example I have porduct default (uid=1), product translated (uid=2), item default (uid=5) and item translated (uid=6).
A) If I save the product, then the uid of the translated product points to the default language uid of the item.
tx_csdummy_product_item_mm
uid_local uid_foreign
1 5
2 5
B) If I save the item, then the uid of the translated item points to the default language uid of the product.
tx_csdummy_product_item_mm
uid_local uid_foreign
1 5
1 6
With A I can't see the related product in the english version of the item in frontend.
With B I can't see the related item in the english version of the product.

TYPO3 Inline Relational Record Editing (IRRE)

I created a new content element which adds a field called heroslider to tt_content.
The TCA looks like this:
'heroslider' => [
'config' => [
'type' => 'inline',
'allowed' => 'tx_ext_domain_model_heroslider_item',
'foreign_table' => 'tx_ext_domain_model_heroslider_item',
'foreign_field' => 'tt_content_uid',
'foreign_sortby' => 'sorting',
'foreign_label' => 'header',
'maxitems' => 99,
'appearance' => [
'collapseAll' => 1,
'expandSingle' => 1,
],
],
],
Now when I add a heroslider_item in the BE, it gets stored properly, except for the field tt_content_uid. This fields contains a zero instead of the uid of the content element.
Do you have any idea what I am missing?
Thanks in advance!
In your table tx_ext_domain_model_heroslider_item you miss a field for the reverse table name. at least you have not declared it in your relation:
foreign_table_field = parent_table
You know that your parent records always are tt_content, but TYPO3 needs some help.
ANFSCD:
why do you have
'allowed' => 'tx_ext_domain_model_heroslider_item',
I can not find any documentation about an option allowed.

TYPO3 singleSelect required

This is my TCA field configuration
'membership_type' => [
'exclude' => 0,
'label' => $ll . '/locallang_db.xlf:my_label.type',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'foreign_table' => 'sys_category',
'foreign_table_where' => ' AND sys_category.parent=' . $membershipTypeParent . ' AND (sys_category.sys_language_uid = 0 OR sys_category.l10n_parent = 0) ORDER BY sys_category.sorting ASC',
'items' => [
[$llg . 'fe_users.groups.unkonwn', 0]
],
],
],
I want this field to be required. I tried setting:
['config']['eval'] = 'required';
['config']['minitems'] = 1;
But none of them seem to do the job. I found also this old thread on typo3 forge which says it is not possible https://forge.typo3.org/issues/60247. I am using TYPO3 8 now.
"Eval does not exist for select fields. However, what you're missing is a field to choose a non-empty value.
I suggest you use a multi-select with two selects (similar to fe_group in pages) where you can only select one item)."
I would prefer to stay with single select instead of multi-select. Is that possible ?
Eval does exist for select fields, there will be something incorrect in your configuration.
Here's an example I made which works
'exampleSelectSingle' => array(
'label' =>'Select Single',
'exclude' => 0,
'config' => array(
'type' => 'select',
'renderType' => 'selectSingle',
'eval' => 'required',
'items' => array(
['Empty',''],
['Label 1','value1'],
['Label 2','value2']
)
),
'size' => 1,
'minitems' => 1
)
This renders correctly with the first (empty) option selected, which triggers the validation:
https://i.stack.imgur.com/EXbdC.png

TCA file, checkbox default checked

I would like to set a checkbox in the backend to default checked.
In my case it is the field showinpreview in the file /typo3conf/ext/news/Configuration/TCA/tx_news_domain_model_media.php.
I changed the value default to 1, but it has no effect:
'showinpreview' => [
'exclude' => 1,
'label' => $ll . 'tx_news_domain_model_media.showinpreview',
'config' => [
'type' => 'check',
'default' => 1
]
],
When I check the TCA File of tt_content for a checked checkbox it looks like this:
'sectionIndex' => [
'exclude' => 1,
'label' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:sectionIndex',
'config' => [
'type' => 'check',
'default' => 1,
'items' => [
'1' => [
'0' => 'LLL:EXT:lang/locallang_core.xlf:labels.enabled'
]
]
]
],
The only difference I see is the items. But I do not really understand what this item-value does.
The easiest way to change this value is by overriding TCA with some pageTS. Add following to the pagets of the folder that holds the news records.
TCAdefaults.sys_file_reference.showinpreview = 1
See https://docs.typo3.org/typo3cms/TSconfigReference/PageTsconfig/TCEform/Index.html
For the older EXT:news versions use: TCAdefaults.tx_news_domain_model_media.showinpreview = 1
The value of the field showinpreview is set in news/Configuration/TCA/Overrides/sys_file_reference.php. Apply your change there, and you will be happy.
But be aware: after updating of the news extension your change will be lost.
Just checked - this works for me
'checkbox' => array(
'exclude' => 0,
'label' => 'My Label',
'config' => array(
'type' => 'check',
'default' => '1'
)
),