Skip to content

Commit

Permalink
Merge branch '4.x' of https://github.com/craftcms/cms into 5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Nov 22, 2024
2 parents 0681a7f + bce2bdc commit 59fde0a
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.

## 5.5.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 @@ -1411,6 +1411,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'),
];

// Fire a 'registerSortOptions' event
if (Event::hasHandlers(static::class, self::EVENT_REGISTER_SORT_OPTIONS)) {
$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 @@ -586,7 +586,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 @@ -315,7 +315,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 @@ -580,7 +580,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 @@ -421,7 +421,6 @@ protected static function defineSortOptions(): array
'orderBy' => 'dateUpdated',
'defaultDir' => 'desc',
],
'id' => Craft::t('app', 'ID'),
];
} else {
$attributes = [
Expand All @@ -445,7 +444,6 @@ protected static function defineSortOptions(): array
'orderBy' => 'dateUpdated',
'defaultDir' => 'desc',
],
'id' => Craft::t('app', 'ID'),
];
}

Expand Down

0 comments on commit 59fde0a

Please sign in to comment.