/** * Change the name/function of the group join button * * @param string $hook the name of the hook * @param string $type the type of the hook * @param \ElggMenuItem[] $return_value current return value * @param array $params supplied params * * @return void|\ElggMenuItem[] */ public static function groupMembership($hook, $type, $return_value, $params) { if (!elgg_in_context('groups')) { return; } $page_owner = elgg_get_page_owner_entity(); $user = elgg_get_logged_in_user_entity(); if (!$page_owner instanceof \ElggGroup || !$user instanceof \ElggUser) { return; } if (empty($return_value) || !is_array($return_value)) { return; } foreach ($return_value as $menu_item) { // group join button? if ($menu_item->getName() !== 'groups:joinrequest') { continue; } if (check_entity_relationship($user->getGUID(), 'membership_request', $page_owner->getGUID())) { // user already requested to join this group $menu_item->setText(elgg_echo('group_tools:joinrequest:already')); $menu_item->setTooltip(elgg_echo('group_tools:joinrequest:already:tooltip')); $menu_item->setHref("action/groups/killrequest?user_guid={$user->getGUID()}&group_guid={$page_owner->getGUID()}"); $menu_item->is_action = true; } elseif (check_entity_relationship($page_owner->getGUID(), 'invited', $user->getGUID())) { // the user was invited, so let him/her join $menu_item->setName('groups:join'); $menu_item->setText(elgg_echo('groups:join')); $menu_item->setTooltip(elgg_echo('group_tools:join:already:tooltip')); $menu_item->setHref("action/groups/join?user_guid={$user->getGUID()}&group_guid={$page_owner->getGUID()}"); $menu_item->is_action = true; } elseif (group_tools_check_domain_based_group($page_owner, $user)) { // user has a matching email domain $menu_item->setName('groups:join'); $menu_item->setText(elgg_echo('groups:join')); $menu_item->setTooltip(elgg_echo('group_tools:join:domain_based:tooltip')); $menu_item->setHref("action/groups/join?user_guid={$user->getGUID()}&group_guid={$page_owner->getGUID()}"); $menu_item->is_action = true; } elseif (group_tools_join_motivation_required($page_owner)) { // a join motivation is required elgg_load_js('lightbox'); elgg_load_css('lightbox'); $menu_item->setHref("ajax/view/group_tools/forms/motivation?guid={$page_owner->getGUID()}"); $menu_item->addLinkClass('elgg-lightbox'); $opts = 'data-colorbox-opts'; $menu_item->{$opts} = json_encode(['width' => '500px']); } break; } return $return_value; }
/** * Change the join status menu item * * @param string $hook the name of the hook * @param string $type the type of the hook * @param \ElggMenuItem[] $return_value current return value * @param array $params supplied params * * @return void|\ElggMenuItem[] */ public static function registerJoinStatus($hook, $type, $return_value, $params) { $entity = elgg_extract('entity', $params); if (!$entity instanceof \ElggGroup) { return; } $user = elgg_get_logged_in_user_entity(); if (empty($user)) { return; } foreach ($return_value as $menu_item) { if ($menu_item->getName() !== 'membership_status') { continue; } if ($menu_item->getText() !== elgg_echo('groups:join')) { // @todo this should be nicer, but Elgg give the same name to 3 use cases??!!! continue; } if (check_entity_relationship($user->getGUID(), 'membership_request', $entity->getGUID())) { // user already requested to join this group $menu_item->setText(elgg_echo('group_tools:joinrequest:already')); $menu_item->setTooltip(elgg_echo('group_tools:joinrequest:already:tooltip')); $menu_item->setHref("action/groups/killrequest?user_guid={$user->getGUID()}&group_guid={$entity->getGUID()}"); $menu_item->is_action = true; } elseif (check_entity_relationship($entity->getGUID(), 'invited', $user->getGUID())) { // the user was invited, so let him/her join $menu_item->setTooltip(elgg_echo('group_tools:join:already:tooltip')); } elseif (group_tools_check_domain_based_group($entity, $user)) { // user has a matching email domain $menu_item->setTooltip(elgg_echo('group_tools:join:domain_based:tooltip')); } elseif (group_tools_join_motivation_required($entity)) { // a join motivation is required elgg_load_js('lightbox'); elgg_load_css('lightbox'); $menu_item->setHref("ajax/view/group_tools/forms/motivation?guid={$entity->getGUID()}"); $menu_item->addLinkClass('elgg-lightbox'); $opts = 'data-colorbox-opts'; $menu_item->{$opts} = json_encode(['width' => '500px']); } } }
// admins has not yet approved the group, store wanted access $group->intended_access_id = $visibility; } else { // already approved group $access_id = $visibility; } } } // set access $group->access_id = $access_id; if (!$group->save()) { register_error(elgg_echo("groups:save_error")); forward(REFERER); } // join motivation if (!$group->isPublicMembership() && group_tools_join_motivation_required()) { $join_motivation = get_input('join_motivation'); $group->setPrivateSetting('join_motivation', $join_motivation); } else { $group->removePrivateSetting('join_motivation'); } // default access $default_access = (int) get_input('group_default_access'); if ($group->getContentAccessMode() === ElggGroup::CONTENT_ACCESS_MODE_MEMBERS_ONLY && ($default_access === ACCESS_PUBLIC || $default_access === ACCESS_LOGGED_IN)) { system_message(elgg_echo('group_tools:action:group:edit:error:default_access')); $default_access = (int) $group->group_acl; } $group->setPrivateSetting("elgg_default_access", $default_access); // group saved so clear sticky form elgg_clear_sticky_form('groups'); // group creator needs to be member of new group and river entry created
* This view contains everything related to group access. * eg: how can people join this group, who can see the group, etc * * @package ElggGroups */ // load js elgg_require_js('group_tools/group_edit'); $entity = elgg_extract("entity", $vars, false); $membership = elgg_extract("membership", $vars); $visibility = elgg_extract("vis", $vars); $owner_guid = elgg_extract("owner_guid", $vars); $content_access_mode = elgg_extract("content_access_mode", $vars); $default_access = elgg_extract("group_default_access", $vars, ACCESS_DEFAULT); $show_visibility = elgg_get_plugin_setting("hidden_groups", "groups") == "yes"; $show_visibility = $show_visibility && (empty($entity->guid) || $entity->access_id !== ACCESS_PRIVATE); $show_motivation_option = group_tools_join_motivation_required(); $motivation_plugin_setting = elgg_get_plugin_setting('join_motivation', 'group_tools', 'no'); $show_motivation_option = $show_motivation_option && strpos($motivation_plugin_setting, 'yes') === 0; ?> <div> <label for="groups-membership"><?php echo elgg_echo("groups:membership"); ?> </label><br /> <?php echo elgg_view("input/select", array("name" => "membership", "id" => "groups-membership", "value" => $membership, "options_values" => array(ACCESS_PRIVATE => elgg_echo("groups:access:private"), ACCESS_PUBLIC => elgg_echo("groups:access:public")), "onchange" => "elgg.group_tools.show_join_motivation(this);")); ?> </div> <?php if ($show_motivation_option) { $checked = $motivation_plugin_setting === 'yes_on';