Skip to content

Instantly share code, notes, and snippets.

@juho-jaakkola
Last active August 29, 2015 13:59
Show Gist options
  • Save juho-jaakkola/10976786 to your computer and use it in GitHub Desktop.
Save juho-jaakkola/10976786 to your computer and use it in GitHub Desktop.
<?php
elgg_register_event_handler('init', 'system', 'my_init');
function my_init () {
elgg_register_plugin_hook_handler('access:collections:write', 'all', 'my_acl_options');
}
/**
* Allow selecting any group as read/write access regardless of page context
*
* By default read/write access to group content can be set only for the group
* that is container of the content. This handler allows acl to be set as any
* group even when creating content outside groups.
*
* @param string $hook 'access:collections:write'
* @param string $type 'user'
* @param array $return Array of "Acl id => Acl name" pairs
* @param array $param Array with user_id and site_id
* @return array $return
*/
function my_acl_options($hook, $type, $return, $params) {
$user_guid = $params['user_id'];
$user = get_entity($user_guid);
if (!$user) {
return $return;
}
$groups = elgg_get_entities_from_relationship(array(
'type' => 'group',
'relationship' => 'member',
'relationship_guid' => $user_guid,
'inverse_relationship' => FALSE,
'limit' => false,
));
if ($groups) {
foreach ($groups as $group) {
$return[$group->group_acl] = elgg_echo('groups:group') . ': ' . $group->name;
}
}
return $return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment