TYPO3 Inline Relational Record Editing (IRRE) - typo3

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.

Related

Extbase proper relation discovery

I've come accross a weird issue with extbasewhile working on some semi-complicated logic for filtering of courses for a LMS tools that we work on.
The logic is as follows:
There are course templates and seminars
A course template always has a start and end date, it contains courses that depend on one another
A seminar contains multiple courses that do not depend on one another
As long as a course template starts after the selected date, it has to be displayed
As long as a seminar contains a course that starts after the selected date, it has to be displayed
There are other filters that do not matter here and that do not play into this issue
In order to solve this request, I resorted to the power of extbase being able to simply create a subquery by using something like $query->greaterThanOrEqual('template_children.start_date', $date) (see below for concrete example). This now generates the below result:
Resulting SQL:
SELECT `tx_xxx_domain_model_courseprogrammetemplate`.*
FROM `tx_xxx_domain_model_courseprogrammetemplate`
`tx_xxx_domain_model_courseprogrammetemplate`
LEFT JOIN `tx_xxx_domain_model_courseprogrammetemplate`
`tx_xxx_domain_model_courseprogrammetemplate0`
ON Find_in_set(
`tx_xxx_domain_model_courseprogrammetemplate0`.`uid`,
`tx_xxx_domain_model_courseprogrammetemplate`.`template_children`)
The relations are built by an important and there are no values written to the field template_children on this side of the relation, thus no result is found.
AFAIK, this should work without having to populate this field with anything else than maybe an amount of children (and I'm not sure if this is even necessary anymore).
Here's my TCA configuration and the PHP code handling the logic.
TCA:
'template_children' => [
'exclude' => true,
'label' => 'LLL:EXT:xxx/Resources/Private/Language/locallang_db.xlf:tx_xxx_domain_model_courseprogrammetemplate.template_children',
'config' => [
'items' => [
['', 0]
],
'type' => 'select',
'renderType' => 'selectSingleBox',
'foreign_table' => 'tx_xxx_domain_model_courseprogrammetemplate',
'foreign_table_where' => 'AND tx_xxx_domain_model_courseprogrammetemplate.template = ###REC_FIELD_uid### AND tx_xxx_domain_model_courseprogrammetemplate.sys_language_uid = 0',
'readOnly' => 1,
'size' => 5,
'maxitems' => 100,
'autoSizeMax' => 20,
],
],
Extbase:
$constraints[] =
$query->logicalAnd(
[
$query->logicalOr(
[
// If the learning form is a course, the start and end date should be in between the period
$query->logicalAnd(
[
$query->greaterThanOrEqual('start_date', $demand->getStartDate()->format('Y-m-d H:i:s')),
$query->logicalNot($query->equals('learning_form', 'Seminar'))
]
),
// If the learning form is seminar, we only want to display it, if there is at least one course that starts in this period
$query->logicalAnd(
[
$query->logicalOr(
[
$query->greaterThanOrEqual('templateChildren.start_date', $demand->getStartDate()->format('Y-m-d H:i:s')),
]
),
$query->equals('learning_form', 'Seminar')
]
)
]
)
]
);
I tried switching the TCA field type to inline but this didn't change the behaviour.
Another way to do this would be to get all objects that relate to each seminar that match the filter, but that would mean creating some thousands of separate queries while filter :-/
Thanks for your support.
PS: I found this article, but it does not describe, how to configure the TCA accordingly, so that it works:
TYPO3 Extbase: Filtering a 1:N relation
Also sadly the documentation doesn't say much about what to configure how in TCA for this to work:
https://docs.typo3.org/m/typo3/book-extbasefluid/master/en-us/6-Persistence/3-implement-individual-database-queries.html
I ended up finding the solution to my problem: you have to use inline as a type so that extbase has a chance to know how to resolve the relation:
'template_children' => [
'exclude' => true,
'label' => 'LLL:EXT:xxx/Resources/Private/Language/locallang_db.xlf:tx_xxx_domain_model_courseprogrammetemplate.template_children',
'config' => [
'items' => [
['', 0]
],
'type' => 'inline',
'foreign_table' => 'tx_xxx_domain_model_courseprogrammetemplate',
'foreign_field' => 'template',
'appearance' => [
'collapseAll' => 1,
'levelLinksPosition' => 'top',
'showSynchronizationLink' => 1,
'showPossibleLocalizationRecords' => 1,
'showAllLocalizationLink' => 1
],
'overrideChildTca' => [
'ctrl' => [
'types' => [
'1' => ['showitem' => 'sys_language_uid, l10n_parent, l10n_diffsource, hidden, title'],
],
],
],
],
],

Update reference index in fields with rendertype inputLink

Links to files or images in fields which use the renderType inputLink (e.g header_link in the normal content elements) do not update the reference index when the content element is saved.
My TCA:
'config' => [
'type' => 'input',
'renderType' => 'inputLink',
'size' => 50,
'max' => 1024,
'eval' => 'trim',
'fieldControl' => [
'linkPopup' => [
'options' => [
'title' => '',
],
],
],
'softref' => 'typolink'
(the same as in header_link in the content elements)
Is there a possibility to force the correct handling of the reference index? The editors can't see which files are linked and which not, so they can delete the files in file module without error message.
Thanks
this bug was fixed with TYPO3 9.7.12:
https://review.typo3.org/c/Packages/TYPO3.CMS/+/62205

Cascade delete TYPO3 inline records don't work

I have a TYPO3 extension for some products which uses inline records to add documentgroups to a product. Deleting the product should also delete the documentgroups (inline records).
The documentation says behaviour.enableCascadingDelete is set to true by default, but the documentgroups are not deleted. Setting this value in the TCA does not make a difference.
'documentgroups' => [
'exclude' => 1,
'label' => $ll . ".documentgroups",
'config' => [
'type' => 'inline',
'allowed' => 'tx_product_domain_model_docgroup',
'behaviour' => [
'allowLanguageSynchronization' => true,
'enableCascadingDelete' => true,
],
'foreign_table' => 'tx_product_domain_model_docgroup',
'MM' => 'tx_product_mm',
'MM_match_fields' => [
'tablenames' => 'tx_product_domain_model_docgroup',
'fieldname' => 'documentgroups',
'table_local' => $tableName,
],
'foreign_sortby' => 'sorting',
'minitems' => 0,
'maxitems' => 99,
]
],
enableCascadingDelete has no effect on MM related tables. In \TYPO3\CMS\Core\DataHandling\DataHandler->deleteRecord_procBasedOnFieldType the inline type is checked and only if it's of type field (foreign_field must be set in the TCA) or list (MM and foreign_field must not be set in TCA) child entries will be deleted.

TYPO3 foreign_table_where not works properly

I have TYPO3 version 7.6.18.
'images' => [
'label' => 'LLL:EXT:fefiles/Resources/Private/Language/locallang_db.xlf:images',
'config' => [
'type' => 'inline',
'foreign_table' => 'tx_fefiles_domain_model_photo',
'foreign_field' => 'album',
'foreign_table_where' => 'AND tx_fefiles_domain_model_photo.allow = 1',
'maxitems' => '5000'
],
],
This is configuration in TCA for someone field.
in table tx_fefiles_domain_model_photo I have 4 rows which id = album,
but allow = 1 only two. But I get all four rows. My condition tx_fefiles_domain_model_photo.allow = 1 does't works. I tried different variants, cleared cache. Really I need your help, I must make it works, help me please (
Try:
'foreign_match_fields' => [
'allow' => 1
]
instead of foreign_table_where.
For examples look into documentation: https://docs.typo3.org/typo3cms/TCAReference/

Typo3: Using TCA type group with FAL

Is it possible to use FAL in TCA with the type group?
Based on the doc where say…
elementBrowserType (string) (since TYPO3 CMS 6.0) Makes it possible to
set an alternative element browser type ("db" or "file") than would
otherwise be rendered based on the "internal_type" setting. This is
used internally for FAL file fields, where internal_type is "db" but
the element browser should be the file element browser anyway.
…I tried following:
'config' => array(
'type' => 'group',
'internal_type' => 'db',
'MM' => 'sys_file_reference', // with and without this option
'uploadfolder' => '',
'minitems' => 0,
'maxitems' => 99,
'appearance' => array(
'elementBrowserType' => 'file',
'elementBrowserAllowed' => $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],
),
'max_size' => $GLOBALS['TYPO3_CONF_VARS']['BE']['maxFileSize'],
),
…and much more, but it wont work.
Any hints?
You need to use the API: \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('media') (taken from core\Configuration\TCA\pages.php).
http://api.typo3.org/typo3cms/master/html/class_t_y_p_o3_1_1_c_m_s_1_1_core_1_1_utility_1_1_extension_management_utility.html#ab95ff2f805d3ec462e869057339eee04