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 13, 2024
1 parent d407d07 commit 70e6a5e
Show file tree
Hide file tree
Showing 45 changed files with 327 additions and 457 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 @@
Static
======

![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/static/actions/workflows/lint.yml/badge.svg?event=push)
[![Latest Stable Version](https://poser.pugx.org/coldtrick/static/v/stable.svg)](https://packagist.org/packages/coldtrick/static)
[![License](https://poser.pugx.org/coldtrick/static/license.svg)](https://packagist.org/packages/coldtrick/static)
Expand Down
4 changes: 2 additions & 2 deletions classes/ColdTrick/StaticPages/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Cache {
*
* @return void
*/
public static function resetMenuCache(\Elgg\Event $event) {
public static function resetMenuCache(\Elgg\Event $event): void {
$entity = $event->getObject();
if (!$entity instanceof \StaticPage) {
return;
Expand All @@ -30,7 +30,7 @@ public static function resetMenuCache(\Elgg\Event $event) {
*
* @return void
*/
public static function resetMenuCacheFromRelationship(\Elgg\Event $event) {
public static function resetMenuCacheFromRelationship(\Elgg\Event $event): void {
$relationship = $event->getObject();
if (!$relationship instanceof \ElggRelationship) {
return;
Expand Down
68 changes: 28 additions & 40 deletions classes/ColdTrick/StaticPages/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Cron {
*
* @return void
*/
public static function outOfDateNotification(\Elgg\Event $event) {
public static function outOfDateNotification(\Elgg\Event $event): void {

if (!static_out_of_date_enabled()) {
return;
Expand Down Expand Up @@ -55,7 +55,7 @@ public static function outOfDateNotification(\Elgg\Event $event) {

// make sure we need to notify this user
$recipient = self::checkRecipient($entity, $last_editor);
if (!($recipient instanceof \ElggUser)) {
if (!$recipient instanceof \ElggUser) {
continue;
}

Expand Down Expand Up @@ -124,27 +124,23 @@ public static function outOfDateNotification(\Elgg\Event $event) {
}

/**
* Let others infuence the recipient of the out-of-date notification
* Let others influence the recipient of the out-of-date notification
*
* @param \StaticPage $entity for which page
* @param \ElggUser $recipient default recipient
*
* @return false|\ElggUser
* @return null|\ElggUser
*/
protected static function checkRecipient(\StaticPage $entity, \ElggUser $recipient) {

if (!($entity instanceof \StaticPage) || !($recipient instanceof \ElggUser)) {
return false;
}

protected static function checkRecipient(\StaticPage $entity, \ElggUser $recipient): ?\ElggUser {

$params = [
'entity' => $entity,
'recipient' => $recipient,
];

$notify_user = elgg_trigger_event_results('out_of_date:user', 'static', $params, $recipient);
if (!$notify_user instanceof \ElggUser) {
return false;
return null;
}

return $notify_user;
Expand All @@ -157,12 +153,7 @@ protected static function checkRecipient(\StaticPage $entity, \ElggUser $recipie
*
* @return void
*/
protected static function sendNotifications($notification_information) {

if (empty($notification_information) || !is_array($notification_information)) {
return;
}

protected static function sendNotifications(array $notification_information): void {
$site = elgg_get_site_entity();
foreach ($notification_information as $user_guid => $info) {
// get recipient
Expand All @@ -186,28 +177,26 @@ protected static function sendNotifications($notification_information) {
}

// add reminder intervals
$remiders = (array) elgg_extract('reminders', $info, []);
if (!empty($remiders)) {
foreach ($remiders as $reminder => $pages) {
if (empty($pages)) {
continue;
}

$list .= PHP_EOL;

// section header
if (elgg_language_key_exists("static:out_of_date:notification:section:reminder:{$reminder}")) {
// custom header
$list .= elgg_echo("static:out_of_date:notification:section:reminder:{$reminder}") . PHP_EOL;
} else {
// default header
$list .= elgg_echo('static:out_of_date:notification:section:reminder', [$reminder]) . PHP_EOL;
}

// list all pages
foreach ($pages as $page_info) {
$list .= '- ' . $page_info['title'] . ' (' . $page_info['url'] . ')' . PHP_EOL;
}
$reminders = (array) elgg_extract('reminders', $info, []);
foreach ($reminders as $reminder => $pages) {
if (empty($pages)) {
continue;
}

$list .= PHP_EOL;

// section header
if (elgg_language_key_exists("static:out_of_date:notification:section:reminder:{$reminder}")) {
// custom header
$list .= elgg_echo("static:out_of_date:notification:section:reminder:{$reminder}") . PHP_EOL;
} else {
// default header
$list .= elgg_echo('static:out_of_date:notification:section:reminder', [$reminder]) . PHP_EOL;
}

// list all pages
foreach ($pages as $page_info) {
$list .= '- ' . $page_info['title'] . ' (' . $page_info['url'] . ')' . PHP_EOL;
}
}

Expand All @@ -225,7 +214,6 @@ protected static function sendNotifications($notification_information) {
]),
]);

// send notification
notify_user($user->guid, $site->guid, $subject, $message, [], 'email');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
class GroupToolContainerLogicCheck extends ToolContainerLogicCheck {

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function getContentType(): string {
return 'object';
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function getContentSubtype(): string {
return \StaticPage::SUBTYPE;
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function getToolName(): string {
return 'static';
Expand Down
67 changes: 30 additions & 37 deletions classes/ColdTrick/StaticPages/Menus.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace ColdTrick\StaticPages;

use ColdTrick\MenuBuilder\Menu;
use Elgg\Menu\MenuItems;
use Elgg\Menu\PreparedMenu;

/**
* Menus
Expand All @@ -14,15 +16,15 @@ class Menus {
*
* @param \Elgg\Event $event 'prepare', 'menu:page'
*
* @return \ElggMenuItem[]
* @return null|PreparedMenu
*/
public static function pageMenuPrepare(\Elgg\Event $event) {
public static function pageMenuPrepare(\Elgg\Event $event): ?PreparedMenu {

$return_value = $event->getValue();

$static = elgg_extract('static', $return_value);
if (!$static instanceof \Elgg\Menu\MenuSection) {
return;
return null;
}

$ordered = self::orderMenu($static->getItems());
Expand All @@ -38,12 +40,7 @@ public static function pageMenuPrepare(\Elgg\Event $event) {
*
* @return array
*/
protected static function orderMenu($menu_items) {

if (!is_array($menu_items)) {
return $menu_items;
}

protected static function orderMenu(array $menu_items): array {
$ordered = [];
foreach ($menu_items as $menu_item) {
$children = $menu_item->getChildren();
Expand All @@ -65,33 +62,30 @@ protected static function orderMenu($menu_items) {
*
* @param \Elgg\Event $event 'register', 'menu:static_edit'
*
* @return \ElggMenuItem[]
* @return null|MenuItems
*/
public static function registerStaticEditMenuItems(\Elgg\Event $event) {
public static function registerStaticEditMenuItems(\Elgg\Event $event): ?MenuItems {
$root_entity = $event->getParam('root_entity');
if (!$root_entity instanceof \StaticPage) {
return;
return null;
}

$return_value = $root_entity->getMenuCache();
if (empty($return_value)) {
// no items in cache so generate menu + add them to the cache
$return_value = Cache::generateMenuItemsCache($root_entity);
}

return $return_value;
/** @var MenuItems $result */
$result = $event->getValue();
$result->fill($root_entity->getMenuCache() ?: Cache::generateMenuItemsCache($root_entity));
return $result;
}

/**
* Add menu items to the admin header menu
*
* @param \Elgg\Event $event 'register', 'menu:admin_header'
*
* @return \ElggMenuItem[]
* @return null|MenuItems
*/
public static function registerAdminHeaderMenuItems(\Elgg\Event $event) {
public static function registerAdminHeaderMenuItems(\Elgg\Event $event): ?MenuItems {
if (!elgg_is_admin_logged_in()) {
return;
return null;
}

$return_value = $event->getValue();
Expand All @@ -110,13 +104,13 @@ public static function registerAdminHeaderMenuItems(\Elgg\Event $event) {
*
* @param \Elgg\Event $event 'register', 'menu:owner_block'
*
* @return void|MenuItems
* @return null|MenuItems
*/
public static function ownerBlockMenuRegister(\Elgg\Event $event) {
public static function ownerBlockMenuRegister(\Elgg\Event $event): ?MenuItems {

$owner = $event->getEntityParam();
if (!$owner instanceof \ElggGroup || !static_group_enabled($owner)) {
return;
return null;
}

$return_value = $event->getValue();
Expand All @@ -136,13 +130,13 @@ public static function ownerBlockMenuRegister(\Elgg\Event $event) {
*
* @param \Elgg\Event $event 'register', 'menu:owner_block'
*
* @return void|MenuItems
* @return null|MenuItems
*/
public static function userOwnerBlockMenuRegister(\Elgg\Event $event) {
public static function userOwnerBlockMenuRegister(\Elgg\Event $event): ?MenuItems {

$owner = $event->getEntityParam();
if (!$owner instanceof \ElggUser || !$owner->canEdit()) {
return;
return null;
}

$return_value = $event->getValue();
Expand All @@ -163,12 +157,12 @@ public static function userOwnerBlockMenuRegister(\Elgg\Event $event) {
*
* @param \Elgg\Event $event 'register', 'menu:filter:static'
*
* @return void|MenuItems
* @return null|MenuItems
*/
public static function filterMenuRegister(\Elgg\Event $event) {
public static function filterMenuRegister(\Elgg\Event $event): ?MenuItems {

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

/* @var $return_value MenuItems */
Expand Down Expand Up @@ -196,7 +190,7 @@ public static function filterMenuRegister(\Elgg\Event $event) {
}

if (!static_out_of_date_enabled()) {
return;
return $return_value;
}

if ($page_owner instanceof \ElggGroup) {
Expand Down Expand Up @@ -254,25 +248,24 @@ public static function filterMenuRegister(\Elgg\Event $event) {
*
* @param \Elgg\Event $event 'register', 'menu:entity'
*
* @return void|MenuItems
* @return null|MenuItems
*/
public static function changeDeleteItem(\Elgg\Event $event) {
public static function changeDeleteItem(\Elgg\Event $event): ?MenuItems {

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

/* @var $result MenuItems */
$result = $event->getValue();

$delete = $result->get('delete');
if (!$delete instanceof \ElggMenuItem) {
return;
return null;
}

$parent = $entity->getParentPage();
$forward_url = null;
if (empty($parent) || $parent->guid === $entity->guid) {
$container = $entity->getContainerEntity();
if ($container instanceof \ElggGroup) {
Expand Down
8 changes: 4 additions & 4 deletions classes/ColdTrick/StaticPages/MigrateStatic.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ class MigrateStatic extends Migrate {
/**
* {@inheritdoc}
*/
public function canBackDate() {
public function canBackDate(): bool {
return true;
}

/**
* {@inheritdoc}
*/
public function canChangeOwner() {
public function canChangeOwner(): bool {
return false;
}

/**
* {@inheritdoc}
*/
public function canChangeContainer() {
public function canChangeContainer(): bool {
return true;
}

/**
* {@inheritdoc}
*/
public function changeContainer($new_container_guid) {
public function changeContainer($new_container_guid): void {
// do all the default stuff
parent::changeContainer($new_container_guid);

Expand Down
Loading

0 comments on commit 70e6a5e

Please sign in to comment.