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

Bugfix #849: Set default Sort only when ParentID is available #937

Merged
merged 2 commits into from
Oct 6, 2021

Conversation

chrispenny
Copy link
Contributor

Fixes #849
Related to #931

  • Do not set a default Sort value until a ParentID is available on the Element.
  • Switch to "exit early" paradigm (easier to read).

Comment on lines +298 to +306
if ($this->hasExtension(Versioned::class)) {
$records = Versioned::get_by_stage(BaseElement::class, Versioned::DRAFT);
} else {
$records = BaseElement::get();
}

$records = $records->filter('ParentID', $this->ParentID);

$this->Sort = $records->max('Sort') + 1;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No changes here - just moved to "exit early" paradigm.

Comment on lines +293 to +296
// If no ParentID is currently set for the Element, then we don't want to define an initial Sort yet
if (!$this->ParentID) {
return;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The guts of the change.

Rationale detailed here:
#849 (comment)

Copy link
Contributor

@ScopeyNZ ScopeyNZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ScopeyNZ ScopeyNZ merged commit 461e3c0 into silverstripe:4.7 Oct 6, 2021
@chrispenny chrispenny deleted the bugfix/849-default-sort-value branch October 6, 2021 18:27
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