Tried with both options, neither seem to affect the order of the results.

Comments

tim.plunkett’s picture

Status: Active » Needs review
StatusFileSize
new963 bytes

The results array is keyed by entity_id, in the order dictated by sort. Building a new array with numeric keys will ignore the order.

amitaibu’s picture

I tried sorting by title, and it worked for me. Can you explain your scenario when it doesn't work?

damien tournoud’s picture

Status: Needs review » Postponed (maintainer needs more info)
-      $entities = entity_load($entity_type, array_keys($results[$entity_type]));
+      $options = $results[$entity_type];
+      $entities = entity_load($entity_type, array_keys($options));

This has only one effect if you entity controller is broken and doesn't respect the order of the loaded IDs. Which one is it?

tim.plunkett’s picture

Status: Postponed (maintainer needs more info) » Active

In this case, $results[$entity_type] contains an array with 4 items, in the order 2, 1, 4, 3.
Before the patch, $options is an empty array, and as it's built, the keys go into numerical order, resulting in 1, 2, 3, 4.

By not building a new array, and just assigning the labels to the existing properly order keys, it works.

That said, I'm using http://drupal.org/project/webform_entity, which has resulted in me filing other bogus bugs...

But I do know that the efq returns a properly ordered set, and after this loop, they aren't ordered correctly anymore.

damien tournoud’s picture

Title: Sort is broken » WebformSubmissionsController::load() returns entities in incorrect order
Project: Entity reference » Webform Entity

Even if it is not properly documented, DrupalEntityControllerInterface::load() needs to return entities in the same order as passed in $ids. This is a bug in Webform Entity.

tim.plunkett’s picture

Thanks for your help, and patience with the misfiled bug reports :)

tim.plunkett’s picture

Assigned: tim.plunkett » Unassigned
drewish’s picture

@Damien Tournoud, is it just the order that's important or should all keys be returned? What about duplicates? Meaning if I request loading items array(3, 2, -99, 2, 4) what should come back?

// Only loadable entities?
array(
  3 => (some entity)
  2 => (some entity)
  4 => (some entity)
);
// Everything?
array(
  3 => (some entity)
  2 => (some entity)
  -99 => NULL,
  4 => (some entity)
);
// Or should it be based off the last time an id is seen?
array(
  3 => (some entity)
  -99 => NULL,
  2 => (some entity)
  4 => (some entity)
);
drewish’s picture

Status: Active » Needs review
StatusFileSize
new1.1 KB

  • tizzo committed e771b10 on 7.x-1.x authored by drewish
    Issue #1440340 by tim.plunkett, drewish: WebformSubmissionsController::...
tizzo’s picture

Issue summary: View changes
Status: Needs review » Fixed

Committed (2 years later) thanks!.

Status: Fixed » Closed (fixed)

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