Skip to content

Commit

Permalink
added: plugin setting to allow normal users to manage index widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalsem committed Jun 7, 2018
1 parent 1a879bc commit ada86bf
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions languages/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
'widget_manager:settings:index_top_row:none' => "No top row",
'widget_manager:settings:index_top_row:full_row' => "Full width row",
'widget_manager:settings:index_top_row:two_column_left' => "Two column aligned left",
'widget_manager:settings:index_managers' => "Index managers",

'widget_manager:settings:group:enable' => "Enable Widget Manager for groups",
'widget_manager:settings:group:enable:yes' => "Yes, managable by group tool option",
Expand Down
30 changes: 29 additions & 1 deletion lib/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function widget_manager_widget_layout_permissions_check($hook_name, $entity_type
$page_owner = elgg_extract('page_owner', $params);
$user = elgg_extract('user', $params);
$context = elgg_extract('context', $params);

if (!$return_value && ($user instanceof ElggUser)) {
if (($page_owner instanceof ElggGroup) && $page_owner->canEdit($user->getGUID())) {
// group widget layout
Expand All @@ -137,6 +137,12 @@ function widget_manager_widget_layout_permissions_check($hook_name, $entity_type
}
}
}
} elseif ($context === 'index') {
$index_managers = explode(',', elgg_get_plugin_setting('index_managers', 'widget_manager', ''));
if (in_array($user->guid, $index_managers)) {
$return_value = true;
}

}
}

Expand Down Expand Up @@ -228,6 +234,28 @@ function widget_manager_plugins_settings_save_hook_handler($hook_name, $entity_t
elgg_set_plugin_setting('extra_contexts', $extra_contexts, 'widget_manager');
elgg_set_plugin_setting('extra_contexts_config', $extra_contexts_config, 'widget_manager');
}

/**
* Flattens the settings value for index managers
*
* @param string $hook_name name of the hook
* @param string $entity_type type of the hook
* @param string $return_value current return value
* @param array $params hook parameters
*
* @return void
*/
function widget_manager_index_manager_setting_plugin_hook_handler($hook_name, $entity_type, $return_value, $params) {
if (elgg_extract('plugin_id', $params) !== 'widget_manager') {
return;
}

if (elgg_extract('name', $params) !== 'index_managers') {
return;
}

return implode(',', $return_value);
}

/**
* Registers the extra context permissions check hook
Expand Down
2 changes: 2 additions & 0 deletions start.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ function widget_manager_init() {

elgg_register_plugin_hook_handler('permissions_check', 'object', 'widget_manager_permissions_check_object_hook_handler');

elgg_register_plugin_hook_handler('setting', 'plugin', 'widget_manager_index_manager_setting_plugin_hook_handler');

elgg_register_plugin_hook_handler('view_vars', 'admin/appearance/default_widgets', '\ColdTrick\WidgetManager\DefaultWidgets::defaultWidgetsViewVars');
elgg_register_plugin_hook_handler('view_vars', 'page/layouts/widgets', '\ColdTrick\WidgetManager\Layouts::checkFixedWidgets');

Expand Down
15 changes: 14 additions & 1 deletion views/default/plugins/widget_manager/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
'two_column_left' => elgg_echo('widget_manager:settings:index_top_row:two_column_left'),
];


$index_managers = $plugin->index_managers;
if ($index_managers) {
$index_managers = explode(',', $index_managers);
}

$settings_index = elgg_view_field([
'#type' => 'select',
'#label' => elgg_echo('widget_manager:settings:custom_index'),
Expand All @@ -63,7 +69,14 @@
'name' => 'params[index_top_row]',
'value' => $plugin->index_top_row,
'options_values' => $index_top_row_options,
]) . '</td>';
]);

$settings_index .= elgg_view_field([
'#type' => 'userpicker',
'#label' => elgg_echo('widget_manager:settings:index_managers'),
'name' => 'params[index_managers]',
'value' => $index_managers,
]);

echo elgg_view_module('inline', elgg_echo('widget_manager:settings:index'), $settings_index);

Expand Down

0 comments on commit ada86bf

Please sign in to comment.