Skip to content

Commit

Permalink
Sort by ID by default
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Nov 22, 2024
1 parent 65cca80 commit bce2bdc
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Element indexes now sort by ID by default, for sources that don’t define a default sort option.
- Fixed a bug where element indexes were sorting by the first sortable attribute alphabetically by default, rather than the first sortable attribute defined by the element type.

## 4.13.2 - 2024-11-19
Expand Down
6 changes: 6 additions & 0 deletions src/base/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,12 @@ public static function sortOptions(): array
{
$sortOptions = static::defineSortOptions();

// Make sure ID is listed first
$sortOptions = [
'id' => Craft::t('app', 'ID'),
...ArrayHelper::without($sortOptions, 'id'),
];

// Give plugins a chance to modify them
$event = new RegisterElementSortOptionsEvent([
'sortOptions' => $sortOptions,
Expand Down
1 change: 0 additions & 1 deletion src/elements/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,6 @@ protected static function defineSortOptions(): array
'orderBy' => 'dateUpdated',
'defaultDir' => 'desc',
],
'id' => Craft::t('app', 'ID'),
'width' => Craft::t('app', 'Width'),
'height' => Craft::t('app', 'Height'),
];
Expand Down
1 change: 0 additions & 1 deletion src/elements/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ protected static function defineSortOptions(): array
'orderBy' => 'dateUpdated',
'defaultDir' => 'desc',
],
'id ' => Craft::t('app', 'ID'),
];
}

Expand Down
1 change: 0 additions & 1 deletion src/elements/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,6 @@ protected static function defineSortOptions(): array
'orderBy' => 'dateUpdated',
'defaultDir' => 'desc',
],
'id' => Craft::t('app', 'ID'),
];
}

Expand Down
2 changes: 0 additions & 2 deletions src/elements/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@ protected static function defineSortOptions(): array
'orderBy' => 'dateUpdated',
'defaultDir' => 'desc',
],
'id' => Craft::t('app', 'ID'),
];
} else {
$attributes = [
Expand All @@ -420,7 +419,6 @@ protected static function defineSortOptions(): array
'orderBy' => 'dateUpdated',
'defaultDir' => 'desc',
],
'id' => Craft::t('app', 'ID'),
];
}

Expand Down

0 comments on commit bce2bdc

Please sign in to comment.