Skip to content
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

Merged

Conversation

GuySartorelli
Copy link
Member

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

Comment on lines -120 to -132
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;
}
Copy link
Member Author

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

Comment on lines 165 to 169
/**
* 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 = [];
Copy link
Member Author

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

Comment on lines -263 to -268
foreach ($field->DisplayRules() as $customRule) {
$newRule = $customRule->duplicate(false);
$newRule->ParentID = $newField->ID;
$newRule->Version = 0;
$newRule->write();
}
Copy link
Member Author

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

Comment on lines -246 to +249
$newField->ParentID = $this->owner->ID;
$newField->ParentClass = $this->owner->ClassName;
$newField->Version = 0;
$newField->write();
$this->getOwner()->Fields()->add($newField);
Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member

@emteknetnz emteknetnz left a 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

@emteknetnz emteknetnz merged commit db8adf5 into silverstripe:6 Aug 27, 2024
12 checks passed
@emteknetnz emteknetnz deleted the pulls/6/duplicate-relations branch August 27, 2024 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants