admin/config/group/group-membership/manage/og_membership_type_default/fields

I'd like to request feature that user can change the field's value after accepted to the Group.

For example if there's a field that asks users for "other site's username", then after the user has been accepted to the group there would be some way the user can change the value he/she entered to "other site's username" field.

Comments

johnnydarkko’s picture

I wanted to allow users to edit their own membership and this is how I was able to achieve this. Hope this helps you and anyone else trying to find this answer, ifish! I was able to achieve this by creating a custom module (referred to as mymodule here).

First, I created an og permission to allow the admin to configure who can edit their own og membership entity:

<?php
/**
 * Implements hook_og_permission().
 */
function mymodule_og_permission() {
  $permissions = array(
    'manage own membership' => array(
      'title' => t('Manage own membership'),
      'description' => t('Allow a user to edit their own membership.'),
    ),
  );
  return $permissions;
}
?>

Then, I implemented hook_menu_alter to override the access control over the og_membership edit page:

<?php
/**
 * Implements hook_menu_alter().
 */
function mymodule_menu_alter(&$items) {
  // Override the access control over the og_membership edit page.
  $items['group/%/%/admin/people/edit-membership/%og_membership']['access callback'] = 'mymodule_edit_membership_access';
  $items['group/%/%/admin/people/edit-membership/%og_membership']['access arguments'] = array(6);
}
?>

The custom access callback will replace the callback provided by og_ui.module.

<?php
/**
 * Helper function to determine if a user has access to edit a member's OG membership entity.
 *
 * @param object $og_membership
 *   OG Membership Entity.
 * @return boolean
 */
function mymodule_edit_membership_access($og_membership) {
  // If user has the stock OG permission to manage members, return TRUE.
  if (og_ui_user_access_group('manage members', $og_membership->group_type, $og_membership->gid)) {
    return TRUE;
  }
  // Get currently logged-in user account information.
  global $user;
  $account = user_load($user->uid);
  // If user has the OG permission to manage their own membership and the logged-in user is the same as the UID in the og_membership entity, return TRUE.
  if (og_ui_user_access_group('manage own membership', $og_membership->group_type, $og_membership->gid) && ($account->uid == $og_membership->etid)) {
    return TRUE;
  }
  // Else, deny access.
  return FALSE;
}
?>

Hope this helps!

jemisond’s picture

Issue summary: View changes

@johnnydarkko- great help- thanks!!

One minor issue- you're missing a closing curly brace at the end of function mymodule_og_permission().

The problem that I have with the implementation is that the user now gets to modify his own roles and can give himself a higher role.

johnnydarkko’s picture

aha! good catch @jemisond! Added that missing closing bracket to my comment above.

pixelsweatshop’s picture

@johnnydarkko. This is a nice little module to add that functionality. Any thoughts on releasing it on D.O?