The "edit membership" View field is a bit annoying because in order to leave a group, you have to click link, then another, then confirm the form (3 actions).

Attached is a patch to provide a "Leave group" Views field. When clicked, it will bring you directly to the confirm form to leave the group. If you're the group owner, and can't leave the group, it will bring you to the normal page which warns you about this.

Comments

soulfroys’s picture

It works great! Thank you!
(Drupal 6.20, OG 6.x-2.1)

ezra-g’s picture

Status: Active » Needs review

Marking as "needs review".

Grayside’s picture

Status: Needs review » Needs work

Looks good. A few standards need tweaking.

+++ b/modules/og_views/includes/og_views_handler_field_og_leave_group.incundefined
@@ -0,0 +1,43 @@
+<?php
+class og_views_handler_field_og_leave_group extends og_views_handler_field_og_uid {

No comment describing handler.

+++ b/modules/og_views/includes/og_views_handler_field_og_leave_group.incundefined
@@ -0,0 +1,43 @@
+      global $user;

Early as possible in the function please. In this case, top of the code block.

+++ b/modules/og_views/includes/og_views_handler_field_og_leave_group.incundefined
@@ -0,0 +1,43 @@
+      // Make sure the user is a member
...
+        // If the user is the group owner, they can't leave, so send them

Periods

Grayside’s picture

Issue tags: +handler

Adding tag.

soulfroys’s picture

Marked #888154: no leave group link field in views? as duplicated of this one.

soulfroys’s picture

Version: 6.x-2.1 » 6.x-2.x-dev
Status: Needs work » Needs review
StatusFileSize
new3.31 KB

Hello @Grayside!
I made a patch with the fixes (last dev), but I don't have git, does it help? Works great for me.

Grayside’s picture

Looking good!

If a user can't leave the group, why show a link at all?

domignon’s picture

soulfroys’s picture

Yes, you're right...

Grayside’s picture

I would think the leaner UI of not showing anything would be cleaner. Is there a particular reason you feel the verbosity of "Closed" is helpful?

soulfroys’s picture

StatusFileSize
new43.23 KB
new55.53 KB

Without the "t('Closed')", the code should look like this:

-    if (in_array($nid, array_keys($user->og_groups))) {
+    if (in_array($nid, array_keys($user->og_groups)) && $values->og_og_selective != OG_CLOSED) {
        $text = !empty($this->options['text']) ? $this->options['text'] : t('Leave group');
        // If the user is the group owner, they can't leave, so send them
        // to the manage page so the message displays.
        if ($user->uid == $uid) {
          return l($text, "og/manage/{$nid}", array('query' => drupal_get_destination()));
        }
        else {
          return l($text, "og/unsubscribe/{$nid}/{$user->uid}", array('query' => drupal_get_destination()));
        }
      }

But it will not show anything, getting a hole in the view:

With the "t('Closed')", looks like this:

@mikestefff, What do you think?

greggles’s picture

It makes sense to me to see "Closed" - otherwise I'd be confused about why I can't leave the group.

Grayside’s picture

In that case, does "Closed" really inform you of why you can't leave the group?

mstef’s picture

Agree something should be said if you can't leave the group, but good point about how "Closed" doesn't really explain anything. Not sure what would work best there.

Grayside’s picture

Status: Needs review » Needs work
Issue tags: +Usability

Required
Locked

alexlim’s picture

Hello Guys,

after i patch the og, i added them to as views field but the result end up with duplicated views..distinct not working too..

hope someone can help

Thanks!

Grayside’s picture

Hi @alexlim!

This issue is for a work-in-progress feature request which has work done on it sporadically at best. That you found a bug is not surprising, and will be helpful to any developer that decides to come forward and resume work on this.

In the meantime, the patch is not really supported, and if there are problems with it I recommend you remove it from your codebase.

soulfroys’s picture

StatusFileSize
new40.32 KB

@alexlim, could you please post your Views export and a screenshot of the complete Views-Display?
My view works great:
view og_all
[EDITED]
Sorry!!! I just fixed the image url...

claudiu.cristea’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)

This version of Drupal is not supported anymore. If this is still an issue in the 8.x-1.x branch, please open a new up-to-date ticket. Closing.