Skip to content

Commit

Permalink
fixed: if widget_manager is not active use single group selector
Browse files Browse the repository at this point in the history
fixes #158
  • Loading branch information
jdalsem committed Oct 7, 2020
1 parent f5aaf36 commit e644ed6
Showing 1 changed file with 40 additions and 15 deletions.
55 changes: 40 additions & 15 deletions views/default/widgets/group_river_widget/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,46 @@

// only allow a group picker if not in a group already
if ($widget->context !== 'groups') {

$group_picker_options = [
'#type' => 'grouppicker',
'#label' => elgg_echo('widgets:group_river_widget:edit:group'),
'name' => 'params[group_guid]',
'value' => $widget->group_guid,
'options' => [],
];

$owner = $widget->getOwnerEntity();
if ($owner instanceof ElggUser) {
$group_picker_options['options']['match_target'] = $owner->guid;
$group_picker_options['options']['match_owner'] = false;
$group_picker_options['options']['match_membership'] = true;
}

echo elgg_view_field($group_picker_options);
if (elgg_is_active_plugin('widget_manager')) {
$group_picker_options = [
'#type' => 'grouppicker',
'#label' => elgg_echo('widgets:group_river_widget:edit:group'),
'name' => 'params[group_guid]',
'value' => $widget->group_guid,
'options' => [],
];

if ($owner instanceof \ElggUser) {
$group_picker_options['options']['match_target'] = $owner->guid;
$group_picker_options['options']['match_owner'] = false;
$group_picker_options['options']['match_membership'] = true;
}

echo elgg_view_field($group_picker_options);
} else {
// Widget owner might not be a user entity (e.g. on default widgets config page it's an ElggSite entity)
if (!$owner instanceof \ElggUser) {
$owner = elgg_get_logged_in_user_entity();
}

$groups = $owner->getGroups(['limit' => false]);

$mygroups = [];
if (!$widget->group_guid) {
$mygroups[0] = '';
}
foreach ($groups as $group) {
$mygroups[$group->guid] = $group->getDisplayName();
}

echo elgg_view_field([
'#type' => 'select',
'name' => 'params[group_guid]',
'#label' => elgg_echo('widgets:group_river_widget:edit:group'),
'value' => $widget->group_guid,
'options_values' => $mygroups,
]);
}
}

0 comments on commit e644ed6

Please sign in to comment.