From 9ccbd106a87a1742a61cc4df0e9ead921046772a Mon Sep 17 00:00:00 2001 From: Brett Profitt Date: Mon, 27 Aug 2012 15:57:47 -0400 Subject: Refs #4381. Cleanup for group sticky forms. Moved logic out of view into groups_prepare_form_vars(). Made group tool options sticky. --- mod/groups/lib/groups.php | 62 ++++++++++++++++++++++++++ mod/groups/views/default/forms/groups/edit.php | 48 +++++--------------- mod/groups/views/default/groups/edit.php | 4 +- 3 files changed, 75 insertions(+), 39 deletions(-) (limited to 'mod/groups') diff --git a/mod/groups/lib/groups.php b/mod/groups/lib/groups.php index dfbb1154b..505cacd01 100644 --- a/mod/groups/lib/groups.php +++ b/mod/groups/lib/groups.php @@ -497,3 +497,65 @@ function groups_register_profile_buttons($group) { } } } + +/** + * Prepares variables for the group edit form view. + * + * @param mixed $group ElggGroup or null. If a group, uses values from the group. + * @return array + */ +function groups_prepare_form_vars($group = null) { + $values = array( + 'name' => '', + 'membership' => ACCESS_PUBLIC, + 'vis' => ACCESS_PUBLIC, + 'guid' => null, + 'entity' => null + ); + + // handle customizable profile fields + $fields = elgg_get_config('group'); + + if ($fields) { + foreach ($fields as $name => $type) { + $values[$name] = ''; + } + } + + // 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'; + } + } + + // get current group settings + if ($group) { + foreach (array_keys($values) as $field) { + if (isset($group->$field)) { + $values[$field] = $group->$field; + } + } + + if ($group->access_id != ACCESS_PUBLIC && $group->access_id != ACCESS_LOGGED_IN) { + // group only access - this is done to handle access not created when group is created + $values['vis'] = ACCESS_PRIVATE; + } + + $values['entity'] = $group; + } + + // get any sticky form settings + if (elgg_is_sticky_form('groups')) { + $sticky_values = elgg_get_sticky_values('groups'); + foreach ($sticky_values as $key => $value) { + $values[$key] = $value; + } + } + + elgg_clear_sticky_form('groups'); + + return $values; +} diff --git a/mod/groups/views/default/forms/groups/edit.php b/mod/groups/views/default/forms/groups/edit.php index 7540d1bf9..532e89c35 100644 --- a/mod/groups/views/default/forms/groups/edit.php +++ b/mod/groups/views/default/forms/groups/edit.php @@ -5,26 +5,9 @@ * @package ElggGroups */ -if (elgg_is_sticky_form('groups')) { - $sticky_values = elgg_get_sticky_values('groups'); - elgg_clear_sticky_form('groups'); -} - -// new groups default to open membership -if (isset($sticky_values)) { - $membership = $sticky_values['membership']; - $access = $sticky_values['access_id']; -} elseif (isset($vars['entity'])) { - $membership = $vars['entity']->membership; - $access = $vars['entity']->access_id; - if ($access != ACCESS_PUBLIC && $access != ACCESS_LOGGED_IN) { - // group only - this is done to handle access not created when group is created - $access = ACCESS_PRIVATE; - } -} else { - $membership = ACCESS_PUBLIC; - $access = ACCESS_PUBLIC; -} +// only extract these elements. +$name = $membership = $vis = $entity = null; +extract($vars, EXTR_IF_EXISTS); ?>
@@ -35,7 +18,7 @@ if (isset($sticky_values)) {
'name', - 'value' => isset($sticky_values['name']) ? $sticky_values['name'] : $vars['entity']->name, + 'value' => $name )); ?>
@@ -53,7 +36,7 @@ if ($group_profile_fields > 0) { echo "$line_break"; echo elgg_view("input/{$valtype}", array( 'name' => $shortname, - 'value' => isset($sticky_values[$shortname]) ? $sticky_values[$shortname] : $vars['entity']->$shortname, + 'value' => elgg_extract($shortname, $vars) )); echo ''; } @@ -78,10 +61,6 @@ if ($group_profile_fields > 0) { owner_guid; - if (!$this_owner) { - $this_owner = elgg_get_logged_in_user_guid(); - } $access_options = array( ACCESS_PRIVATE => elgg_echo('groups:access:group'), ACCESS_LOGGED_IN => elgg_echo("LOGGED_IN"), @@ -94,7 +73,7 @@ if (elgg_get_plugin_setting('hidden_groups', 'groups') == 'yes') {
'vis', - 'value' => $access, + 'value' => $vis, 'options_values' => $access_options, )); ?> @@ -109,12 +88,7 @@ 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"; - if ($group_option->default_on) { - $group_option_default_value = 'yes'; - } else { - $group_option_default_value = 'no'; - } - $value = $vars['entity']->$group_option_toggle_name ? $vars['entity']->$group_option_toggle_name : $group_option_default_value; + $value = elgg_extract($group_option_toggle_name, $vars); ?>