Skip to content

Commit

Permalink
changed: updated for Elgg 6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalsem committed Jun 10, 2024
1 parent 4db22a8 commit 96f9502
Show file tree
Hide file tree
Showing 42 changed files with 542 additions and 784 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: PHPUnit Plugin Tests
on: [push, pull_request]

jobs:
lint:
phpunit:
name: Run PHPUnit test suites
uses: ColdTrick/.github/.github/workflows/phpunit.yml@master
with:
elgg_major_version: 6
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Widget Manager
==============

![Elgg 5.1](https://img.shields.io/badge/Elgg-5.1-green.svg)
![Elgg 6.0](https://img.shields.io/badge/Elgg-6.0-green.svg)
![Lint Checks](https://github.com/ColdTrick/widget_manager/actions/workflows/lint.yml/badge.svg?event=push)
[![Latest Stable Version](https://poser.pugx.org/coldtrick/widget_manager/v/stable.svg)](https://packagist.org/packages/coldtrick/widget_manager)
[![License](https://poser.pugx.org/coldtrick/widget_manager/license.svg)](https://packagist.org/packages/coldtrick/widget_manager)
Expand Down
1 change: 1 addition & 0 deletions actions/widget_manager/force_tool_widgets.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
'limit' => false,
'batch' => true,
]);

foreach ($groups as $group) {
$group->save();
$counter++;
Expand Down
8 changes: 3 additions & 5 deletions actions/widget_manager/groups/update_widget_access.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@
'limit' => false,
]);

if ($widgets) {
foreach ($widgets as $widget) {
$widget->access_id = (int) $new_access;
$widget->save();
}
foreach ($widgets as $widget) {
$widget->access_id = (int) $new_access;
$widget->save();
}

return elgg_ok_response('', elgg_echo('widget_manager:action:groups:update_widget_access:success'), $group->getURL());
59 changes: 26 additions & 33 deletions classes/ColdTrick/WidgetManager/Access.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ class Access {
*
* @param \Elgg\Event $event 'access:collections:write', 'all'
*
* @return array
* @return null|array
*/
public static function setWriteAccess(\Elgg\Event $event) {
public static function setWriteAccess(\Elgg\Event $event): ?array {

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

$container = get_entity(elgg_extract('container_guid', $input_params));
if (!$container instanceof \ElggEntity) {
return;
return null;
}

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

$widget = elgg_extract('entity', $input_params);
if (!$widget instanceof \ElggWidget) {
return;
return null;
}

if (elgg_can_edit_widget_layout($widget->context)) {
Expand All @@ -54,59 +54,54 @@ public static function setWriteAccess(\Elgg\Event $event) {
];
}
}

return null;
}

/**
* Allow write access for index managers
*
* @param \Elgg\Event $event 'permissions_check', 'site'
*
* @return array
* @return null|bool
*/
public static function writeAccessForIndexManagers(\Elgg\Event $event) {
public static function writeAccessForIndexManagers(\Elgg\Event $event): ?bool {
$result = $event->getValue();

if ($result) {
return;
return $result;
}

$entity = $event->getEntityParam();
if (!$entity instanceof \ElggSite) {
return;
return null;
}

$user = $event->getUserParam();
if (!$user instanceof \ElggUser) {
return;
return null;
}

$index_managers = explode(',', elgg_get_plugin_setting('index_managers', 'widget_manager', ''));
if (in_array($user->guid, $index_managers)) {
return true;
}
return in_array($user->guid, $index_managers) ?: null;
}

/**
* Creates the ability to see content only for logged_out users
*
* @param \Elgg\Event $event 'access:collections:read', 'user'
*
* @return array
* @return null|array
*/
public static function addLoggedOutReadAccess(\Elgg\Event $event) {
public static function addLoggedOutReadAccess(\Elgg\Event $event): ?array {

if (elgg_is_logged_in() && !elgg_is_admin_logged_in()) {
return;
return null;
}

$return_value = $event->getValue();
$return_value = $event->getValue() ?: [];

if (empty($return_value)) {
$return_value = [];
} else {
if (!is_array($return_value)) {
$return_value = [$return_value];
}
if (!is_array($return_value)) {
$return_value = [$return_value];
}

$return_value[] = ACCESS_LOGGED_OUT;
Expand All @@ -119,25 +114,23 @@ public static function addLoggedOutReadAccess(\Elgg\Event $event) {
*
* @param \Elgg\Event $event 'permissions_check', 'object'
*
* @return boolean
* @return null|bool
*/
public static function canEditWidgetOnManagedLayout(\Elgg\Event $event) {
public static function canEditWidgetOnManagedLayout(\Elgg\Event $event): ?bool {
$user = $event->getUserParam();
$entity = $event->getEntityParam();

if ($event->getValue() || !$user instanceof \ElggUser || !$entity instanceof \ElggWidget) {
return;
return null;
}

if (!$entity->getOwnerEntity() instanceof \ElggSite) {
// special permission is only for widget owned by site
return;
return null;
}

$context = $entity->context;
if ($context) {
return elgg_can_edit_widget_layout($context, $user->guid);
}
return $context ? elgg_can_edit_widget_layout($context, $user->guid) : null;
}

/**
Expand All @@ -147,7 +140,7 @@ public static function canEditWidgetOnManagedLayout(\Elgg\Event $event) {
*
* @return void
*/
public static function moreRightsForWidgetManager(\Elgg\Event $event) {
public static function moreRightsForWidgetManager(\Elgg\Event $event): void {
if ($event->getType() === 'widgets/add') {
elgg_register_event_handler('permissions_check', 'site', '\ColdTrick\WidgetManager\Access::writeAccessForIndexManagers');
return;
Expand All @@ -171,7 +164,7 @@ public static function moreRightsForWidgetManager(\Elgg\Event $event) {
elgg_register_event_handler('get_sql', 'access', function(\Elgg\Event $event) use ($widget_guid) {
if ($event->getParam('ignore_access')) {
// no need to give extra access
return;
return null;
}

/**
Expand Down
32 changes: 16 additions & 16 deletions classes/ColdTrick/WidgetManager/Groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ class Groups {
*
* @param \Elgg\Event $event 'get_list', 'default_widgets'
*
* @return string
* @return null|array
*/
public static function addGroupsContextToDefaultWidgets(\Elgg\Event $event) {
public static function addGroupsContextToDefaultWidgets(\Elgg\Event $event): ?array {
if (!elgg_is_active_plugin('groups')) {
return;
return null;
}

$group_enable = elgg_get_plugin_setting('group_enable', 'widget_manager');
if (!in_array($group_enable, ['yes', 'forced'])) {
return;
return null;
}

$return_value = $event->getValue();
Expand Down Expand Up @@ -53,7 +53,7 @@ public static function addGroupsContextToDefaultWidgets(\Elgg\Event $event) {
*
* @return void
*/
public static function updateGroupWidgets(\Elgg\Event $event) {
public static function updateGroupWidgets(\Elgg\Event $event): void {
$object = $event->getObject();
if (!$object instanceof \ElggGroup || !elgg_is_active_plugin('groups')) {
return;
Expand Down Expand Up @@ -211,23 +211,23 @@ public static function updateGroupWidgets(\Elgg\Event $event) {
*
* @param \Elgg\Event $event 'view_vars', 'groups/profile/widgets'
*
* @return array
* @return null|array
*/
public static function getGroupWidgetsLayout(\Elgg\Event $event) {
public static function getGroupWidgetsLayout(\Elgg\Event $event): ?array {
$vars = $event->getValue();
$group = elgg_extract('entity', $vars);

if (!$group instanceof \ElggGroup) {
return;
return null;
}

$group_enable = elgg_get_plugin_setting('group_enable', 'widget_manager');
if (!in_array($group_enable, ['forced', 'yes'])) {
return;
return null;
}

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

// need context = groups to fix the issue with the new group_profile context
Expand All @@ -252,12 +252,12 @@ public static function getGroupWidgetsLayout(\Elgg\Event $event) {
*
* @param \Elgg\Event $event 'tool_options', 'group'
*
* @return array
* @return null|array
*/
public static function registerGroupWidgetsTool(\Elgg\Event $event) {
public static function registerGroupWidgetsTool(\Elgg\Event $event): ?array {
$plugin = elgg_get_plugin_from_id('widget_manager');
if ($plugin->getSetting('group_enable') !== 'yes') {
return;
return null;
}

$result = $event->getValue();
Expand All @@ -280,7 +280,7 @@ public static function registerGroupWidgetsTool(\Elgg\Event $event) {
*
* @return void
*/
public static function addGroupWidget(\Elgg\Event $event) {
public static function addGroupWidget(\Elgg\Event $event): void {
$object = $event->getObject();
if (!$object instanceof \ElggWidget || elgg_in_context('widget_manager_group_tool_widgets') || !elgg_is_active_plugin('groups')) {
return;
Expand Down Expand Up @@ -320,7 +320,7 @@ public static function addGroupWidget(\Elgg\Event $event) {
*
* @return void
*/
public static function addGroupWidgetShutdown(\Elgg\Event $event) {
public static function addGroupWidgetShutdown(\Elgg\Event $event): void {
global $widget_manager_group_guids;

if (empty($widget_manager_group_guids)) {
Expand Down Expand Up @@ -378,7 +378,7 @@ public static function addGroupWidgetShutdown(\Elgg\Event $event) {
*
* @return void
*/
public static function deleteGroupWidget(\Elgg\Event $event) {
public static function deleteGroupWidget(\Elgg\Event $event): void {
$object = $event->getObject();
if (!$object instanceof \ElggWidget || elgg_in_context('widget_manager_group_tool_widgets') || !elgg_is_active_plugin('groups')) {
return;
Expand Down
22 changes: 12 additions & 10 deletions classes/ColdTrick/WidgetManager/Menus.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace ColdTrick\WidgetManager;

use Elgg\Menu\MenuItems;

/**
* Menu callbacks
*/
Expand All @@ -12,11 +14,11 @@ class Menus {
*
* @param \Elgg\Event $event 'register', 'menu:admin_header'
*
* @return boolean
* @return null|MenuItems
*/
public static function registerAdminHeaderMenu(\Elgg\Event $event) {
public static function registerAdminHeaderMenu(\Elgg\Event $event): ?MenuItems {
if (!elgg_is_admin_logged_in()) {
return;
return null;
}

$return_value = $event->getValue();
Expand Down Expand Up @@ -71,12 +73,12 @@ public static function registerAdminHeaderMenu(\Elgg\Event $event) {
*
* @param \Elgg\Event $event 'register', 'menu:entity'
*
* @return array
* @return null|MenuItems
*/
public static function addWidgetPageEntityMenuItems(\Elgg\Event $event) {
public static function addWidgetPageEntityMenuItems(\Elgg\Event $event): ?MenuItems {
$entity = $event->getEntityParam();
if (!$entity instanceof \WidgetPage || !$entity->canEdit()) {
return;
return null;
}

$result = $event->getValue();
Expand All @@ -100,16 +102,16 @@ public static function addWidgetPageEntityMenuItems(\Elgg\Event $event) {
*
* @param \Elgg\Event $event 'register', 'title:widgets'
*
* @return array
* @return null|MenuItems
*/
public static function addWidgetsContentToggle(\Elgg\Event $event) {
public static function addWidgetsContentToggle(\Elgg\Event $event): ?MenuItems {

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

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

$result = $event->getValue();
Expand Down
Loading

0 comments on commit 96f9502

Please sign in to comment.