If you change the order of shortcuts it makes no difference to the order they are actually displayed.

Comments

geertvd’s picture

StatusFileSize
new768 bytes
geertvd’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 1: shortcuts_not_sorted-2415645-1.patch, failed testing.

alexpott’s picture

Status: Needs work » Needs review
Issue tags: +Needs tests
StatusFileSize
new3.43 KB

I imagined that the fix would be more like this.

We also need to add a test to ensure we don't break this again.

Status: Needs review » Needs work

The last submitted patch, 4: 2415645.3.patch, failed testing.

alexpott’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new1.32 KB
new2.25 KB
new5.68 KB

Added a test and fixed the test the got broke.

The last submitted patch, 6: 2415645.test-only.patch, failed testing.

geertvd’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, I agree doing the sort in getShortcuts is a better solution then what I came up with.
Test looks good also.

amateescu’s picture

+++ b/core/modules/shortcut/src/Entity/Shortcut.php
@@ -183,4 +183,21 @@ public function getCacheTags() {
+  public static function sort(array &$shortcuts) {

Wouldn't it look better if we put this in the ShortcutSet class?

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 6: 2415645.6.patch, failed testing.

Status: Needs work » Needs review

geertvd queued 6: 2415645.6.patch for re-testing.

alexpott’s picture

Status: Needs review » Reviewed & tested by the community

re #9 I think sorting of shortcuts should be handled by the Shortcut entity. Setting back to rtbc as per #8

amateescu’s picture

The $shortcuts array passed to the new sort() method is basically a shortcut set. Isn't it semantically correct that we're sorting a set of shortcuts, hence ShortcutSet::sort()?

By the reasoning in #12, should we move getShortcuts() to the Shortcut class as well?

geertvd’s picture

Shouldn't new sort() function just contain the comparison function and the uasort be done in getShortcuts().

Something like this:


public static function sort(ShortcutInterface $a, ShortcutInterface $b) {
  $a_weight = $a->getWeight();
  $b_weight = $b->getWeight();
  if ($a_weight == $b_weight) {
    return strnatcasecmp($a->getTitle(), $b->getTitle());
  }
  return ($a_weight < $b_weight) ? -1 : 1;
}

and then getShortcuts() should be this

public function getShortcuts() {
  $shortcuts = \Drupal::entityManager()->getStorage('shortcut')->loadByProperties(array('shortcut_set' => $this->id()));
  uasort($shortcuts, array('\Drupal\shortcut\Entity\Shortcut', 'sort'));
  return $shortcuts;
}

This seems more consistent with what other core modules are doing.

alexpott’s picture

@geertvd I thought about doing it that way too... I copied Language::sort. If you think that is better then go for it. I concede it is more flexible :)

geertvd’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new1.92 KB
new5.75 KB

As discussed.

amateescu’s picture

+++ b/core/modules/shortcut/src/Entity/Shortcut.php
@@ -186,18 +186,23 @@ public function getCacheTags() {
+   * @param array $a
+   *   First item for comparison.
+   * @param array $b
+   *   Second item for comparison.

These are ShortcutInterface objects, not arrays :)

geertvd’s picture

StatusFileSize
new576 bytes
new5.81 KB
amateescu’s picture

Status: Needs review » Reviewed & tested by the community

Cool, thanks!

  • catch committed 151e339 on 8.0.x
    Issue #2415645 by geertvd, alexpott: Shortcuts not sorted on display
    
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.0.x, thanks!

wim leers’s picture

HURRAY! Shortcut Sanity!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.