yii2-composite-form icon indicating copy to clipboard operation
yii2-composite-form copied to clipboard

added __clone method - cloning nested forms while cloning parent composite form

Open annechko opened this issue 5 years ago • 4 comments

$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)

annechko avatar Aug 30 '19 14:08 annechko

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 avatar Aug 30 '20 09:08 annechko

@annechko Hm... I think that form cloning is not an ordinary operation.

ElisDN avatar Aug 31 '20 17:08 ElisDN

Maybe it's not, but if someone will do it - they will have a bug

annechko avatar Aug 31 '20 20:08 annechko

@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.

ElisDN avatar Sep 03 '20 09:09 ElisDN