Looks like groups are ordered by gid and not the name, so it it driving administrators crazy trying to find the correct group when there are hundreds listed (to them) in random order.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ZetaTrooper’s picture

Priority: Normal » Major

Its really bad when you expose the audience list to the user on registration to have them select a group from a long list of groups, and they can't find there group because it is not sorted alphabetically.

erikhopp’s picture

Version: 7.x-1.3 » 7.x-1.4
Status: Active » Needs review
FileSize
562 bytes

Hmmm. That was easy. Patch attached.

Status: Needs review » Needs work

The last submitted patch, sort_og_listing_alphabetically.patch, failed testing.

erikhopp’s picture

Version: 7.x-1.4 » 7.x-1.x-dev
Status: Needs work » Needs review
FileSize
502 bytes

I'll try that again.

Status: Needs review » Needs work

The last submitted patch, og-sort_listing_alphabetically-1567492-4.patch, failed testing.

erikhopp’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, og-sort_listing_alphabetically-1567492-4.patch, failed testing.

erikhopp’s picture

Well, I guess I need some help with this. It isn't clear to me why the tests are failing.

ZetaTrooper’s picture

Thank you so much for working on this. I wish I could offer some help but I don't have much expertise in this area.

Does the patch work for you?

edvanleeuwen’s picture

I have added the asort() manually and this works perfectly. I have not patched the file, so I do not know why that fails.

jday’s picture

I've also patched it manually and it works like a DREAM! Thank You erikhopp! I hope the change makes it into OG core.

Nephele’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, og-sort_listing_alphabetically-1567492-4.patch, failed testing.

Nephele’s picture

Status: Needs work » Needs review

#4: og-sort_listing_alphabetically-1567492-4.patch queued for re-testing.

The patch was failing originally because of #1748782: Existing 7.x-1.x-dev code always fails QA tests. The most recent failure was a testbot client malfunction. Try, try, try again....

Status: Needs review » Needs work

The last submitted patch, og-sort_listing_alphabetically-1567492-4.patch, failed testing.

Nephele’s picture

The latest failure of #4 was indeed a result of this patch -- but only because the QA test incorrectly assumed that the groups were listed in a given order. I've now changed the QA test so that it checks for the deletion/existence of groups without making assumptions about the order used for listing the groups.

Nephele’s picture

Status: Needs work » Needs review
amitaibu’s picture

@Nephele,
Off topic - when are you upgrading to 2.x? I'd love to get your high quality patches there as-well :)

Nephele’s picture

@Amitaibu: Although it might not look like it, I've been doing these patches because I'm in the middle of a 2.x upgrade. But since I need to step through 1.4 as part of the upgrade (#1754540: og_migrate does not migrate memberships from group_audience field), I've been getting getting caught up in 1.x issues first. Also, getting my site's custom modules updated with all the API changes in 2.x is taking some work. Hopefully I'll be starting to contribute more to 2.x soon -- which reminds me that I'd wanted to check on whether a 2.x version of #16 is needed....

visualnotion’s picture

#16: og-sort_listing_alphabetically-1567492-16.patch queued for re-testing.

Okay, I had an error thrown with this line on my autocomplete field placed on the user registration form:
drupal_set_message('sorted audience = '.serialize($audience));

I had it under this section:
case OG_AUDIENCE_AUTOCOMPLETE_WIDGET:

Moving it under this section fixed it:
case OG_AUDIENCE_WIDGET:

Edit: You can remove the drupal_set_message item, btw. It's for debugging.

Nephele’s picture

Oops, that line wasn't supposed to be in the patch.

HongPong’s picture

Has anyone looked at how to integrate this with 7.x-2.x? Or other ways/hooks to adjust large group audience lists in 7.x-2.x?

katannshaw’s picture

I'd definitely be interested in this patch for 7.x-2.x as well. I was very surprised that it wasn't already built-in to the field settings on the UI's "Manage Display" section for user accounts.

UPDATE:

The good news: They do have a built-in feature in 7.x-2.x under OG's people settings that allows you to sort the list of groups via entity.

The bad news: After making these changes, the group names on My account page are still showing up in the order they were created. If someone can let me know what step I'm missing, I'd appreciate it.

I thought that I'd still share where I found these settings:

1) Go to the field Admin > Config > People > Account Settings > Manage Fields at: admin/config/people/accounts/fields

2) Click "edit" next to the field named "og_user_node"

3) Under Group membership field settings > Entity selection, change the following settings:
Sort by: "Don't sort" > "A field attached to this entity
Sort field: Group (column value)
Sort direction: Ascending

4) Click "Save settings" button, run CRON and clear cache

stevehutchison’s picture

thanks for posting this. Its been bugging me for a while and your post pointed me in the right direction.

Instead of sorting by "A field attached to this entity" | Sort field: "Group (column value)"

I tried sorting by "A property of the base table of the entity" | Sort field: "Title"

... and that worked.

katannshaw’s picture

@stevehutchison: That's awesome that those steps worked for you; thanks for letting us know! For some reason, it's still not sorting properly for me, but I'll (hopefully) figure it out eventually. Thanks.

BrightBold’s picture

Issue summary: View changes

I want to sort on a field other than the group name, so like @jayhawkfan75 I tried both the "Sort by a field attached to this entity" and "Sort by a property of the base table of the entity" and it works when editing the user account but not when viewing it. Since this issue is focused on alphabetical sorting by default (and I actually want to sort by a field other than title), I've filed a separate issue for that bug at https://github.com/Gizra/og/issues/87.

jeffschuler’s picture

Setting the sort criteria as described in #23 will only affect the ordering of groups when editing the field value (choosing a user's groups).

To set the display order, you can add a preprocess function:

/**
 * Implements hook_preprocess_field().
 *
 * Alphabetically sort the display of a user's group membership list,
 * shown on the user page.
 */
function example_preprocess_field(&$variables) {
  if ($variables['element']['#field_name'] == 'og_user_node') {
    usort($variables['items'], '_compare_title_strings');
  }
}

/**
 * String-compare the '#title' element of two provided associative arrays.
 *
 * For use as a usort() callback.
 */
function _compare_title_strings($a, $b) {
  return strcasecmp($a['#title'], $b['#title']);
}