Typo3 select filled with childs category from sys_category - typo3

I'm writing a TCA to define a form, and I need to fill the select with the childs categories from sys_category table.
'category' => [
'label' => 'LLL:EXT:hebo_ideas/Resources/Private/Language/locallang_db.xlf:hk_ideas_idea.category',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'foreign_table' => 'sys_category',
'foreign_table_where' => ' AND sys_category.sys_language_uid IN (-1, 0) ORDER BY sys_category.sorting ASC',
'MM' => 'sys_category_record_mm',
'size' => 10
],
],
I understand that I have to use foreign_table_where but I don't know what parameter from TYPO3 core database should I use to filter this categories by parent. Or may be my approach is wrong?

If you want to add categories to your table, you should use \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::makeCategorizable(). Thats the easiest way. Please have a look at the documentation for details.

Related

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 Extbase m:m relation within TCA

I'm currently struggling with a m:m relation within a simple custom TYPO3 extension.
There are multiple filters and about a dozen of categories a filter can be related to. The relation consists of the category being selected within the filter:
Now, there are about 150 filters and all categories show all filters when assigning them to a product, but should only show those filters that are associated to that category.
I could not find any documentation about this, my current TCA setup looks like this:
'filter_bauwerkszustand' => array(
'exclude' => 0,
'label' => 'Bauwerkszustand',
'config' => array(
'type' => 'select',
'renderType' => 'selectMultipleSideBySide',
'foreign_table' => 'tx_produkte_domain_model_filter',
'foreign_table_where' => ' AND tx_produkte_domain_model_filter.filterkategorie = 1 AND tx_produkte_domain_model_filter.sys_language_uid=###REC_FIELD_sys_language_uid### ORDER BY tx_produkte_domain_model_filter.titel ASC',
'MM' => 'tx_produkte_filter_filterkategorie_mm',
'size' => 10,
'autoSizeMax' => 10,
'maxitems' => 9999,
'multiple' => 0,
),
),
If its a MM-relation thats the problem: the relation colum in filter doesnt acutally hold the categories, just the count of relations. The actual relations are reflected in a MM-table. The backend incorporates the categories in a SELECT statement with JOINs, first to the MM-table, and from there to the actual categories, like so:
tx_produkte_domain_model_filter.uid =
tx_produkte_filter_filterkategorie_mm.uid_local
tx_produkte_filter_filterkategorie_mm.uid_foreign =
tx_produkte_domain_model_filterkategorie.uid
Try relacing the tx_produkte_domain_model_filter.filterkategorie = 1 part in the query with tx_produkte_filter_filterkategorie_mm.uid_foreign = 1.

TYPO3 extbase & IRRE: add existing records with 'foreign_selector'

