TYPO3 TCA categories and FAL - typo3

I would like to illustrate the following in the TCA of TYPO3 v9.5.5
Category 1 (Select selection from dataset, after selection one should be able to select PDFs)
--- FAL 1
--- FAL 2
--- FAL 3
Category 2
--- FAL 1
--- FAL 2
I find it hard to find an approach. I am relatively new to TYPO3. About "type = inline" does not work, because the SELECT fields should be.
I do not want a ready-made solution, just approaches. Happy with links to documentaries or sources.

According to your answer on my comment what you need is the following:
'yourField' => [
'exclude' => true,
'label' => 'LLL:EXT:yourExtension/Resources/Private/Language/locallang_db.xlf:yourfield',
'config' => [
'type' => 'select',
'renderType' => 'selectMultipleSideBySide',
'foreign_table' => 'nameofpdftables',
'MM' => 'nameofthe_relation_mm',
],
],
If you created the extension with Extension manager, then the mm table should automatically be there. Then you will see the pdfs that belong to this field.

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 field of type group doesn't show records if there are too many items

In my own extension I have extended fe_user table to add some relations for users to sysfolders (pages with doktype 254). I did it with common TCA override and adding the group type. In general that works for normal amount of records (like several tens or so) but in some cases some users can have chosen up to 3000+ relations.
Unfortunately, in such case TYPO3 BE doesn't render these relations in form properly (it's empty, although database contains a list of 3000 comma-separated UIDs and FE plugins displays these relations properly).
Of course in such case after saving the form in BE causes that the DB column is cleared.
As you can see, I tried to increase the maxitems without result. Is there some other config option that I missed, or for such huge amount I should use another type of form field? Any advice will be highly appreciated.
File typo3conf/ext/myext/Configuration/TCA/Overrides/fe_users.php
'tx_myext_points' => [
'exclude' => 0,
'label' => 'Sale points for user',
'config' => [
'type' => 'group',
'internal_type' => 'db',
'allowed' => 'pages',
'maxitems' => 999999,
'suggestOptions' => [
'default' => [
'searchWholePhrase' => 1
],
'pages' => [
'searchCondition' => 'doktype = 254'
]
]
]
],

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

Extend TYPO3 News Repository with M:M Relation

I've been trying to extend tx_news with a m:m relation with not much luck so far. Anything I can find online is just for a regular relation, where the ID is saved directly into the same table, not an extra _mm column.
The backend looks fine so far, the way I want it with a selectMultipleSideBySide renderType. It also saves the relations to the database.
Extending the News TCA with this, works fine:
$extendArtistId = array(
'artist_id' => array (
'exclude' => 0,
'l10n_mode' => 'exclude',
'label' => 'Künstler',
'config' => array(
'type' => 'select',
'renderType' => 'selectMultipleSideBySide',
'enableMultiSelectFilterTextfield' => TRUE,
'foreign_table' => 'tx_bfartistmanagement_domain_model_kuenstler',
'foreign_table_where' => 'AND tx_bfartistmanagement_domain_model_kuenstler.sys_language_uid = 0 AND tx_bfartistmanagement_domain_model_kuenstler.pid = 63 ORDER BY tx_bfartistmanagement_domain_model_kuenstler.name ASC',
'MM' => 'tx_news_domain_model_news_artist_id_mm',
'minitems' => 0,
'maxitems' => 99
),
),
);
And the entries are saved the way I expected:
The problem I'm having now is getting these relations from a different extension. News has something called "Hooks", but I'm not sure I want/need that for my case.
The query inside my other extension currently looks like this, newsRepository being injected:
$news = $this->newsRepository->findByArtistId(intval($userID));
I struggle with the next step(s). The function findByArtistId was working before as I was saving the artistId directly inside the news table, but that only works with a direct relation, not an M:M one.
How can I get the News that are associated with that artist, with an m:m relation?

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.