Jeroen Dalsem's Widget Manager enables group owners to replace the group tools module block with selected widgets. This shows how to create a "Group Hello" widget placeable on group profile pages.
First, create the widget content view:
<?php // myPlugin/views/default/widgets/myPlugin_group_hello/content.php
$widget = $vars["entity"];
/* @var ElggWidget $widget */
$group = $widget->getOwnerEntity();
/* @var ElggGroup $group */
$count = (int) $widget->display_count;
if (! $count) {
$count = 5;
}
echo str_repeat("Hello!<br />", $count);
...and the edit view:
<?php // myPlugin/views/default/widgets/myPlugin_group_hello/edit.php
$widget = $vars['entity'];
/* @var ElggWidget $widget */
$count = (int) $widget->display_count;
if (! $count) {
$count = 5;
}
echo "<div>";
echo elgg_echo("widget:numbertodisplay");
echo elgg_view("input/dropdown", array("name" => "params[display_count]", "options" => range(1, 10), "value" => $count));
echo "</div>";
Now, we just need to register the widget. Do this at the end of the [init, system] event, and make sure the Widget Manager plugin is active:
<?php // in myPlugin/start.php
elgg_register_event_handler("init", "system", "myPlugin_setup_widgets", 999);
function myPlugin_setup_widgets() {
if (! elgg_is_active_plugin('widget_manager')) {
return;
}
elgg_register_widget_type(
"my_plugin_group_hello",
elgg_echo("myPlugin:widget:myPlugin_group_hello:title"),
elgg_echo("myPlugin:widget:myPlugin_group_hello:description"),
"groups");
}
Now run the Elgg upgrade and you should be able to add the widget to a group. All that's left is adding the appropriate language strings.
Let's say you want to disable some of the included widgets. You can simply use the elgg_unregister_widget_type function in your setup function:
function myPlugin_setup_widgets() {
if (! elgg_is_active_plugin('widget_manager')) {
return;
}
elgg_register_widget_type(
"myPlugin_group_hello",
elgg_echo("myPlugin:widget:myPlugin_group_hello:title"),
elgg_echo("myPlugin:widget:myPlugin_group_hello:description"),
"groups");
// remove some widgets
foreach (array('content_by_tag', 'image_slider') as $id) {
elgg_unregister_widget_type($id);
}
}
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by Raül Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
Excellent timing, I'm going to be needing this next week. Bookmarked... Thank you!
Short addition:
To add the widget to index, dashboard etc replace the part:
with:
Which port does the RSS Feed widget in the Widget Manager use?
The RSS Feed widget worked fine until yesterday. Today I get an error - no RSS feeds and message that says - The API is no longer available.
our port 80 is open but 7780 is disabled.
Aha! I found this:
https://github.com/hubot-scripts/hubot-google-images/issues/29
Would this be related?
It looks like the plugin is using a deprecated API.
It also turns out the Context of the widget call excluded Groups. Had to be added in in order to post RSS Feeds in Groups....Geeezzzz!!