Beispiel #1
0
/**
 * 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, 'owner_guid' => elgg_get_logged_in_user_guid(), 'content_access_mode' => ElggGroup::CONTENT_ACCESS_MODE_UNRESTRICTED);
    // handle customizable profile fields
    $fields = elgg_get_config('group');
    if ($fields) {
        foreach ($fields as $name => $type) {
            $values[$name] = '';
        }
    }
    // handle tool options
    $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
    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;
        } else {
            $values['vis'] = $group->access_id;
        }
        // The content_access_mode was introduced in 1.9. This method must be
        // used for backwards compatibility with groups created before 1.9.
        $values['content_access_mode'] = $group->getContentAccessMode();
        $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;
}
Beispiel #2
0
        // The group profile displays all profile fields that have a value.
        // We don't want to display fields with empty string value, so we
        // remove the metadata completely.
        $group->deleteMetadata($shortname);
        continue;
    }
    $group->{$shortname} = $value;
}
// Validate create
if (!$group->name) {
    register_error(elgg_echo("groups:notitle"));
    forward(REFERER);
}
// 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";
        $option_default = $group_option->default_on ? 'yes' : 'no';
        $value = get_input($option_toggle_name);
        // if already has option set, don't change if no submission
        if ($group->{$option_toggle_name} && $value === null) {
            continue;
        }
        $group->{$option_toggle_name} = $value ? $value : $option_default;
    }
}
// Group membership - should these be treated with same constants as access permissions?
$value = get_input('membership');
if ($group->membership === null || $value !== null) {
Beispiel #3
0
<?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(['#tag_name' => 'div', '#text' => elgg_view('input/checkbox', ['name' => $group_option_toggle_name, 'value' => 'yes', 'default' => 'no', 'checked' => $value === 'yes' ? true : false, 'label' => $group_option->label])]);
}