Skip to content

Commit 96f9502

Browse files
committed
changed: updated for Elgg 6.0
1 parent 4db22a8 commit 96f9502

File tree

42 files changed

+542
-784
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+542
-784
lines changed

.github/workflows/phpunit.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name: PHPUnit Plugin Tests
33
on: [push, pull_request]
44

55
jobs:
6-
lint:
6+
phpunit:
77
name: Run PHPUnit test suites
88
uses: ColdTrick/.github/.github/workflows/phpunit.yml@master
9+
with:
10+
elgg_major_version: 6

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Widget Manager
22
==============
33

4-
![Elgg 5.1](https://img.shields.io/badge/Elgg-5.1-green.svg)
4+
![Elgg 6.0](https://img.shields.io/badge/Elgg-6.0-green.svg)
55
![Lint Checks](https://github.com/ColdTrick/widget_manager/actions/workflows/lint.yml/badge.svg?event=push)
66
[![Latest Stable Version](https://poser.pugx.org/coldtrick/widget_manager/v/stable.svg)](https://packagist.org/packages/coldtrick/widget_manager)
77
[![License](https://poser.pugx.org/coldtrick/widget_manager/license.svg)](https://packagist.org/packages/coldtrick/widget_manager)

actions/widget_manager/force_tool_widgets.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
'limit' => false,
1313
'batch' => true,
1414
]);
15+
1516
foreach ($groups as $group) {
1617
$group->save();
1718
$counter++;

actions/widget_manager/groups/update_widget_access.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@
2828
'limit' => false,
2929
]);
3030

31-
if ($widgets) {
32-
foreach ($widgets as $widget) {
33-
$widget->access_id = (int) $new_access;
34-
$widget->save();
35-
}
31+
foreach ($widgets as $widget) {
32+
$widget->access_id = (int) $new_access;
33+
$widget->save();
3634
}
3735

3836
return elgg_ok_response('', elgg_echo('widget_manager:action:groups:update_widget_access:success'), $group->getURL());

classes/ColdTrick/WidgetManager/Access.php

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ class Access {
1414
*
1515
* @param \Elgg\Event $event 'access:collections:write', 'all'
1616
*
17-
* @return array
17+
* @return null|array
1818
*/
19-
public static function setWriteAccess(\Elgg\Event $event) {
19+
public static function setWriteAccess(\Elgg\Event $event): ?array {
2020

2121
$input_params = $event->getParam('input_params', []);
2222
if (elgg_extract('entity_type', $input_params) !== 'object' || elgg_extract('entity_subtype', $input_params) !== 'widget') {
23-
return;
23+
return null;
2424
}
2525

2626
$container = get_entity(elgg_extract('container_guid', $input_params));
2727
if (!$container instanceof \ElggEntity) {
28-
return;
28+
return null;
2929
}
3030

3131
if ($container instanceof \ElggGroup) {
@@ -42,7 +42,7 @@ public static function setWriteAccess(\Elgg\Event $event) {
4242

4343
$widget = elgg_extract('entity', $input_params);
4444
if (!$widget instanceof \ElggWidget) {
45-
return;
45+
return null;
4646
}
4747

4848
if (elgg_can_edit_widget_layout($widget->context)) {
@@ -54,59 +54,54 @@ public static function setWriteAccess(\Elgg\Event $event) {
5454
];
5555
}
5656
}
57+
58+
return null;
5759
}
5860

5961
/**
6062
* Allow write access for index managers
6163
*
6264
* @param \Elgg\Event $event 'permissions_check', 'site'
6365
*
64-
* @return array
66+
* @return null|bool
6567
*/
66-
public static function writeAccessForIndexManagers(\Elgg\Event $event) {
68+
public static function writeAccessForIndexManagers(\Elgg\Event $event): ?bool {
6769
$result = $event->getValue();
68-
6970
if ($result) {
70-
return;
71+
return $result;
7172
}
7273

7374
$entity = $event->getEntityParam();
7475
if (!$entity instanceof \ElggSite) {
75-
return;
76+
return null;
7677
}
7778

7879
$user = $event->getUserParam();
7980
if (!$user instanceof \ElggUser) {
80-
return;
81+
return null;
8182
}
8283

8384
$index_managers = explode(',', elgg_get_plugin_setting('index_managers', 'widget_manager', ''));
84-
if (in_array($user->guid, $index_managers)) {
85-
return true;
86-
}
85+
return in_array($user->guid, $index_managers) ?: null;
8786
}
8887

8988
/**
9089
* Creates the ability to see content only for logged_out users
9190
*
9291
* @param \Elgg\Event $event 'access:collections:read', 'user'
9392
*
94-
* @return array
93+
* @return null|array
9594
*/
96-
public static function addLoggedOutReadAccess(\Elgg\Event $event) {
95+
public static function addLoggedOutReadAccess(\Elgg\Event $event): ?array {
9796

9897
if (elgg_is_logged_in() && !elgg_is_admin_logged_in()) {
99-
return;
98+
return null;
10099
}
101100

102-
$return_value = $event->getValue();
101+
$return_value = $event->getValue() ?: [];
103102

104-
if (empty($return_value)) {
105-
$return_value = [];
106-
} else {
107-
if (!is_array($return_value)) {
108-
$return_value = [$return_value];
109-
}
103+
if (!is_array($return_value)) {
104+
$return_value = [$return_value];
110105
}
111106

112107
$return_value[] = ACCESS_LOGGED_OUT;
@@ -119,25 +114,23 @@ public static function addLoggedOutReadAccess(\Elgg\Event $event) {
119114
*
120115
* @param \Elgg\Event $event 'permissions_check', 'object'
121116
*
122-
* @return boolean
117+
* @return null|bool
123118
*/
124-
public static function canEditWidgetOnManagedLayout(\Elgg\Event $event) {
119+
public static function canEditWidgetOnManagedLayout(\Elgg\Event $event): ?bool {
125120
$user = $event->getUserParam();
126121
$entity = $event->getEntityParam();
127122

128123
if ($event->getValue() || !$user instanceof \ElggUser || !$entity instanceof \ElggWidget) {
129-
return;
124+
return null;
130125
}
131126

132127
if (!$entity->getOwnerEntity() instanceof \ElggSite) {
133128
// special permission is only for widget owned by site
134-
return;
129+
return null;
135130
}
136131

137132
$context = $entity->context;
138-
if ($context) {
139-
return elgg_can_edit_widget_layout($context, $user->guid);
140-
}
133+
return $context ? elgg_can_edit_widget_layout($context, $user->guid) : null;
141134
}
142135

143136
/**
@@ -147,7 +140,7 @@ public static function canEditWidgetOnManagedLayout(\Elgg\Event $event) {
147140
*
148141
* @return void
149142
*/
150-
public static function moreRightsForWidgetManager(\Elgg\Event $event) {
143+
public static function moreRightsForWidgetManager(\Elgg\Event $event): void {
151144
if ($event->getType() === 'widgets/add') {
152145
elgg_register_event_handler('permissions_check', 'site', '\ColdTrick\WidgetManager\Access::writeAccessForIndexManagers');
153146
return;
@@ -171,7 +164,7 @@ public static function moreRightsForWidgetManager(\Elgg\Event $event) {
171164
elgg_register_event_handler('get_sql', 'access', function(\Elgg\Event $event) use ($widget_guid) {
172165
if ($event->getParam('ignore_access')) {
173166
// no need to give extra access
174-
return;
167+
return null;
175168
}
176169

177170
/**

classes/ColdTrick/WidgetManager/Groups.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ class Groups {
1414
*
1515
* @param \Elgg\Event $event 'get_list', 'default_widgets'
1616
*
17-
* @return string
17+
* @return null|array
1818
*/
19-
public static function addGroupsContextToDefaultWidgets(\Elgg\Event $event) {
19+
public static function addGroupsContextToDefaultWidgets(\Elgg\Event $event): ?array {
2020
if (!elgg_is_active_plugin('groups')) {
21-
return;
21+
return null;
2222
}
2323

2424
$group_enable = elgg_get_plugin_setting('group_enable', 'widget_manager');
2525
if (!in_array($group_enable, ['yes', 'forced'])) {
26-
return;
26+
return null;
2727
}
2828

2929
$return_value = $event->getValue();
@@ -53,7 +53,7 @@ public static function addGroupsContextToDefaultWidgets(\Elgg\Event $event) {
5353
*
5454
* @return void
5555
*/
56-
public static function updateGroupWidgets(\Elgg\Event $event) {
56+
public static function updateGroupWidgets(\Elgg\Event $event): void {
5757
$object = $event->getObject();
5858
if (!$object instanceof \ElggGroup || !elgg_is_active_plugin('groups')) {
5959
return;
@@ -211,23 +211,23 @@ public static function updateGroupWidgets(\Elgg\Event $event) {
211211
*
212212
* @param \Elgg\Event $event 'view_vars', 'groups/profile/widgets'
213213
*
214-
* @return array
214+
* @return null|array
215215
*/
216-
public static function getGroupWidgetsLayout(\Elgg\Event $event) {
216+
public static function getGroupWidgetsLayout(\Elgg\Event $event): ?array {
217217
$vars = $event->getValue();
218218
$group = elgg_extract('entity', $vars);
219219

220220
if (!$group instanceof \ElggGroup) {
221-
return;
221+
return null;
222222
}
223223

224224
$group_enable = elgg_get_plugin_setting('group_enable', 'widget_manager');
225225
if (!in_array($group_enable, ['forced', 'yes'])) {
226-
return;
226+
return null;
227227
}
228228

229229
if ($group_enable === 'yes' && !$group->isToolEnabled('widget_manager')) {
230-
return;
230+
return null;
231231
}
232232

233233
// need context = groups to fix the issue with the new group_profile context
@@ -252,12 +252,12 @@ public static function getGroupWidgetsLayout(\Elgg\Event $event) {
252252
*
253253
* @param \Elgg\Event $event 'tool_options', 'group'
254254
*
255-
* @return array
255+
* @return null|array
256256
*/
257-
public static function registerGroupWidgetsTool(\Elgg\Event $event) {
257+
public static function registerGroupWidgetsTool(\Elgg\Event $event): ?array {
258258
$plugin = elgg_get_plugin_from_id('widget_manager');
259259
if ($plugin->getSetting('group_enable') !== 'yes') {
260-
return;
260+
return null;
261261
}
262262

263263
$result = $event->getValue();
@@ -280,7 +280,7 @@ public static function registerGroupWidgetsTool(\Elgg\Event $event) {
280280
*
281281
* @return void
282282
*/
283-
public static function addGroupWidget(\Elgg\Event $event) {
283+
public static function addGroupWidget(\Elgg\Event $event): void {
284284
$object = $event->getObject();
285285
if (!$object instanceof \ElggWidget || elgg_in_context('widget_manager_group_tool_widgets') || !elgg_is_active_plugin('groups')) {
286286
return;
@@ -320,7 +320,7 @@ public static function addGroupWidget(\Elgg\Event $event) {
320320
*
321321
* @return void
322322
*/
323-
public static function addGroupWidgetShutdown(\Elgg\Event $event) {
323+
public static function addGroupWidgetShutdown(\Elgg\Event $event): void {
324324
global $widget_manager_group_guids;
325325

326326
if (empty($widget_manager_group_guids)) {
@@ -378,7 +378,7 @@ public static function addGroupWidgetShutdown(\Elgg\Event $event) {
378378
*
379379
* @return void
380380
*/
381-
public static function deleteGroupWidget(\Elgg\Event $event) {
381+
public static function deleteGroupWidget(\Elgg\Event $event): void {
382382
$object = $event->getObject();
383383
if (!$object instanceof \ElggWidget || elgg_in_context('widget_manager_group_tool_widgets') || !elgg_is_active_plugin('groups')) {
384384
return;

classes/ColdTrick/WidgetManager/Menus.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace ColdTrick\WidgetManager;
44

5+
use Elgg\Menu\MenuItems;
6+
57
/**
68
* Menu callbacks
79
*/
@@ -12,11 +14,11 @@ class Menus {
1214
*
1315
* @param \Elgg\Event $event 'register', 'menu:admin_header'
1416
*
15-
* @return boolean
17+
* @return null|MenuItems
1618
*/
17-
public static function registerAdminHeaderMenu(\Elgg\Event $event) {
19+
public static function registerAdminHeaderMenu(\Elgg\Event $event): ?MenuItems {
1820
if (!elgg_is_admin_logged_in()) {
19-
return;
21+
return null;
2022
}
2123

2224
$return_value = $event->getValue();
@@ -71,12 +73,12 @@ public static function registerAdminHeaderMenu(\Elgg\Event $event) {
7173
*
7274
* @param \Elgg\Event $event 'register', 'menu:entity'
7375
*
74-
* @return array
76+
* @return null|MenuItems
7577
*/
76-
public static function addWidgetPageEntityMenuItems(\Elgg\Event $event) {
78+
public static function addWidgetPageEntityMenuItems(\Elgg\Event $event): ?MenuItems {
7779
$entity = $event->getEntityParam();
7880
if (!$entity instanceof \WidgetPage || !$entity->canEdit()) {
79-
return;
81+
return null;
8082
}
8183

8284
$result = $event->getValue();
@@ -100,16 +102,16 @@ public static function addWidgetPageEntityMenuItems(\Elgg\Event $event) {
100102
*
101103
* @param \Elgg\Event $event 'register', 'title:widgets'
102104
*
103-
* @return array
105+
* @return null|MenuItems
104106
*/
105-
public static function addWidgetsContentToggle(\Elgg\Event $event) {
107+
public static function addWidgetsContentToggle(\Elgg\Event $event): ?MenuItems {
106108

107109
if (!elgg_get_plugin_setting('show_collapse_content', 'widget_manager')) {
108-
return;
110+
return null;
109111
}
110112

111113
if (!$event->getParam('show_collapse_content', false)) {
112-
return;
114+
return null;
113115
}
114116

115117
$result = $event->getValue();

0 commit comments

Comments
 (0)