Bug #16459
closedBug in t3lib_loaddbgroup.php when using defVals while creating new records
0%
Description
Today I ran into some problems while transferring defVals to a TCE_form
containing group fields with MM relations.
In the link the defVal had been created correctly and it was transferred to
alt_doc.php (tested this with a debug of GPvars) but it never appeared in
the corresponding selectbox of the form.
Digging a bit deeper into the code I found out that it is a bug in
t3lib_loaddbgroup.php
In line 126 there's a check if the field is MM or not.
if($MMtable) {
$this->readMM($MMtable,$MMuid);
} else {
$this->readList($itemlist);
}
As you can see for this check only $MMtable is used.
If you create a new record the value for $MMuid always is empty since there
is no existing MM relation yet. So $this->readMM returns an empty value.
Changing the lines to
if($MMtable && $MMuid) {
$this->readMM($MMtable,$MMuid);
} else {
$this->readList($itemlist);
}
did the trick, because the empty $MMuid will trigger $this->readList instead
that will transfer the defVal (which is available in $itemlist) to the
field.
Could anyone check if this change will cause some unwanted behaviour?
IMHO it should not since $this->readMM would return a result anyway only if
$MMuid is not empty. (Which is only the case when editing a record but not
when creating a new one).
Try to fill in a predefined defVal for a group field with MM relations via URL Parameter while calling a backendform.
(issue imported from #M4022)
Files
Updated by Marc Bastian Heinrichs over 18 years ago
Updated by Franz Holzinger about 18 years ago
Hello Joey, I think the behaviour should be changed in a different way. When you use a mm table for a select box, then the special field containg values separated by comma ',' should not be used any more. If you want to select entries from a selection group coming from a mm table then the mm table shall be filled or nothing should be shown at all.
Updated by Andreas Frthner almost 18 years ago
Hi all,
this patch works great. I don't really understand what you mean Franz, because the MM Table will be used if I save the record, it is just for preselecting via the defVals GET variable. This is definitely a bug in the core that can be fixed so easily. So please commit this for the upcoming version 4.1. It would be very sad, if i must patch the core with every update.
Please, please commit it ;-)
Updated by Andreas Frthner almost 18 years ago
Please have a look at it ;-) This bug needs just one minute to fix. I sadly have no write access to svn ;-)
Updated by Oliver Hader almost 18 years ago
The suggested patch is attached as separate patch file (0004022.patch). It solves the problem. The $MMuid is empty on creating a blank new "parent" record.
The defVals will be set using t3lib_transferdate, but this also uses t3lib_loadDBgroup. So IMO this solution is okay.
It is possible to set defaul values for MM relations like this on User TSconfig:
TCEdefaults.[table].[field] = [id]
TCEdefaults.[table].[field] = [tablename]_[id]
e.g.
TCEdefaults.[table].[field] = 123
TCEdefaults.[table].[field] = tx_myext_child_123
Updated by Oliver Hader almost 18 years ago
Oh sorry, I just realized this is the defVals bug and not the TCAdefault bug. I mixed it. But it should work the same however. ;-)
Updated by Steffen Kamper over 17 years ago
Hi Oliver,
i applied the patch and tried to set a default value vor MM-Field in cal:
TCEdefaults.tx_cal_event.monitor_cnt=1
TCEdefaults.tx_cal_event.monitor_cnt=fe_users_1
like you told, but it doesn't work. Do you have an advice ?