-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIX Duplicate userforms using cascade_duplicates config #1320
FIX Duplicate userforms using cascade_duplicates config #1320
Conversation
public function duplicate(bool $doWrite = true, array|null $relations = null): static | ||
{ | ||
$clonedNode = parent::duplicate(true); | ||
|
||
foreach ($this->Options() as $field) { | ||
$newField = $field->duplicate(false); | ||
$newField->ParentID = $clonedNode->ID; | ||
$newField->Version = 0; | ||
$newField->write(); | ||
} | ||
|
||
return $clonedNode; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method exists on a superclass so we don't need to deprecate it here
/** | ||
* Temporary storage of field ids when the form is duplicated. | ||
* Example layout: array('EditableCheckbox3' => 'EditableCheckbox14') | ||
* @var array | ||
* Unused property | ||
* @deprecated 5.3.0 Will be removed without equivalent functionality to replace it | ||
*/ | ||
protected $fieldsFromTo = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't referenced anywhere in the code
3cd2bd5
to
2575edb
Compare
foreach ($field->DisplayRules() as $customRule) { | ||
$newRule = $customRule->duplicate(false); | ||
$newRule->ParentID = $newField->ID; | ||
$newRule->Version = 0; | ||
$newRule->write(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced with $cascade_duplicates
on EditableFormField
$newField->ParentID = $this->owner->ID; | ||
$newField->ParentClass = $this->owner->ClassName; | ||
$newField->Version = 0; | ||
$newField->write(); | ||
$this->getOwner()->Fields()->add($newField); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Matches how this is done in duplicateHasManyRelation
which is what we're effectively doing here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes in the test just output validation error messages when the test fails, so it's easier to see why it failed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally, works well
Intentionally targeting
6
instead of a patch release because we're changing some API around which always comes with a higher chance of regressions than what we normally release in patches.This PR removes custom duplication logic in favour of the standard
$cascade_duplicates
configuration.Issue