[Typo3-dev] 3.6.0-related: Problem when creating form elements of type "user"

Ingmar Schlecht ingmars at web.de
Thu Dec 25 01:15:47 CET 2003


Hi developers,

This is a bug(?) report about Typo3 version 3.6.0-dev.

TCEForm *doesn't* pass the parent object *as reference* to user field 
rendering functions.

---- Description:
If the "type" key of a database field configuration in TCA is set to 
"user", the TCEForm engine alows to use user functions for rendering the 
form.
The TCEForm engine passes some parameters to the function, one of them 
being the parent TCEForm object which it tries to pass by reference.
However, despite the fact that a '&' is put in front of the variable 
name, the user function that is called does not get a reference, it gets 
a copy of the object.
This prevents the user function from changing or adding to the parent 
object, so it's for instance impossible to add messages to 
$this->commentMessages[].

The problem is that during t3lib_div::callUserFunc() the reference gets 
lost.
The PHP function call_user_method() doesn't support passing by reference.

---- quick hack:
In the function t3lib_tceforms::getSingleField_typeUser() I inserted the 
following line
before the user function is being called:

$GLOBALS['tceFormsObject'] =& $this;

This way you can use the global variable from your user field rendering 
function to access the TCEForms object.

---- better solution:
Doing it as tslib_cObj::callUserFunction() does it:
          $classObj->cObj = &$this;

Currently tslib_cObj has its own function for calling userFuncs.
IMHO it would be best to generalize the function 
tslib_cObj::callUserFunction(), put it into t3lib_div, and then use it 
from everywhere.

cheers,
Ingmar




More information about the TYPO3-dev mailing list