TCA type 'inline' handling in multi language environment - typo3

The following scenario: I have a page translated (connected mode, not copy/free mode!) with multiple elements that are translated from the default language.
In my elements without inline fields everything is fine!
In my elements with inline fields I am completely confused about the handling and/or the configuration!
Let’s say I have a content element which contains three inline elements (let’s call them “quotes”). If I translate these quotes 1:1 everything works as expected.
Well ... almost:
I can create new quotes in the translation, but they won’t be displayed.
I can change the sorting, which won’t be taken into account in frontend. The frontend uses the sorting of the default language.
If I create a new quote in the default language, I get the record displayed in the translation and can translate it. So this works as expected.
This leads me to my questions:
How do I make it the quotes/inline elements in the translation independent of the default language?
If this is not possible (which would be fine to me, as it contradicts the idea of the Translate/Connected-Mode somehow) how do I get rid of the buttons for Sort and Create new (of cause only in the translation, not the default language!)? Otherwise, of course, editors try this and wonder why it doesn’t work.
I hope I’ve simply forget an option, but I’ve been thinking about it and looking for a solution for hours now that I probably can’t see the forest for the trees.
This might help if it is a missing option:
TCA
'config' => [
'appearance' => [
'collapseAll' => '1',
'enabledControls' => [
'dragdrop' => '1',
],
'levelLinksPosition' => 'bottom',
'newRecordLinkTitle' => 'New quote',
'useSortable' => '1',
'showSynchronizationLink' => true,
'showAllLocalizationLink' => true,
'showPossibleLocalizationRecords' => true,
],
'foreign_field' => 'parent_id',
'foreign_sortby' => 'sorting',
'foreign_table' => 'my_quotes_table',
'foreign_table_field' => 'parent_table',
'minitems' => '1',
'type' => 'inline',
],
Typoscript
dataProcessing {
10 = TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor
10 {
if.isTrue.field = my_quotes_field
table = my_quotes_table
pidInList.field = pid
where = parent_id=###uid### AND deleted=0 AND hidden=0
orderBy = sorting
markers.uid.field = uid
as = quotes
}
}
I am using TYPO3 version 11.5.17 with PHP 8.1 and MariaDB 10.5

1.How do I make it the quotes/inline elements in the translation independent of the default language?
You cannot (by any standard TYPO3 means) do this in connected mode. Your page needs to be in free-translation mode to do stuff like that.
If you want do hide the field for all the other languages you can add a "displayCond" property to your tca like this:
'displayCond' => [
'AND' => [
'FIELD:sys_language_uid:=:0'
]
],
This way the field at least stays hidden for the connected languages.

Related

How to get 'friendly' text of a TYPO3 MultiSelect field in the TYPO3 Fluid template?

I have a multi select field that is defined by TCA that way:
'type' => [
'exclude' => true,
'label' => 'LLL:EXT:extension/Resources/Private/Language/locallang_db.xlf:tx_extension.type',
'config' => [
'type' => 'select',
'renderType' => 'selectCheckBox',
'items' => [
['LLL:EXT:extension/Resources/Private/Language/locallang_db.xlf:tx_extension.type.b', 'b'],
['LLL:EXT:extension/Resources/Private/Language/locallang_db.xlf:tx_extension.type.w', 'w'],
],
'size' => 1,
'maxitems' => 2,
'eval' => 'required'
],
],
In the backend form everything works as expected, but when selecting the data in a frontend controller from the database, for example by ->findAll(), I only get 'b', 'w' or 'b,w' as values.
Is there a simple way to get the 'friendly' names?
When using relations to other tables, the values are getting resolved, but not when using static items as values for the select.
I was thinking about using the translate view helper <f:translate key="{value}" extensionName="extension" /> but this will fail when more than one item is selected.
Then I was trying to write an own view helper but failed with the initialisation of the translation factory service (that does not exist in TYPO3 v8.7!!!). Then calling the TranslateViewHelper::renderStatic() method failed because I did not find a way to get the RenderingContextInterface what is needed as third parameter.
Anyway, isn't there a smarter way to solve my problem (in good old TYPO3 v9 ☹️)?

