Skip to content

Commit 172baec

Browse files
committed
chore: organized menu callbacks in seperated files
fixes #130
1 parent 96f9502 commit 172baec

File tree

4 files changed

+98
-76
lines changed

4 files changed

+98
-76
lines changed
Lines changed: 3 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22

3-
namespace ColdTrick\WidgetManager;
3+
namespace ColdTrick\WidgetManager\Menus;
44

55
use Elgg\Menu\MenuItems;
66

77
/**
8-
* Menu callbacks
8+
* Admin Header menu callbacks
99
*/
10-
class Menus {
10+
class AdminHeader {
1111

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

6868
return $return_value;
6969
}
70-
71-
/**
72-
* Adds an optional fix link to the menu
73-
*
74-
* @param \Elgg\Event $event 'register', 'menu:entity'
75-
*
76-
* @return null|MenuItems
77-
*/
78-
public static function addWidgetPageEntityMenuItems(\Elgg\Event $event): ?MenuItems {
79-
$entity = $event->getEntityParam();
80-
if (!$entity instanceof \WidgetPage || !$entity->canEdit()) {
81-
return null;
82-
}
83-
84-
$result = $event->getValue();
85-
86-
$result[] = \ElggMenuItem::factory([
87-
'name' => 'edit',
88-
'text' => elgg_echo('edit'),
89-
'icon' => 'edit',
90-
'href' => "ajax/form/widget_manager/widget_page?guid={$entity->guid}",
91-
'link_class' => 'elgg-lightbox',
92-
'data-colorbox-opts' => json_encode([
93-
'trapFocus' => false,
94-
]),
95-
]);
96-
97-
return $result;
98-
}
99-
100-
/**
101-
* Adds a toggle to show/hide widget contents
102-
*
103-
* @param \Elgg\Event $event 'register', 'title:widgets'
104-
*
105-
* @return null|MenuItems
106-
*/
107-
public static function addWidgetsContentToggle(\Elgg\Event $event): ?MenuItems {
108-
109-
if (!elgg_get_plugin_setting('show_collapse_content', 'widget_manager')) {
110-
return null;
111-
}
112-
113-
if (!$event->getParam('show_collapse_content', false)) {
114-
return null;
115-
}
116-
117-
$result = $event->getValue();
118-
119-
$result[] = \ElggMenuItem::factory([
120-
'name' => 'hide-widget-contents',
121-
'class' => 'elgg-more',
122-
'text' => elgg_echo('widget_manager:layout:content:hide'),
123-
'icon' => 'eye-slash',
124-
'href' => false,
125-
'priority' => 80,
126-
]);
127-
128-
$result[] = \ElggMenuItem::factory([
129-
'name' => 'show-widget-contents',
130-
'class' => 'elgg-more',
131-
'item_class' => 'hidden',
132-
'text' => elgg_echo('widget_manager:layout:content:show'),
133-
'icon' => 'eye',
134-
'href' => false,
135-
'priority' => 81,
136-
]);
137-
138-
return $result;
139-
}
14070
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace ColdTrick\WidgetManager\Menus;
4+
5+
use Elgg\Menu\MenuItems;
6+
7+
/**
8+
* Entity menu callbacks
9+
*/
10+
class Entity {
11+
12+
/**
13+
* Adds an optional fix link to the menu
14+
*
15+
* @param \Elgg\Event $event 'register', 'menu:entity'
16+
*
17+
* @return null|MenuItems
18+
*/
19+
public static function addWidgetPageEntityMenuItems(\Elgg\Event $event): ?MenuItems {
20+
$entity = $event->getEntityParam();
21+
if (!$entity instanceof \WidgetPage || !$entity->canEdit()) {
22+
return null;
23+
}
24+
25+
$result = $event->getValue();
26+
27+
$result[] = \ElggMenuItem::factory([
28+
'name' => 'edit',
29+
'text' => elgg_echo('edit'),
30+
'icon' => 'edit',
31+
'href' => "ajax/form/widget_manager/widget_page?guid={$entity->guid}",
32+
'link_class' => 'elgg-lightbox',
33+
'data-colorbox-opts' => json_encode([
34+
'trapFocus' => false,
35+
]),
36+
]);
37+
38+
return $result;
39+
}
40+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace ColdTrick\WidgetManager\Menus;
4+
5+
use Elgg\Menu\MenuItems;
6+
7+
/**
8+
* Title entity menu callbacks
9+
*/
10+
class Title {
11+
12+
/**
13+
* Adds a toggle to show/hide widget contents
14+
*
15+
* @param \Elgg\Event $event 'register', 'menu:title:widgets'
16+
*
17+
* @return null|MenuItems
18+
*/
19+
public static function addWidgetsContentToggle(\Elgg\Event $event): ?MenuItems {
20+
21+
if (!elgg_get_plugin_setting('show_collapse_content', 'widget_manager')) {
22+
return null;
23+
}
24+
25+
if (!$event->getParam('show_collapse_content', false)) {
26+
return null;
27+
}
28+
29+
$result = $event->getValue();
30+
31+
$result[] = \ElggMenuItem::factory([
32+
'name' => 'hide-widget-contents',
33+
'class' => 'elgg-more',
34+
'text' => elgg_echo('widget_manager:layout:content:hide'),
35+
'icon' => 'eye-slash',
36+
'href' => false,
37+
'priority' => 80,
38+
]);
39+
40+
$result[] = \ElggMenuItem::factory([
41+
'name' => 'show-widget-contents',
42+
'class' => 'elgg-more',
43+
'item_class' => 'hidden',
44+
'text' => elgg_echo('widget_manager:layout:content:show'),
45+
'icon' => 'eye',
46+
'href' => false,
47+
'priority' => 81,
48+
]);
49+
50+
return $result;
51+
}
52+
}

elgg-plugin.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,13 @@
167167
],
168168
'register' => [
169169
'menu:admin_header' => [
170-
'\ColdTrick\WidgetManager\Menus::registerAdminHeaderMenu' => [],
170+
'\ColdTrick\WidgetManager\Menus\AdminHeader::registerAdminHeaderMenu' => [],
171171
],
172172
'menu:entity' => [
173-
'\ColdTrick\WidgetManager\Menus::addWidgetPageEntityMenuItems' => [],
173+
'\ColdTrick\WidgetManager\Menus\Entity::addWidgetPageEntityMenuItems' => [],
174174
],
175175
'menu:title:widgets' => [
176-
'\ColdTrick\WidgetManager\Menus::addWidgetsContentToggle' => [],
176+
'\ColdTrick\WidgetManager\Menus\Title::addWidgetsContentToggle' => [],
177177
],
178178
],
179179
'seeds' => [

0 commit comments

Comments
 (0)