Permalink
Browse files

feature(groups): introduced a hook to influence group tool options

fixes #9497
  • Loading branch information...
jdalsem committed Mar 18, 2016
1 parent b931e22 commit b6617e5ea33609ae32dfd9f9af404b42e85609dd
@@ -523,6 +523,9 @@ Groups
**profile_buttons, group**
Filters buttons (``ElggMenuItem`` instances) to be registered in the title menu of the group profile page
**tool_options, group**
Use this hook to influence the available group tool options
HTMLawed
--------
@@ -93,8 +93,9 @@
forward(REFERER);
}
// Set group tool options
$tool_options = elgg_get_config('group_tool_options');
// Set group tool options (only pass along saved entities)
$tool_entity = !$is_new_group ? $group : null;
$tool_options = groups_get_group_tool_options($tool_entity);
if ($tool_options) {
foreach ($tool_options as $group_option) {
$option_toggle_name = $group_option->name . "_enable";
View
@@ -51,12 +51,11 @@ function groups_prepare_form_vars($group = null) {
}
// handle tool options
$tools = elgg_get_config('group_tool_options');
if ($tools) {
foreach ($tools as $group_option) {
$option_name = $group_option->name . "_enable";
$values[$option_name] = $group_option->default_on ? 'yes' : 'no';
}
$entity = ($group instanceof \ElggGroup) ? $group : null;
$tools = groups_get_group_tool_options($entity);
foreach ($tools as $group_option) {
$option_name = $group_option->name . "_enable";
$values[$option_name] = $group_option->default_on ? 'yes' : 'no';
}
// get current group settings
@@ -93,3 +92,22 @@ function groups_prepare_form_vars($group = null) {
return $values;
}
/**
* Function to return available group tool options
*
* @param \ElggGroup $group optional group
*
* @return array
*/
function groups_get_group_tool_options(\ElggGroup $group = null) {
$tool_options = elgg_get_config('group_tool_options');
$hook_params = [
'group_tool_options' => $tool_options,
'entity' => $group,
];
return (array) elgg_trigger_plugin_hook('tool_options', 'group', $hook_params, $tool_options);
}
View
@@ -16,7 +16,8 @@
function groups_init() {
elgg_register_library('elgg:groups', __DIR__ . '/lib/groups.php');
elgg_load_library('elgg:groups');
// register group entities for search
elgg_register_entity_type('group', '');
@@ -242,8 +243,6 @@ function groups_setup_sidebar_menus() {
*/
function groups_page_handler($page) {
elgg_load_library('elgg:groups');
if (!isset($page[0])) {
$page[0] = 'all';
}
@@ -1,27 +1,31 @@
<?php
/**
* Group edit form
*
* This view contains the group tool options provided by the different plugins
*
* @package ElggGroups
*/
$tools = elgg_get_config("group_tool_options");
if ($tools) {
usort($tools, create_function('$a, $b', 'return strcmp($a->label, $b->label);'));
foreach ($tools as $group_option) {
$group_option_toggle_name = $group_option->name . "_enable";
$value = elgg_extract($group_option_toggle_name, $vars);
echo elgg_format_element('div', [], elgg_view('input/checkbox', array(
'name' => $group_option_toggle_name,
'value' => 'yes',
'default' => 'no',
'checked' => ($value === 'yes') ? true : false,
'label' => $group_option->label
)));
}
}
<?php
/**
* Group edit form
*
* This view contains the group tool options provided by the different plugins
*
* @package ElggGroups
*/
$tools = groups_get_group_tool_options(elgg_extract('entity', $vars));
if (empty($tools)) {
return;
}
usort($tools, function($a, $b) {
return strcmp($a->label, $b->label);
});
foreach ($tools as $group_option) {
$group_option_toggle_name = $group_option->name . "_enable";
$value = elgg_extract($group_option_toggle_name, $vars);
echo elgg_format_element('div', [], elgg_view('input/checkbox', array(
'name' => $group_option_toggle_name,
'value' => 'yes',
'default' => 'no',
'checked' => ($value === 'yes') ? true : false,
'label' => $group_option->label
)));
}

0 comments on commit b6617e5

Please sign in to comment.