TYPO3 TCA and select form

I try to get values for my tca:
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => [
['Herr', 0],
['Frau', 1]
],
'size' => 1,
'maxitems' => 2,
'eval' => 'required'
],
my form.html has this select types:
<label>Anrede</label>
<f:form.select name="salutation" class="form-control">
<f:form.select.option value="0">Herr</f:form.select.option>
<f:form.select.option value="1">Frau</f:form.select.option>
</f:form.select>
but i get always the first item: Herr, can somebody tell me what i am doing wrong?
For frontend forms with Extbase you will need a proper TypoScript conffiguration, a PHP newAction and/or createAction method and your Fluid template.
Based on the additional information now there are two options that came to my mind:
Either the validation and storage of your form values is not
configured properly, so they will be removed on the way to the
database.
Or you might have rendered the field twice with the same name in the
frontend form, thus making the last entry the winner.
So please double check the fields first before digging deeper into the storage process.
https://docs.typo3.org/m/typo3/book-extbasefluid/master/en-us/7-Controllers/1-Creating-Controllers-and-Actions.html

TYPO3 8.7 randomly sorting content

We have an typo3 instance (8.7), and sometimes it happens, that over hundred of sites the content elements are resorted in an wrong way. It is definitely not done by an user of the system.
Our company has many typo3 projects and the big difference here, is our self developed extension, where you can create records and the record can contain tt_content elements.
TCA of the "field":
'content' => [
'exclude' => 0,
'label' => 'Content',
'config' => [
'type' => 'inline',
'foreign_table' => 'tt_content',
'foreign_sortby' => 'sorting',
'foreign_field' => 'event',
'foreign_record_defaults' => [
],
'maxitems' => 9999,
'appearance' => [
'collapse' => 1,
'levelLinksPosition' => 'top',
'showSynchronizationLink' => 1,
'showPossibleLocalizationRecords' => 1,
'showAllLocalizationLink' => 1,
'useSortable' => 1,
'enabledControls' => [
'dragdrop' => 1
],
],
],
],
The pid of the tt_content element is set with an hook.
The main problem is, I can´t reproduce this behaviour and it happens not very often.
How does TYPO3 organize the sorting of (content) records?
TYPO3 in general uses a field named sorting. the values are not consecutive, so not all records need an update for an insertion or remove of single records. Only on collisions the values are renumbered.
For tt_content you have one special handling: as the content is organized in columns (identified by field colPos) the sorting of each column is individual.
In this way you can have multiple chains of sorting values for each colPos.
In your definition you have no colPos value for the inserted tt_content records. Maybe that results in confusion when records are sorted and all sorting-values are rewritten without respecting the colPos field.
You can find similar chaos if you have records where the order of appearance is given by another field (e.g. title). if you define sortby = title the records are shown in this order - until TYPO3 thinks it must renumber the sorting field. this would result in Numbers overwritten titles. (**Don't use sortby =, but orderBy =)

TYPO3 Extbase TCA MM-relation filter results by site-defined constant "newRecordStoragePid"

TLDR:
I've got two models with MM-Relations with different StoragePids defined via Constants in my template.
I don't know how to filter results while querying my data regarding my configured storagePids for my related Model.
Long version:
In my multisite-TYPO3 installation I've got two models "Person" and "PersonalInformation". These models have a MM-Relation defined via TCA.
"Person" contains all general data, stored in a global RecordStore. "PersonalInformation" contains editable Data i.e. images to be editable for each site separately. These data are stored in seperate RecordStores under each site.
That means within each site-template->Constants I've defined the extension-storagePid i.e.: $plugin.tx_myext.persistence.storagePid = 1
This config is on all sites the same, to be able to access the same RecordStore from each Site.
The RecordStore for "PersonalInformation" should be different for each site. So my setup.txt of my extension looks like:
persistence {
storagePid = {$plugin.tx_myext.persistence.storagePid},
{$plugin.tx_tx_myext.persistence.personalInformationStoragePid}
classes {
TYPO3\T3myext\Domain\Model\PersonalInformation {
newRecordStoragePid = {$plugin.tx_myext.persistence.personalInformationStoragePid}
}
}
}
And in my root-site-template under Constants I've defined plugin.tx_myext.persistence.personalInformationStoragePid for each site individually.
My TCA MM-Relation defined for PersonalInformation:
'person' => array(
'exclude' => 1,
'label' => 'LLL:EXT:myext/Resources/Private/Language/locallang_db.xlf:tx_myext_domain_model_person',
'config' => array(
'type' => 'select',
'renderType' => 'selectMultipleSideBySide',
'foreign_table' => 'tx_myext_domain_model_person',
'foreign_table_where' => 'AND 1=1 ORDER BY last_name ASC',
'MM' => 'tx_myext_person_personalinformation_mm',
'size' => 10,
'autoSizeMax' => 30,
'maxitems' => 1,
'minitems' => 0,
'multiple' => 0,
),
),
My TCA MM-Relation defined for Person:
'personalinformation' => array(
'exclude' => 1,
'label' => 'LLL:EXT:myext/Resources/Private/Language/locallang_db.xlf:tx_myext_domain_model_person.personalinformation',
'config' => array(
'type' => 'none',
'readonly' => 1,
'foreign_table' => 'tx_myext_domain_model_personalinformation',
'MM_opposite_field' => 'personalinformation',
'MM' => 'tx_myext_person_personalinformation_mm',
'foreign_table_where' => 'AND tx_myext_domain_model_personalinformation.pid=###The-PID-defined-in-my-site-Const-for-personalInformationStoragePid###'
),
),
If I var_dump my Person in the Frontend all Person.PersonaInformation of all RecordStores are displayed. But I what to show only PersonalInformation Records of the current Site.
The field in the model will always give back all relations, independent of the storage pid. The foreign_table_where in TCA is only for the backend, so this will do nothing for the frontend.
If you want to only get relations from a certain pid, there are several solutions:
Filter it yourself, either in your template, model or controller. Just loop through the relations and check the pid. This option is easiest, but will be slow if you have a lot of relations.
Select the PersonalInformation records separately in your controller using a PersonalInformationRepository with a findByPerson function. This will respect the storagePid set in TypoScript. This will work fine if you only need the information for 1 person. If you need it for multiple persons on 1 page (in a list view for example) you can do this in a custom getPersonalInformation function in your Person model. If it's not cached it could also be slow for lists (depending on the amount of records).
Use a completely custom query using QueryBuilder (https://docs.typo3.org/typo3cms/CoreApiReference/latest/ApiOverview/Database/QueryBuilder/Index.html). This way you can do it in 1 query with joins.
What is the best solution depends on your exact situation and the number of records.

Backend user restricted to one language should not be able to create content for all languages

I have a backend user with permissions to work with only one language. But this backend user still can create or switch content to the "All languages" language.
How can I disable the "All languages" option for this user.
Or how can I disable it at all? We do not need it at all.
My attempt so far:
I edited the configuration for sys_language_uid in typo3\sysext\frontend\Configuration\TCA\tt_content.php:
'sys_language_uid' => array(
'exclude' => 1,
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.language',
'config' => array(
'type' => 'select',
'renderType' => 'selectSingle',
'special' => 'languages',
/* 'items' => array(
array(
'LLL:EXT:lang/locallang_general.xlf:LGL.allLanguages',
-1,
'flags-multiple'
),
),*/
'default' => 0,
)
),
In all normal tt_content elements the "all" language is not available anymore. But there are two drawbacks:
It overwrites a core file and is not update-safe.
It only disable the "all" language in tt_content elements, not in other elements from extensions (e.g. news).
Yes, you can remove options from TCEFORM select boxes using Page TSConfig:
TCEFORM.tt_content.sys_language_uid.removeItems = -1
You need to have such a configuration for every table affected:
TCEFORM.tx_news_domain_model_news.sys_language_uid.removeItems = -1
Unfortunately there is no hook in the core to influence the language list of a select box with special type languages. If you really need this low-level, you could XCLASS \TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseSystemLanguageRow.php and remove the [All languages] language there.