Skip to content

Commit

Permalink
added: widget collapse capability is now hookable
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalsem committed Nov 3, 2017
1 parent 920fbea commit e770434
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
8 changes: 4 additions & 4 deletions classes/ColdTrick/WidgetManager/Menus.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Menus {
*
* @return boolean
*/
public static function registerAdminPageMenu($hook_name, $entity_type, $return_value, $params) {
public static function registerAdminPageMenu($hook_name, $entity_type, $return_value, $params) {
if (!elgg_is_admin_logged_in() || !elgg_in_context('admin')) {
return;
}
Expand Down Expand Up @@ -73,7 +73,7 @@ public static function addFixDefaultWidgetMenuItem($hook_name, $entity_type, $re
return;
}

$widget = elgg_extract('entity', $params);
$widget = elgg_extract('entity', $params);
if (!in_array($widget->context, ['profile', 'dashboard'])) {
return;
}
Expand Down Expand Up @@ -135,9 +135,9 @@ public static function prepareWidgetEditDeleteMenuItems($hook_name, $entity_type
}

if ($item->getName() == 'collapse') {
if ($widget->widget_manager_collapse_disable === 'yes' && $widget->widget_manager_collapse_state !== 'closed') {
if (!$widget->canCollapse() && $widget->widget_manager_collapse_state !== 'closed') {
unset($return_value[$section_key][$item_key]);
} elseif ($widget->widget_manager_collapse_disable !== 'yes') {
} elseif ($widget->canCollapse()) {
$widget_is_collapsed = false;
$widget_is_open = true;

Expand Down
19 changes: 18 additions & 1 deletion classes/WidgetManagerWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,31 @@ public function getClasses() {
return $result;
}

/**
* Checks if a widget can be collapsed
*
* @return boolean
*/
public function canCollapse() {
if (!elgg_is_logged_in()) {
return false;
}

$result = $this->widget_manager_collapse_disable !== 'yes';

$result = elgg_trigger_plugin_hook('collapsable', "widgets:{$this->handler}", ['entity' => $this], $result);

return $result;
}

/**
* Return a boolean if the widget should show collapsed
*
* @return bool
*/
public function showCollapsed() {

if ($this->widget_manager_collapse_disable == 'yes') {
if (!$this->canCollapse()) {
return false;
}

Expand Down

0 comments on commit e770434

Please sign in to comment.