I "kickstarted" an extension with the extbase extension builder that contains some 1:1 and 1:n relations. It automatically set the field types to 'inline' and displayed a nice IRRE UI in the backend.
But by default, there is no way to select an existing record, just create new ones.
I found various explanations on how to achieve this with 'foreign_selector', but all of them very sketchy. The feature itself should be working, see https://forge.typo3.org/issues/43239
Can someone walk me through this or point to a working example in the TER? I could create a step-by-step tutorial from the example, once I get it to work.
PS The field's TCA config as generated by extension_builder:
'myfield' => array(
'exclude' => 1,
'label' => 'LLL:EXT:myextension/Resources/Private/Language/locallang_db.xlf:tx_myextension_domain_model_myitem.myfield',
'config' => array(
'type' => 'inline',
'foreign_table' => 'tx_myextension_domain_model_myfield',
'foreign_field' => 'myitem',
'maxitems' => 9999,
'appearance' => array(
'collapseAll' => 0,
'levelLinksPosition' => 'top',
'showSynchronizationLink' => 1,
'showPossibleLocalizationRecords' => 1,
'showAllLocalizationLink' => 1
),
),
),
The main problem is that IRRE relations of type 1:n work like this: A child record holds the uid of its parent. So your table tx_myext_domain_model_city holds the UID of your (imaginary) tx_myext_domain_model_address.
Therefore with the default configuration you will not be able to select a city multiple times as it can only have exactly one parent.
So you will need to use a relation table for this field. This table needs to contain a uid field for both the address (uid_address) and the city (uid_city):
CREATE TABLE tx_irreforeignselectordemo_address_city_mm (
uid int(11) NOT NULL auto_increment,
pid int(11) DEFAULT '0' NOT NULL,
uid_address int(11) unsigned DEFAULT '0' NOT NULL,
uid_city int(11) unsigned DEFAULT '0' NOT NULL,
sorting int(11) unsigned DEFAULT '0' NOT NULL,
PRIMARY KEY (uid),
KEY parent (pid)
);
And it needs to have a TCA configuration for these fields (while the table itself can be hidden):
return array(
'ctrl' => array(
'title' => 'Relation table',
'hideTable' => TRUE,
'sortby' => 'sorting',
),
'columns' => array(
'uid_address' => Array(
'label' => 'Address',
'config' => Array(
'type' => 'select',
'foreign_table' => 'tx_irreforeignselectordemo_domain_model_address',
'size' => 1,
'minitems' => 0,
'maxitems' => 1,
),
),
'uid_city' => Array(
'label' => 'City',
'config' => Array(
'type' => 'select',
'foreign_table' => 'tx_irreforeignselectordemo_domain_model_city',
'foreign_table_where' => ' AND sys_language_uid IN (0,-1)',
'size' => 1,
'minitems' => 0,
'maxitems' => 1,
),
),
),
'types' => array(
'0' => array('showitem' => 'uid_address,uid_city')
),
'palettes' => array()
);
You can then configure the TCA of your address to make it an IRRE field:
'type' => 'inline',
'foreign_table' => 'tx_yourext_address_city_mm',
'foreign_field' => 'uid_address',
'foreign_label' => 'uid_city',
'foreign_selector' => 'uid_city',
'foreign_unique' => 'uid_city',
'foreign_sortby' => 'sorting',
Note that foreign_unique tells TYPO3 that a city can only selected once.
And you need to define the relation from the other side (from your city TCA):
'addresses' => array(
'exclude' => 1,
'label' => 'Addresses',
'config' => array(
'type' => 'inline',
'foreign_table' => 'tx_irreforeignselectordemo_address_city_mm',
'foreign_field' => 'uid_city',
'foreign_label' => 'uid_address',
),
),
Once your configuration is complete, you will be able to use this in the Backend.
Since this is a non-standard MM relation, Extbase will not be able to deal with it by default. But we can compare this to the sys_file_reference table that was introduced in TYPO3 6. So we build an Extbase model for the CityRelation with the properties "address" and "city" and map this model to our mm table:
config.tx_extbase.persistence.classes {
Visol\Irreforeignselectordemo\Domain\Model\CityRelation {
mapping {
tableName = tx_irreforeignselectordemo_address_city_mm
columns {
uid_address.mapOnProperty = address
uid_city.mapOnProperty = city
}
}
}
}
Now in our address model, we define the city (or cities - of you allow more than one choice) as ObjectStorage of type CityRelation:
/**
* Cities
*
* #var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Visol\Irreforeignselectordemo\Domain\Model\CityRelation>
*/
protected $cities = NULL;
We now have a property "cities" that contains the references to all selected cities. You can iterate through them and use them:
<f:for each="{address.cities}" as="cityRelation">
<li>{cityRelation.city.name}</li>
</f:for>
Since I couldn't find an all-in-one demo for this and was interested in the topic, I created a demo extension that does what I just described - based on the Core and two extensions that deal with the topic: https://github.com/lorenzulrich/irreforeignselectordemo
The solution is an m:n approach anyway (because 1:n wouldn't work for the reasons stated above) so I decided to use "cities" instead of "city". While this might not make sense for selecting a city (as suggested by your post), it might make sense for other opportunities. Feel free to replace "cities" by "city" and set maxItems in the inline configuration to one - then you have kind of an 1:n.

TYPO3 TCA select, NULL value in items array

I have made an extension in Typo3 4.5 with extbase and fluid. Now to insert some data i use the backend module 'list' that makes some forms with the TCA of the tables.
To make a select box optional, I insert an item before the foreign table like this:
'feuser' => array(
'exclude' => 0,
'label' => 'LLL:EXT:yes/Resources/Private/Language/locallang_db.xml:tx_yes_domain_model_schools.feuser',
'config' => array(
'type' => 'select',
'items' => array(
array('', NULL),
),
'foreign_table' => 'fe_users',
'maxitems' => 1,
),
),
Now, since i have a relation (with NULL alowed) in my DB, i have to insert a NULL value. But like this it doesn't work. I have also tried '', "" and 0. But those don't work either.
I would appreciate any help.
Try this:
'items' => array(
array('', -1))
The second parameter in the array is not the value for the db!