Project

General

Profile

Actions

Feature #68097

closed

add the marker ###PARENT_UID### to the $TCA column type:inline, foreign_record_defaults property

Added by Sebastian Mazza almost 9 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
FormEngine aka TCEforms
Target version:
-
Start date:
2015-07-14
Due date:
% Done:

0%

Estimated time:
PHP Version:
Tags:
Complexity:
no-brainer
Sprint Focus:

Description

Posible Solution:

Change the line 644 in typo3_src-7.3.1/typo3/sysext/backend/Classes/Form/FormEngine.php
from:

$record[$fieldName] = $defaultValue;

to:

$record[$fieldName] = str_replace('###PARENT_UID###', $parent['uid'], $defaultValue);

surrounding loop:

foreach ($config['foreign_record_defaults'] as $fieldName => $defaultValue) {
    if (isset($foreignTableConfig['columns'][$fieldName]) && !in_array($fieldName, $notSettableFields)) {
        //$record[$fieldName] = $defaultValue;
        $record[$fieldName] = str_replace('###PARENT_UID###', $parent['uid'], $defaultValue);
    }
}


Files

Bildschirmfoto 2015-07-14 um 14.18.51.png (53.2 KB) Bildschirmfoto 2015-07-14 um 14.18.51.png add new Shop problem example Sebastian Mazza, 2015-07-14 14:58
Bildschirmfoto 2015-07-14 um 14.21.43.png (63 KB) Bildschirmfoto 2015-07-14 um 14.21.43.png simplified Domain Model Sebastian Mazza, 2015-07-14 14:58
Actions #1

Updated by Frans Saris almost 9 years ago

  • Status changed from New to Needs Feedback

Hi Sebastian,

what's your use-case for this?

gr. Frans

Updated by Sebastian Mazza almost 9 years ago

Hi Frans

I have 3 Tables, company, shop and address. Every address and every shop belongs to an company. The address has a column company which stores the uid of a company (type select in TCA).

A shop has exactly on address, the uid of this address is sores in the column shop.address. I have to provide a select box from which the User can select an address that belongs to se same company as the shop does. So I have to configure an additional WHERE in the foreign_table_where property.
The TCA config for the column shop.address:

'address' => array(
    'exclude' => 1,
    'label' => 'LLL:EXT:mywachau/Resources/Private/Language/locallang_db.xlf:tx_mywachau_domain_model_shop.address',
    'config' => array(
        'type' => 'select',
        'foreign_table' => 'tx_mywachau_domain_model_address',
        'foreign_table_where' => 'AND tx_mywachau_domain_model_address.company=###REC_FIELD_company###',
        'minitems' => 0,
        'maxitems' => 1,
    ),
),

The shops of an company are managed bei a TCA column called shop with the type inline in the TCA for the table company.
The TCA for this column company.shop:

'shop' => array(
            'exclude' => 1,
            'label' => 'LLL:EXT:mywachau/Resources/Private/Language/locallang_db.xlf:tx_mywachau_domain_model_company.shop',
            'config' => array(
                'type' => 'inline',
                'foreign_table' => 'tx_mywachau_domain_model_shop',
                'foreign_field' => 'company',
                'maxitems'      => 9999,
                'appearance' => array(
                    'collapseAll' => 0,
                    'levelLinksPosition' => 'top',
                    'showSynchronizationLink' => 1,
                    'showPossibleLocalizationRecords' => 1,
                    'showAllLocalizationLink' => 1
                ),
                'foreign_unique' => 'type', // a company can only have one shop of a specific type
                'foreign_record_defaults' => array(
                    'company' => '###PARENT_UID###' // my NEW SOLUTION!!!!!!!!!!!!
                ),
            ),

        ),

Problem

Now if you add a new shop to a company a shop record is created and all controlles are rendered for this record, by an AJAX request. The Problem is that the new created record don't have set the correct foreign key value in the column shop.company. And because of that, an empty list for the address select box is rendered.

If a user want's to add a shop to a company he have to click the Create New Button save the hole company record an only after that he is able to select an address for a shop. Becaus wen the shop record is save for the first time Typo3 of corse writs the correct uid to the column shop.company.
With my ###PARENT_UID### marker I can overcome the problem that an user is force to save a new created inline shop record bevor he really can edit this new shop record.

Actions #3

Updated by Frans Saris almost 9 years ago

Ok, but how does this work when you create the shop record?

Actions #4

Updated by Sebastian Mazza almost 9 years ago

Wen a new shop record is created and filled with the values provided by the foreign_record_defaults property the marker ###PARENT_UID### is replaced bei the uid of the company the user is currently editing. So when the controls for the new shop record are rendered the correct foreign key value in the column shop.company is already there and the foreign_table_where (AND tx_mywachau_domain_model_address.company=###REC_FIELD_company###) in the address column config can do his job.
The marker ###REC_FIELD_company### in the where clause is replaced by the value of the shop.company which was provided by my ###PARENT_UID### marker previously. ([[http://docs.typo3.org/typo3cms/TCAReference/Reference/Columns/Select/Index.html#foreign-table-where]])

process example for company with the uid: 123


user click on button new shop record.
ajax request
record = new shop(); # create new recod
record[company] = 123; # because the marker ###PARENT_UID### is replaced by the uid of the owning company
:
# render the select for the address column
foreign_table_where = "AND tx_mywachau_domain_model_address.company=123"; # because the marker ###REC_FIELD_company### in "AND tx_mywachau_domain_model_address.company=###REC_FIELD_company###" 
                                                                              is replaced by the the value of record[company] which is 123
execute sql statement, blablabla
=> the address select box contains all addresses with the company uid 123 :-)
return html for the record to the browser

This of course only woks if the company record was saved any time bevor because we ned real uid for it and not only a "NEW123456789.123456789"

other possible solution for my problem:
Always fill up the foreign key column (defined in the foreign_field property of the inline config) with the correct values during record creation and not only when the record is saved for the first time.

Actions #5

Updated by Alexander Opitz over 8 years ago

  • Status changed from Needs Feedback to New
Actions #6

Updated by Susanne Moog over 4 years ago

  • Status changed from New to Closed

Due to low demand / low priority I'm going to close this issue now. If anyone takes time to implement it, simply open a new issue please. Thanks.

Actions

Also available in: Atom PDF