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

🐛 (cms interface) applies default sort order to CMS ordering #325

Merged
merged 4 commits into from
Feb 2, 2022

Conversation

davejtoews
Copy link
Contributor

This allows secondary sort ordering to be applied when it exists and when the objects have not been sorted manually.

This attempts to address #324. It could use some sanity checks and testing, but it is working as needed in my application. It was an open question to me whether this was the best way to address it or whether additional sort fields should be applied via a similar mechanism as what exists for $extraSortFields. My preference was for the component to automatically pick up on default sorts, but applying sort through another method would make sense to me too.

davejtoews and others added 2 commits August 24, 2021 11:12
This allows secondary sort ordering to be applied when it exists and when the objects have not been sorted manually
@@ -359,7 +360,15 @@ public function getManipulatedData(GridField $grid, SS_List $list)
// Fix bug in 3.1.3+ where ArrayList doesn't account for quotes
$sortterm .= $this->getSortTable($list).'.'.$this->getSortField();
} else {
// If not an ArrayList it's definitely a DataList right?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nope. The param says SS_List (which is an interface) and there are more classes implementing it than just ArrayList and DataList. It's also extended to Sortable which may be implemented by yet another set of classes, so we can't assume the ->dataClass() method is available without further checks.

Copy link
Contributor Author

@davejtoews davejtoews Nov 25, 2021

Choose a reason for hiding this comment

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

You're right! I missed the sub-interfaces of SS_List.

Happy to alter the PR. I'm thinking of just directly checking method_exists($list, 'dataClass') or do you think $list instanceof DataList would be cleaner?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would check for the DataList and only apply the default sort as the secondary ordering there

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checking for a DataList now.

if (Config::inst()->get($list->dataClass(), 'default_sort')) {
// Append the default sort to the end of the sort string
// This may result in redundancy... but it seems to work
$sortterm .= ', ' . Config::inst()->get($classname, 'default_sort');
Copy link
Collaborator

Choose a reason for hiding this comment

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

$sorttterm can be an empty string here, so we can't start with the comma here, will need further logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adjusted to only add a comma when the string is not empty.

@emteknetnz emteknetnz merged commit 6d6cf4a into symbiote:3 Feb 2, 2022
@emteknetnz
Copy link
Collaborator

I've created a follow up unit-test PR for this here #329

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.

4 participants