Skip to content

Commit

Permalink
chore: organized menu callbacks in seperated files
Browse files Browse the repository at this point in the history
fixes #130
  • Loading branch information
jdalsem committed Jun 18, 2024
1 parent 96f9502 commit 172baec
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 76 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace ColdTrick\WidgetManager;
namespace ColdTrick\WidgetManager\Menus;

use Elgg\Menu\MenuItems;

/**
* Menu callbacks
* Admin Header menu callbacks
*/
class Menus {
class AdminHeader {

/**
* Event to register menu items on the admin pages
Expand Down Expand Up @@ -67,74 +67,4 @@ public static function registerAdminHeaderMenu(\Elgg\Event $event): ?MenuItems {

return $return_value;
}

/**
* Adds an optional fix link to the menu
*
* @param \Elgg\Event $event 'register', 'menu:entity'
*
* @return null|MenuItems
*/
public static function addWidgetPageEntityMenuItems(\Elgg\Event $event): ?MenuItems {
$entity = $event->getEntityParam();
if (!$entity instanceof \WidgetPage || !$entity->canEdit()) {
return null;
}

$result = $event->getValue();

$result[] = \ElggMenuItem::factory([
'name' => 'edit',
'text' => elgg_echo('edit'),
'icon' => 'edit',
'href' => "ajax/form/widget_manager/widget_page?guid={$entity->guid}",
'link_class' => 'elgg-lightbox',
'data-colorbox-opts' => json_encode([
'trapFocus' => false,
]),
]);

return $result;
}

/**
* Adds a toggle to show/hide widget contents
*
* @param \Elgg\Event $event 'register', 'title:widgets'
*
* @return null|MenuItems
*/
public static function addWidgetsContentToggle(\Elgg\Event $event): ?MenuItems {

if (!elgg_get_plugin_setting('show_collapse_content', 'widget_manager')) {
return null;
}

if (!$event->getParam('show_collapse_content', false)) {
return null;
}

$result = $event->getValue();

$result[] = \ElggMenuItem::factory([
'name' => 'hide-widget-contents',
'class' => 'elgg-more',
'text' => elgg_echo('widget_manager:layout:content:hide'),
'icon' => 'eye-slash',
'href' => false,
'priority' => 80,
]);

$result[] = \ElggMenuItem::factory([
'name' => 'show-widget-contents',
'class' => 'elgg-more',
'item_class' => 'hidden',
'text' => elgg_echo('widget_manager:layout:content:show'),
'icon' => 'eye',
'href' => false,
'priority' => 81,
]);

return $result;
}
}
40 changes: 40 additions & 0 deletions classes/ColdTrick/WidgetManager/Menus/Entity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace ColdTrick\WidgetManager\Menus;

use Elgg\Menu\MenuItems;

/**
* Entity menu callbacks
*/
class Entity {

/**
* Adds an optional fix link to the menu
*
* @param \Elgg\Event $event 'register', 'menu:entity'
*
* @return null|MenuItems
*/
public static function addWidgetPageEntityMenuItems(\Elgg\Event $event): ?MenuItems {
$entity = $event->getEntityParam();
if (!$entity instanceof \WidgetPage || !$entity->canEdit()) {
return null;
}

$result = $event->getValue();

$result[] = \ElggMenuItem::factory([
'name' => 'edit',
'text' => elgg_echo('edit'),
'icon' => 'edit',
'href' => "ajax/form/widget_manager/widget_page?guid={$entity->guid}",
'link_class' => 'elgg-lightbox',
'data-colorbox-opts' => json_encode([
'trapFocus' => false,
]),
]);

return $result;
}
}
52 changes: 52 additions & 0 deletions classes/ColdTrick/WidgetManager/Menus/Title.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace ColdTrick\WidgetManager\Menus;

use Elgg\Menu\MenuItems;

/**
* Title entity menu callbacks
*/
class Title {

/**
* Adds a toggle to show/hide widget contents
*
* @param \Elgg\Event $event 'register', 'menu:title:widgets'
*
* @return null|MenuItems
*/
public static function addWidgetsContentToggle(\Elgg\Event $event): ?MenuItems {

if (!elgg_get_plugin_setting('show_collapse_content', 'widget_manager')) {
return null;
}

if (!$event->getParam('show_collapse_content', false)) {
return null;
}

$result = $event->getValue();

$result[] = \ElggMenuItem::factory([
'name' => 'hide-widget-contents',
'class' => 'elgg-more',
'text' => elgg_echo('widget_manager:layout:content:hide'),
'icon' => 'eye-slash',
'href' => false,
'priority' => 80,
]);

$result[] = \ElggMenuItem::factory([
'name' => 'show-widget-contents',
'class' => 'elgg-more',
'item_class' => 'hidden',
'text' => elgg_echo('widget_manager:layout:content:show'),
'icon' => 'eye',
'href' => false,
'priority' => 81,
]);

return $result;
}
}
6 changes: 3 additions & 3 deletions elgg-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,13 @@
],
'register' => [
'menu:admin_header' => [
'\ColdTrick\WidgetManager\Menus::registerAdminHeaderMenu' => [],
'\ColdTrick\WidgetManager\Menus\AdminHeader::registerAdminHeaderMenu' => [],
],
'menu:entity' => [
'\ColdTrick\WidgetManager\Menus::addWidgetPageEntityMenuItems' => [],
'\ColdTrick\WidgetManager\Menus\Entity::addWidgetPageEntityMenuItems' => [],
],
'menu:title:widgets' => [
'\ColdTrick\WidgetManager\Menus::addWidgetsContentToggle' => [],
'\ColdTrick\WidgetManager\Menus\Title::addWidgetsContentToggle' => [],
],
],
'seeds' => [
Expand Down

0 comments on commit 172baec

Please sign in to comment.