yii2-composite-form
yii2-composite-form copied to clipboard
added __clone method - cloning nested forms while cloning parent composite form
$originalCompositeForm = new MyCompositeForm();
$nestedForm = new TitleForm();
$nestedForm->name = 'original';
$originalCompositeForm->titleForms = [$nestedForm];
echo $originalCompositeForm->titleForms[0]->name; // 'original'
$newForm = clone $originalCompositeForm;
$newForm->titleForms[0]->name = 'new name';
echo $newForm->titleForms[0]->name; // 'new name'
echo $originalCompositeForm->titleForms[0]->name; // 'new name' (but 'original' is expected)
Hi @ElisDN, today its been 1 year since this PR was opened!) Could you please tell me if you're interested in it at all or should I maybe just close it?
@annechko Hm... I think that form cloning is not an ordinary operation.
Maybe it's not, but if someone will do it - they will have a bug
@annechko It is not a bug. Typical framework files do not have __clone
method. And it is not a problem in general cases where people do not use clone
expression.
if someone will do it - they can add own optional __clone
method. Or they can make abstract base class with this method and use own class for extending of all own composite forms.