TYPO3 TCA and select form - typo3

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

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 ☹️)?

TCA type 'inline' handling in multi language environment

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.

TYPO3: How to set up textfield in custom content element to avoid missing file references in backend filelist?

How to set up textfield in custom content element to avoid missing file references in backend filelist
I have a custom content element with a field of type "text". When I link in this field to a file in fileadmin there is no reference counted in the backend.
How I have to configure the field in my TCA to regard the references from that field in the file list?
My TCA-Config for that field is:
'my_ext_fiedname' =>
array(
'config' =>
array(
'type' => 'text',
'eval' => 'required',
'richtextConfiguration' => 'default',
'enableRichtext' => '1',
),
'exclude' => '1',
'label' => 'title',
),
Try to avoid using media references in text fields. It has been difficult over the past years to upgrade TYPO3 with such configuration and usages.
If you can't avoid, try using extension rte_ckeditor_image from Christian Opitz which is regularly maintained.

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.

Restrict output of typo3 extbase backend module

I wrote a backendmodule with extbase in typo3 4.5 and I would like to show different extbase models for different usergroups, but I don't know how. My idea was to register one backendmodul per usergroup, but i think its too laborious. I don't want to check the user group and their rights in my extension. Is there a way to get this?
Example:
models | usergroup: editor could see
specific models | usergroup: specific_editor could see
Please explain the scenario in details. From this i can say this is possible . All you do see to check the user group and according to this you can create a switchable actions in your controller .
What about having a few checkboxes in extension manager - extension configuration tab for selecting the user group and their rights in your extension?
I try to show different extbase-model-entries to different users in my own backend-modul. For example user 'editor' only see 'entry1' and 'special_editor' see 'entry2' and 'entry3'. My idea was to extend the usergroup tca and add a selectfield for my models. My backend-modul will check the current backenduser to get his usergroup and than i want to check the assigned model. It seems to be laborious, but i think its the best and the only way.
I get one solution:
At first i add a field to be_users.
$tempColumns = array(
'model' => array(
'exclude' => 0,
'l10n_mode' => 'mergeIfNotBlank',
'label' => 'LLL:EXT:extensionResources/Private/Language/locallang_db.xml:tx_extension_domain_model_ownmodel',
'config' => array(
'type' => 'select',
'foreign_table' => 'tx_extension_domain_model_ownmodel',
'size' => 10,
'width' => 20,
'minitems' => 0,
'maxitems' => 9999,
'allowNonIdValues' => 0,
'eval' => 'required',
),
),
);
t3lib_div::loadTCA('be_users');
t3lib_extMgm::addTCAcolumns('be_users',$tempColumns,1);
t3lib_extMgm::addToAllTCAtypes('be_users','model;;;;1-1-1');
in my backend-modul i check the current backenduser
$GLOBALS['BE_USER']->user['model']
so i get a list of my modelids separated by commas.
thats it.