diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 67fe092..6147873 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -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 diff --git a/README.md b/README.md index 6588c2d..3f5395e 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/classes/ColdTrick/StaticPages/Cache.php b/classes/ColdTrick/StaticPages/Cache.php index 28a1913..7640083 100644 --- a/classes/ColdTrick/StaticPages/Cache.php +++ b/classes/ColdTrick/StaticPages/Cache.php @@ -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; @@ -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; diff --git a/classes/ColdTrick/StaticPages/Cron.php b/classes/ColdTrick/StaticPages/Cron.php index e6cff5b..a049a48 100644 --- a/classes/ColdTrick/StaticPages/Cron.php +++ b/classes/ColdTrick/StaticPages/Cron.php @@ -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; @@ -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; } @@ -124,19 +124,15 @@ 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, @@ -144,7 +140,7 @@ protected static function checkRecipient(\StaticPage $entity, \ElggUser $recipie $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; @@ -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 @@ -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; } } @@ -225,7 +214,6 @@ protected static function sendNotifications($notification_information) { ]), ]); - // send notification notify_user($user->guid, $site->guid, $subject, $message, [], 'email'); } } diff --git a/classes/ColdTrick/StaticPages/GroupToolContainerLogicCheck.php b/classes/ColdTrick/StaticPages/GroupToolContainerLogicCheck.php index 2c1bef9..373b443 100644 --- a/classes/ColdTrick/StaticPages/GroupToolContainerLogicCheck.php +++ b/classes/ColdTrick/StaticPages/GroupToolContainerLogicCheck.php @@ -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'; diff --git a/classes/ColdTrick/StaticPages/Menus.php b/classes/ColdTrick/StaticPages/Menus.php index 353e331..246f37b 100644 --- a/classes/ColdTrick/StaticPages/Menus.php +++ b/classes/ColdTrick/StaticPages/Menus.php @@ -2,7 +2,9 @@ namespace ColdTrick\StaticPages; +use ColdTrick\MenuBuilder\Menu; use Elgg\Menu\MenuItems; +use Elgg\Menu\PreparedMenu; /** * Menus @@ -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()); @@ -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(); @@ -65,21 +62,18 @@ 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; } /** @@ -87,11 +81,11 @@ public static function registerStaticEditMenuItems(\Elgg\Event $event) { * * @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(); @@ -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(); @@ -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(); @@ -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 */ @@ -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) { @@ -254,13 +248,13 @@ 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 */ @@ -268,11 +262,10 @@ public static function changeDeleteItem(\Elgg\Event $event) { $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) { diff --git a/classes/ColdTrick/StaticPages/MigrateStatic.php b/classes/ColdTrick/StaticPages/MigrateStatic.php index e27ef39..f188fa2 100644 --- a/classes/ColdTrick/StaticPages/MigrateStatic.php +++ b/classes/ColdTrick/StaticPages/MigrateStatic.php @@ -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); diff --git a/classes/ColdTrick/StaticPages/PageHandler.php b/classes/ColdTrick/StaticPages/PageHandler.php index be04edf..74a05db 100644 --- a/classes/ColdTrick/StaticPages/PageHandler.php +++ b/classes/ColdTrick/StaticPages/PageHandler.php @@ -4,6 +4,7 @@ use Elgg\Http\ErrorResponse; use Elgg\Exceptions\HttpException; +use Elgg\Http\Response; /** * PageHandler @@ -15,17 +16,17 @@ class PageHandler { * * @param \Elgg\Event $event 'response', 'all' * - * @return array + * @return null|Response */ - public static function respondAll(\Elgg\Event $event) { + public static function respondAll(\Elgg\Event $event): ?Response { if ($event->getValue()->getStatusCode() !== 404) { - return; + return null; } list($path_type, $identifier) = explode(':', $event->getType()); if ($path_type !== 'path') { - return; + return null; } $entities = elgg_call(ELGG_IGNORE_ACCESS, function() use ($identifier) { @@ -37,15 +38,14 @@ public static function respondAll(\Elgg\Event $event) { 'metadata_case_sensitive' => false, ]); }); + if (empty($entities)) { - return; + return null; } - $entity = $entities[0]; - try { $content = elgg_view_resource('static/view', [ - 'guid' => $entity->guid + 'guid' => $entities[0]->guid ]); return elgg_ok_response($content); diff --git a/classes/ColdTrick/StaticPages/Permissions.php b/classes/ColdTrick/StaticPages/Permissions.php index a6ada7a..f990e54 100644 --- a/classes/ColdTrick/StaticPages/Permissions.php +++ b/classes/ColdTrick/StaticPages/Permissions.php @@ -2,6 +2,8 @@ namespace ColdTrick\StaticPages; +use Elgg\Database\QueryBuilder; + /** * Permissions */ @@ -12,19 +14,19 @@ class Permissions { * * @param \Elgg\Event $event 'permissions_check', 'object' * - * @return bool + * @return null|bool */ - public static function objectPermissionsCheck(\Elgg\Event $event) { + public static function objectPermissionsCheck(\Elgg\Event $event): ?bool { if ($event->getValue()) { // already have access, no need to add - return; + return null; } $entity = $event->getEntityParam(); $user = $event->getUserParam(); if (!$entity instanceof \StaticPage || !$user instanceof \ElggUser) { - return; + return null; } // allowed if you are the last editor @@ -64,6 +66,8 @@ public static function objectPermissionsCheck(\Elgg\Event $event) { return true; } } + + return null; } /** @@ -71,16 +75,16 @@ public static function objectPermissionsCheck(\Elgg\Event $event) { * * @param \Elgg\Event $event 'container_permissions_check', 'object' * - * @return bool + * @return null|bool */ - public static function containerPermissionsCheck(\Elgg\Event $event) { + public static function containerPermissionsCheck(\Elgg\Event $event): ?bool { if ($event->getType() !== 'object') { - return; + return null; } if ($event->getParam('subtype') !== 'static') { - return; + return null; } $container = $event->getParam('container'); @@ -104,7 +108,7 @@ public static function containerPermissionsCheck(\Elgg\Event $event) { * * @return void */ - public static function allowActionAccessToPrivateEntity(\Elgg\Event $event) { + public static function allowActionAccessToPrivateEntity(\Elgg\Event $event): void { $entity_guid = (int) get_input('guid'); if (empty($entity_guid)) { return; @@ -126,7 +130,7 @@ public static function allowActionAccessToPrivateEntity(\Elgg\Event $event) { elgg_register_event_handler('get_sql', 'access', function(\Elgg\Event $event) use ($entity_guid) { if ($event->getParam('ignore_access')) { // access is ignored, no need for additional query parts - return; + return null; } $result = $event->getValue(); diff --git a/classes/ColdTrick/StaticPages/Plugins/CSVExporter.php b/classes/ColdTrick/StaticPages/Plugins/CSVExporter.php index 8c60db3..02e77c7 100644 --- a/classes/ColdTrick/StaticPages/Plugins/CSVExporter.php +++ b/classes/ColdTrick/StaticPages/Plugins/CSVExporter.php @@ -12,12 +12,12 @@ class CSVExporter { * * @param \Elgg\Event $event 'get_exportable_values', 'csv_exporter' * - * @return void|array + * @return null|array */ - public static function addLastEditor(\Elgg\Event $event) { + public static function addLastEditor(\Elgg\Event $event): ?array { if ($event->getParam('subtype') !== \StaticPage::SUBTYPE) { - return; + return null; } $values = [ @@ -40,23 +40,23 @@ public static function addLastEditor(\Elgg\Event $event) { * * @param \Elgg\Event $event 'export_value', 'csv_exporter' * - * @return void|string + * @return null|string */ - public static function exportLastEditor(\Elgg\Event $event) { + public static function exportLastEditor(\Elgg\Event $event): ?string { $return_value = $event->getValue(); if (!is_null($return_value)) { // someone already provided output - return; + return null; } $entity = $event->getEntityParam(); if (!$entity instanceof \StaticPage) { - return; + return null; } $last_editor = $entity->getLastEditor(); if (empty($last_editor)) { - return; + return null; } switch ($event->getParam('exportable_value')) { @@ -76,6 +76,8 @@ public static function exportLastEditor(\Elgg\Event $event) { return $last_editor->getURL(); break; } + + return null; } /** @@ -83,12 +85,12 @@ public static function exportLastEditor(\Elgg\Event $event) { * * @param \Elgg\Event $event 'get_exportable_values', 'csv_exporter' * - * @return void|array + * @return null|array */ - public static function addLastRevision(\Elgg\Event $event) { + public static function addLastRevision(\Elgg\Event $event): ?array { if ($event->getParam('subtype') !== \StaticPage::SUBTYPE) { - return; + return null; } $values = [ @@ -108,23 +110,23 @@ public static function addLastRevision(\Elgg\Event $event) { * * @param \Elgg\Event $event 'export_value', 'csv_exporter' * - * @return void|string + * @return null|string */ - public static function exportLastRevision(\Elgg\Event $event) { + public static function exportLastRevision(\Elgg\Event $event): ?string { if (!is_null($event->getValue())) { // someone already provided output - return; + return null; } $entity = $event->getEntityParam(); if (!$entity instanceof \StaticPage) { - return; + return null; } $last_revision = $entity->getLastRevision(); if (empty($last_revision)) { - return; + return null; } switch ($event->getParam('exportable_value')) { @@ -135,6 +137,8 @@ public static function exportLastRevision(\Elgg\Event $event) { return csv_exported_get_readable_timestamp($last_revision->time_created); break; } + + return null; } /** @@ -142,16 +146,16 @@ public static function exportLastRevision(\Elgg\Event $event) { * * @param \Elgg\Event $event 'get_exportable_values', 'csv_exporter' * - * @return void|array + * @return null|array */ - public static function addOutOfDate(\Elgg\Event $event) { + public static function addOutOfDate(\Elgg\Event $event): ?array { if ($event->getParam('subtype') !== \StaticPage::SUBTYPE) { - return; + return null; } if (!static_out_of_date_enabled()) { - return; + return null; } $values = [ @@ -170,18 +174,18 @@ public static function addOutOfDate(\Elgg\Event $event) { * * @param \Elgg\Event $event 'export_value', 'csv_exporter' * - * @return void|string + * @return null|string */ - public static function exportOutOfDate(\Elgg\Event $event) { + public static function exportOutOfDate(\Elgg\Event $event): ?string { if (!is_null($event->getValue())) { // someone already provided output - return; + return null; } $entity = $event->getEntityParam(); if (!$entity instanceof \StaticPage) { - return; + return null; } switch ($event->getParam('exportable_value')) { @@ -189,6 +193,8 @@ public static function exportOutOfDate(\Elgg\Event $event) { return $entity->isOutOfDate() ? 'yes' : 'no'; break; } + + return null; } /** @@ -196,12 +202,12 @@ public static function exportOutOfDate(\Elgg\Event $event) { * * @param \Elgg\Event $event 'get_exportable_values', 'csv_exporter' * - * @return void|array + * @return null|array */ - public static function addParentPages(\Elgg\Event $event) { + public static function addParentPages(\Elgg\Event $event): ?array { if ($event->getParam('subtype') !== \StaticPage::SUBTYPE) { - return; + return null; } $values = [ @@ -225,57 +231,38 @@ public static function addParentPages(\Elgg\Event $event) { * * @param \Elgg\Event $event 'export_value', 'csv_exporter' * - * @return void|string + * @return null|string */ - public static function exportParentPages(\Elgg\Event $event) { + public static function exportParentPages(\Elgg\Event $event): ?string { if (!is_null($event->getValue())) { // someone already provided output - return; + return null; } $entity = $event->getEntityParam(); if (!$entity instanceof \StaticPage) { - return; + return null; } switch ($event->getParam('exportable_value')) { case 'static_parent_title': - $parent = $entity->getParentPage(); - if (empty($parent)) { - return ''; - } - return $parent->getDisplayName(); + return $entity->getParentPage()?->getDisplayName(); case 'static_parent_guid': - $parent = $entity->getParentPage(); - if (empty($parent)) { - return ''; - } - return $parent->guid; + return $entity->getParentPage()?->guid; case 'static_parent_url': - $parent = $entity->getParentPage(); - if (empty($parent)) { - return ''; - } - return $parent->getURL(); + return $entity->getParentPage()?->getURL(); case 'static_main_title': $main = $entity->getRootPage(); - if ($main->guid === $entity->guid) { - return ''; - } - return $main->getDisplayName(); + return ($main->guid === $entity->guid) ? '' : $main->getDisplayName(); case 'static_main_guid': $main = $entity->getRootPage(); - if ($main->guid === $entity->guid) { - return ''; - } - return $main->guid; + return ($main->guid === $entity->guid) ? '' : $main->guid; case 'static_main_url': $main = $entity->getRootPage(); - if ($main->guid === $entity->guid) { - return ''; - } - return $main->getURL(); + return ($main->guid === $entity->guid) ? '' : $main->getURL(); } + + return null; } } diff --git a/classes/ColdTrick/StaticPages/Plugins/EntityTools.php b/classes/ColdTrick/StaticPages/Plugins/EntityTools.php index 5fe2a6b..890b8cc 100644 --- a/classes/ColdTrick/StaticPages/Plugins/EntityTools.php +++ b/classes/ColdTrick/StaticPages/Plugins/EntityTools.php @@ -8,17 +8,17 @@ class EntityTools { /** - * Limit list of updateable entities to top pages + * Limit list of updatable entities to top pages * * @param \Elgg\Event $event 'view_vars', 'forms/entity_tools/update_entities' * * @return void|array */ - public static function limitTopPages(\Elgg\Event $event) { + public static function limitTopPages(\Elgg\Event $event): ?array { $vars = $event->getValue(); $subtype = elgg_extract('subtype', $vars); if ($subtype !== \StaticPage::SUBTYPE) { - return; + return null; } $vars['entity_options'] = (array) elgg_extract('entity_options', $vars, []); @@ -37,7 +37,7 @@ public static function limitTopPages(\Elgg\Event $event) { * * @return array */ - public static function supportedSubtypes(\Elgg\Event $event) { + public static function supportedSubtypes(\Elgg\Event $event): array { $return_value = $event->getValue(); $return_value[\StaticPage::SUBTYPE] = \ColdTrick\StaticPages\MigrateStatic::class; return $return_value; diff --git a/classes/ColdTrick/StaticPages/Plugins/SearchAdvanced.php b/classes/ColdTrick/StaticPages/Plugins/SearchAdvanced.php index 8c84b69..e7ae50d 100644 --- a/classes/ColdTrick/StaticPages/Plugins/SearchAdvanced.php +++ b/classes/ColdTrick/StaticPages/Plugins/SearchAdvanced.php @@ -14,11 +14,11 @@ class SearchAdvanced { * * @return array */ - public static function searchAdvancedAutocomplete(\Elgg\Event $event) { + public static function searchAdvancedAutocomplete(\Elgg\Event $event): ?array { $query = $event->getParam('query'); if (empty($query)) { - return; + return null; } $params = $event->getParams(); @@ -28,7 +28,7 @@ public static function searchAdvancedAutocomplete(\Elgg\Event $event) { $entities = elgg_search($params); if (empty($entities)) { - return; + return null; } $static_count = count($entities); diff --git a/classes/ColdTrick/StaticPages/Seeder.php b/classes/ColdTrick/StaticPages/Seeder.php index eee748f..38eb290 100644 --- a/classes/ColdTrick/StaticPages/Seeder.php +++ b/classes/ColdTrick/StaticPages/Seeder.php @@ -12,7 +12,7 @@ class Seeder extends Seed { /** - * {@inheritDoc} + * {@inheritdoc} */ public function seed() { $this->advance($this->getCount()); @@ -74,7 +74,7 @@ public function seed() { } /** - * {@inheritDoc} + * {@inheritdoc} */ public function unseed() { /* @var $entities \ElggBatch */ @@ -102,14 +102,14 @@ public function unseed() { } /** - * {@inheritDoc} + * {@inheritdoc} */ public static function getType(): string { return \StaticPage::SUBTYPE; } /** - * {@inheritDoc} + * {@inheritdoc} */ protected function getCountOptions(): array { return [ diff --git a/classes/ColdTrick/StaticPages/Upgrades/MoveHeaderIcons.php b/classes/ColdTrick/StaticPages/Upgrades/MoveHeaderIcons.php deleted file mode 100644 index 4fec3d4..0000000 --- a/classes/ColdTrick/StaticPages/Upgrades/MoveHeaderIcons.php +++ /dev/null @@ -1,84 +0,0 @@ -countItems()); - } - - /** - * {@inheritdoc} - */ - public function countItems(): int { - return elgg_count_entities($this->getOptions()); - } - - /** - * {@inheritdoc} - */ - public function run(Result $result, $offset): Result { - $pages = elgg_get_entities($this->getOptions(['offset' => $offset])); - - /* @var $page \Event */ - foreach ($pages as $page) { - $old_icon = $page->getIcon('master', 'icon'); - if ($old_icon->exists()) { - $coords = [ - 'x1' => $page->x1, - 'y1' => $page->y1, - 'x2' => $page->x2, - 'y2' => $page->y2, - ]; - - $page->saveIconFromElggFile($old_icon, 'header', $coords); - } - - $page->deleteIcon('icon'); - - $result->addSuccesses(); - } - - return $result; - } - - /** - * Get options for elgg_get_entities - * - * @param array $options additional options - * - * @return array - */ - protected function getOptions(array $options = []) { - $defaults = [ - 'type' => 'object', - 'subtype' => 'static', - 'limit' => 50, - 'batch' => true, - 'metadata_name' => 'icontime', - ]; - - return array_merge($defaults, $options); - } -} diff --git a/classes/ColdTrick/StaticPages/Widgets.php b/classes/ColdTrick/StaticPages/Widgets.php index 2c003fd..dc0de48 100644 --- a/classes/ColdTrick/StaticPages/Widgets.php +++ b/classes/ColdTrick/StaticPages/Widgets.php @@ -12,17 +12,17 @@ class Widgets { * * @param \Elgg\Event $event 'entity:url', 'object' * - * @return string + * @return null|string */ - public static function widgetURL(\Elgg\Event $event) { + public static function widgetURL(\Elgg\Event $event): ?string { $return_value = $event->getValue(); if (!empty($return_value)) { - return; + return null; } $entity = $event->getEntityParam(); if (!$entity instanceof \ElggWidget) { - return; + return null; } switch ($entity->handler) { @@ -41,13 +41,13 @@ public static function widgetURL(\Elgg\Event $event) { * * @param \Elgg\Event $event 'group_tool_widgets', 'widget_manager' * - * @return array + * @return null|array */ - public static function groupToolWidgets(\Elgg\Event $event) { + public static function groupToolWidgets(\Elgg\Event $event): ?array { $entity = $event->getEntityParam(); if (!$entity instanceof \ElggGroup) { - return; + return null; } $return_value = $event->getValue(); diff --git a/classes/StaticPage.php b/classes/StaticPage.php index a4e144a..3c098d6 100644 --- a/classes/StaticPage.php +++ b/classes/StaticPage.php @@ -53,7 +53,7 @@ public function canComment(int $user_guid = 0): bool { /** * {@inheritdoc} */ - public function delete(bool $recursive = true): bool { + public function delete(bool $recursive = true, bool $persistent = null): bool { // do this here so we can ignore access later if (!$this->canDelete()) { @@ -61,9 +61,9 @@ public function delete(bool $recursive = true): bool { } // ignore access, so moderators cleanup everything correctly - return elgg_call(ELGG_IGNORE_ACCESS, function() use ($recursive) { + return elgg_call(ELGG_IGNORE_ACCESS, function() use ($recursive, $persistent) { - $result = parent::delete($recursive); + $result = parent::delete($recursive, $persistent); if ($result === false || $recursive !== true) { return $result; } @@ -84,7 +84,7 @@ public function delete(bool $recursive = true): bool { /* @var $entity \StaticPage */ foreach ($batch as $entity) { - $entity->delete($recursive); + $entity->delete($recursive, $persistent); } return $result; @@ -152,50 +152,42 @@ public function getRootPage(): \StaticPage { /** * Returns the parent page of an entity * - * @return \StaticPage|false + * @return null|\StaticPage */ - public function getParentPage() { + public function getParentPage(): ?\StaticPage { $parent_guid = $this->parent_guid; if (empty($parent_guid)) { - return false; + return null; } return elgg_call(ELGG_IGNORE_ACCESS, function() use ($parent_guid) { $parent_entity = get_entity($parent_guid); - if (!$parent_entity instanceof \StaticPage) { - return false; - } - - return $parent_entity; + return $parent_entity instanceof \StaticPage ? $parent_entity : null; }); } /** * Returns the latest editor entity for this page, or false if there is none * - * @return false|\ElggUser + * @return null|\ElggUser */ - public function getLastEditor() { + public function getLastEditor(): ?\ElggUser { $revision = $this->getLastRevision(); if (empty($revision)) { - return false; + return null; } $user = $revision->getOwnerEntity(); - if (empty($user)) { - return false; - } - - return $user; + return $user instanceof \ElggUser ? $user : null; } /** * Get the last revision of a static page * - * @return false|\ElggAnnotation + * @return null|\ElggAnnotation */ - public function getLastRevision() { + public function getLastRevision(): ?\ElggAnnotation { $revisions = elgg_call(ELGG_IGNORE_ACCESS, function() { return $this->getAnnotations([ @@ -205,7 +197,7 @@ public function getLastRevision() { ]); }); - return $revisions ? $revisions[0] : false; + return elgg_extract(0, $revisions); } /** diff --git a/composer.json b/composer.json index 5c295f1..fc06f4d 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,6 @@ "issues": "https://github.com/ColdTrick/static/issues" }, "conflict": { - "elgg/elgg": "<5.1" + "elgg/elgg": "<6.0" } } diff --git a/composer.lock b/composer.lock index cf6ce3b..63d7a4d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "19413511a149dc8bed4cee2ed490ddcc", + "content-hash": "2660a58fdb78faafd14971df6ef25cd2", "packages": [], "packages-dev": [], "aliases": [], diff --git a/elgg-plugin.php b/elgg-plugin.php index 33dcde4..aefe7c8 100644 --- a/elgg-plugin.php +++ b/elgg-plugin.php @@ -29,9 +29,6 @@ ], ], ], - 'upgrades' => [ - 'ColdTrick\StaticPages\Upgrades\MoveHeaderIcons', - ], 'actions' => [ 'static/edit' => [], 'static/reorder' => [], @@ -247,7 +244,7 @@ ], 'view_extensions' => [ 'elgg.css' => [ - 'css/static/site.css' => [], + 'static/site.css' => [], ], ], 'view_options' => [ diff --git a/languages/en.php b/languages/en.php index 3b9ccaa..e35ee3f 100644 --- a/languages/en.php +++ b/languages/en.php @@ -92,7 +92,4 @@ 'static:csv_exporter:main:title' => "Main page title", 'static:csv_exporter:main:guid' => "Main page GUID", 'static:csv_exporter:main:url' => "Main page URL", - - 'static:upgrade:2023031300:title' => "Move static icons to header images", - 'static:upgrade:2023031300:description' => "Moves old static page icons to header images", ]; diff --git a/languages/nl.php b/languages/nl.php index 2d21914..e89c67e 100644 --- a/languages/nl.php +++ b/languages/nl.php @@ -5,8 +5,6 @@ */ return array ( - 'static:upgrade:2023031300:title' => 'Verplaats iconen voor statische pagina\'s naar kopafbeeldingen', - 'static:upgrade:2023031300:description' => 'Verplaats de oude iconen voor statische pagina\'s naar de kopafbeeldingen', 'static:menu:owner_block:last_editor' => 'Statische pagina\'s', 'static:last_editor:title' => 'Statische pagina\'s: %s', 'collection:object:static' => 'Statische pagina\'s', diff --git a/lib/functions.php b/lib/functions.php index d09b64d..8890135 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -15,7 +15,7 @@ */ function static_setup_page_menu(\StaticPage $entity, string $menu_name = 'page'): void { - elgg_require_js('static/sidebar_menu'); + elgg_import_esm('static/sidebar_menu'); $page_owner = elgg_get_page_owner_entity(); $ignore_access = 0; @@ -141,6 +141,7 @@ function static_is_moderator_in_container(\ElggEntity $container_entity, \ElggUs 'metadata_names' => ['moderators'], 'limit' => false, ]); + if (empty($md)) { return false; } @@ -218,8 +219,8 @@ function static_get_parent_moderators(\ElggObject $entity, bool $guid_only = fal /** * Get the parent select options for the edit form * - * @param int $parent_guid the current parent to check the children of (default: site) - * @param int $depth internal depth counter + * @param int|null $parent_guid the current parent to check the children of (default: site) + * @param int $depth internal depth counter * * @return array */ @@ -406,7 +407,7 @@ function static_check_children_tree(\StaticPage $entity, int $tree_guid = 0): vo /** * Check if group support is enabled * - * @param \ElggGroup $group (optional) check if the group has this enabled + * @param \ElggGroup|null $group (optional) check if the group has this enabled * * @return bool */ @@ -421,9 +422,5 @@ function static_group_enabled(\ElggGroup $group = null): bool { return false; } - if (!$group instanceof \ElggGroup) { - return $plugin_setting; - } - - return $group->isToolEnabled('static'); + return $group instanceof \ElggGroup ? $group->isToolEnabled('static') : $plugin_setting; } diff --git a/views/default/annotation/static_revision.php b/views/default/annotation/static_revision.php index 915e54b..454d207 100644 --- a/views/default/annotation/static_revision.php +++ b/views/default/annotation/static_revision.php @@ -8,8 +8,6 @@ return true; } -$output = elgg_view_entity_url($owner); +echo elgg_view_entity_url($owner); -$output .= elgg_format_element('span', ['class' => 'mls'], elgg_view_friendly_time($annotation->time_created)); - -echo elgg_format_element('div', [], $output); +echo elgg_format_element('span', ['class' => 'mls'], elgg_view_friendly_time($annotation->time_created)); diff --git a/views/default/forms/static/edit.php b/views/default/forms/static/edit.php index 875c83a..6b11407 100644 --- a/views/default/forms/static/edit.php +++ b/views/default/forms/static/edit.php @@ -110,7 +110,10 @@ echo $form_body; -$footer = elgg_view('input/submit', ['text' => elgg_echo('save')]); +$footer = elgg_view_field([ + '#type' => 'submit', + 'text' => elgg_echo('save'), +]); elgg_set_form_footer($footer); diff --git a/views/default/input/entity_tools_container/static.php b/views/default/input/entity_tools_container/static.php index 9bf4d99..c62cb09 100644 --- a/views/default/input/entity_tools_container/static.php +++ b/views/default/input/entity_tools_container/static.php @@ -1,6 +1,6 @@ guid); diff --git a/views/default/object/static.php b/views/default/object/static.php index 73d6ad6..8c06a45 100644 --- a/views/default/object/static.php +++ b/views/default/object/static.php @@ -32,5 +32,6 @@ 'content' => elgg_get_excerpt((string) $entity->description), ]; $params = $params + $vars; + echo elgg_view('object/elements/summary', $params); } diff --git a/views/default/object/static/widget.php b/views/default/object/static/widget.php index 50d252a..4d8315c 100644 --- a/views/default/object/static/widget.php +++ b/views/default/object/static/widget.php @@ -1,7 +1,7 @@ guid); $page_owner = $site; } @@ -21,12 +21,12 @@ if ($guid) { $entity = get_entity($guid); elgg_call(ELGG_ENFORCE_ACCESS, function() use ($entity) { - if ($entity instanceof StaticPage && !$entity->canEdit()) { + if ($entity instanceof \StaticPage && !$entity->canEdit()) { throw new EntityPermissionsException(); } }); - if ($entity instanceof StaticPage) { + if ($entity instanceof \StaticPage) { // edit $body_vars['entity'] = $entity; @@ -37,7 +37,7 @@ $sidebar = elgg_view('static/sidebar/revisions', [ 'entity' => $entity, ]); - } elseif ($entity instanceof ElggGroup) { + } elseif ($entity instanceof \ElggGroup) { // new in group elgg_set_page_owner_guid($entity->guid); $page_owner = elgg_get_page_owner_entity(); @@ -45,13 +45,13 @@ } } - if ($page_owner instanceof ElggGroup) { + if ($page_owner instanceof \ElggGroup) { elgg_push_collection_breadcrumbs('object', StaticPage::SUBTYPE, $page_owner); } else { elgg_push_collection_breadcrumbs('object', StaticPage::SUBTYPE); } - if ($entity instanceof StaticPage) { + if ($entity instanceof \StaticPage) { elgg_push_breadcrumb($entity->getDisplayName(), $entity->getURL()); } @@ -62,7 +62,6 @@ ], $body_vars); }); -// draw page echo elgg_view_page(elgg_echo('static:edit'), [ 'content' => $body, 'sidebar' => $sidebar, diff --git a/views/default/resources/static/group.php b/views/default/resources/static/group.php index 0b39424..9f58db5 100644 --- a/views/default/resources/static/group.php +++ b/views/default/resources/static/group.php @@ -12,11 +12,11 @@ throw new PageNotFoundException(); } -elgg_push_collection_breadcrumbs('object', StaticPage::SUBTYPE, $group); +elgg_push_collection_breadcrumbs('object', \StaticPage::SUBTYPE, $group); -$can_write = $group->canWriteToContainer(0, 'object', StaticPage::SUBTYPE); +$can_write = $group->canWriteToContainer(0, 'object', \StaticPage::SUBTYPE); if ($can_write) { - elgg_register_title_button('add', 'object', StaticPage::SUBTYPE); + elgg_register_title_button('add', 'object', \StaticPage::SUBTYPE); } $ignore_access = $can_write ? ELGG_IGNORE_ACCESS : 0; @@ -24,7 +24,7 @@ $body = elgg_call($ignore_access, function() use ($group) { return elgg_list_entities([ 'type' => 'object', - 'subtype' => StaticPage::SUBTYPE, + 'subtype' => \StaticPage::SUBTYPE, 'metadata_name_value_pairs' => [ 'parent_guid' => 0, ], diff --git a/views/default/resources/static/last_editor.php b/views/default/resources/static/last_editor.php index 74b6f5a..ab41a0a 100644 --- a/views/default/resources/static/last_editor.php +++ b/views/default/resources/static/last_editor.php @@ -9,14 +9,14 @@ $page_owner = elgg_get_page_owner_entity(); -elgg_push_collection_breadcrumbs('object', StaticPage::SUBTYPE); +elgg_push_collection_breadcrumbs('object', \StaticPage::SUBTYPE); $title = elgg_echo('static:last_editor:title', [$page_owner->getDisplayName()]); $body = elgg_call(ELGG_IGNORE_ACCESS, function() use ($page_owner) { return elgg_list_entities([ 'type' => 'object', - 'subtype' => StaticPage::SUBTYPE, + 'subtype' => \StaticPage::SUBTYPE, 'wheres' => [ function (QueryBuilder $qb, $main_alias) use ($page_owner) { $where = new WhereClause("{$main_alias}.guid IN ( diff --git a/views/default/resources/static/out_of_date.php b/views/default/resources/static/out_of_date.php index 696c3d9..3bd1680 100644 --- a/views/default/resources/static/out_of_date.php +++ b/views/default/resources/static/out_of_date.php @@ -20,7 +20,6 @@ 'checked' => $include_groups ? true : false, 'default' => false, 'label' => elgg_echo('static:out_of_date:include_groups'), - 'label_class' => 'float-alt', 'onchange' => '$("#static_out_of_date").submit();', ]); @@ -30,6 +29,7 @@ 'disable_security' => true, 'body' => $checkbox, 'action' => 'static/out_of_date', + 'class' => 'elgg-justify-right', ]); $body .= elgg_list_entities([ diff --git a/views/default/resources/static/out_of_date_group.php b/views/default/resources/static/out_of_date_group.php index ed4c6d2..686b394 100644 --- a/views/default/resources/static/out_of_date_group.php +++ b/views/default/resources/static/out_of_date_group.php @@ -12,21 +12,19 @@ elgg_group_tool_gatekeeper('static', $page_owner->guid); -elgg_push_collection_breadcrumbs('object', StaticPage::SUBTYPE, $page_owner); +elgg_push_collection_breadcrumbs('object', \StaticPage::SUBTYPE, $page_owner); $days = (int) elgg_get_plugin_setting('out_of_date_days', 'static'); -$body = elgg_list_entities([ - 'type' => 'object', - 'subtype' => StaticPage::SUBTYPE, - 'container_guid' => $page_owner->guid, - 'modified_time_upper' => Values::normalizeTime("-{$days} days"), - 'order_by' => new OrderByClause('e.time_updated', 'DESC'), - 'no_results' => elgg_echo('static:out_of_date:none'), -]); - echo elgg_view_page(elgg_echo('static:out_of_date:title'), [ - 'content' => $body, + 'content' => elgg_list_entities([ + 'type' => 'object', + 'subtype' => \StaticPage::SUBTYPE, + 'container_guid' => $page_owner->guid, + 'modified_time_upper' => Values::normalizeTime("-{$days} days"), + 'order_by' => new OrderByClause('e.time_updated', 'DESC'), + 'no_results' => elgg_echo('static:out_of_date:none'), + ]), 'filter_id' => 'static', 'filter_value' => 'out_of_date_group', ]); diff --git a/views/default/resources/static/out_of_date_owner.php b/views/default/resources/static/out_of_date_owner.php index fbf730d..409fc01 100644 --- a/views/default/resources/static/out_of_date_owner.php +++ b/views/default/resources/static/out_of_date_owner.php @@ -11,7 +11,7 @@ $page_owner = elgg_get_page_owner_entity(); -elgg_push_collection_breadcrumbs('object', StaticPage::SUBTYPE); +elgg_push_collection_breadcrumbs('object', \StaticPage::SUBTYPE); $title_text = elgg_echo('static:out_of_date:owner:title', [$page_owner->getDisplayName()]); diff --git a/views/default/resources/static/view.php b/views/default/resources/static/view.php index 21522a4..3390df1 100644 --- a/views/default/resources/static/view.php +++ b/views/default/resources/static/view.php @@ -8,7 +8,7 @@ $entity = elgg_call(ELGG_IGNORE_ACCESS, function () use ($guid) { return get_entity($guid); }); -if (!$entity instanceof StaticPage) { +if (!$entity instanceof \StaticPage) { throw new EntityNotFoundException(); } @@ -44,12 +44,12 @@ // page owner (for groups) $owner = $entity->getOwnerEntity(); -if ($owner instanceof ElggGroup) { +if ($owner instanceof \ElggGroup) { elgg_set_page_owner_guid($owner->guid); - elgg_push_collection_breadcrumbs('object', StaticPage::SUBTYPE, $owner); + elgg_push_collection_breadcrumbs('object', \StaticPage::SUBTYPE, $owner); } else { - elgg_push_collection_breadcrumbs('object', StaticPage::SUBTYPE); + elgg_push_collection_breadcrumbs('object', \StaticPage::SUBTYPE); } // show breadcrumb diff --git a/views/default/static/out_of_date.js b/views/default/static/out_of_date.js deleted file mode 100644 index f41157d..0000000 --- a/views/default/static/out_of_date.js +++ /dev/null @@ -1,19 +0,0 @@ -define(['jquery', 'elgg/Ajax'], function($, Ajax) { - $(document).on('click', '#static-out-of-date-touch-link', function(event) { - event.preventDefault(); - - if ((typeof event.result !== 'undefined') && (event.result === false)) { - return false; - } - - var $link = $(this); - var ajax = new Ajax(); - ajax.action($link.attr('href'), { - success: function() { - $link.closest('.static-out-of-date-message').remove(); - } - }); - - return false; - }); -}); diff --git a/views/default/static/out_of_date.mjs b/views/default/static/out_of_date.mjs new file mode 100644 index 0000000..90e2d54 --- /dev/null +++ b/views/default/static/out_of_date.mjs @@ -0,0 +1,20 @@ +import 'jquery'; +import Ajax from 'elgg/Ajax'; + +$(document).on('click', '#static-out-of-date-touch-link', function(event) { + event.preventDefault(); + + if ((typeof event.result !== 'undefined') && (event.result === false)) { + return false; + } + + var $link = $(this); + var ajax = new Ajax(); + ajax.action($link.attr('href'), { + success: function() { + $link.closest('.static-out-of-date-message').remove(); + } + }); + + return false; +}); diff --git a/views/default/static/out_of_date.php b/views/default/static/out_of_date.php index 9dddc92..9b1340c 100644 --- a/views/default/static/out_of_date.php +++ b/views/default/static/out_of_date.php @@ -1,7 +1,7 @@ 'static-out-of-date-touch-link', ]); - elgg_require_js('static/out_of_date'); + elgg_import_esm('static/out_of_date'); } echo elgg_view_message('warning', elgg_echo('static:out_of_date:message'), [ diff --git a/views/default/static/search_advanced/item.php b/views/default/static/search_advanced/item.php index 3641ec9..72b6927 100644 --- a/views/default/static/search_advanced/item.php +++ b/views/default/static/search_advanced/item.php @@ -1,5 +1,3 @@ title; +echo elgg_extract('entity', $vars)?->title; diff --git a/views/default/static/sidebar_menu.js b/views/default/static/sidebar_menu.js deleted file mode 100644 index d1b2ff5..0000000 --- a/views/default/static/sidebar_menu.js +++ /dev/null @@ -1,59 +0,0 @@ -define(['jquery', 'elgg/Ajax', 'jquery-ui/widgets/sortable'], function($, Ajax) { - var ajax = new Ajax(); - - $('.elgg-menu[data-menu-section="static"] > li.static-sortable ul').sortable({ - items: '> li', - connectWith: '.elgg-menu[data-menu-section="static"] > li.static-sortable ul', - forcePlaceholderSize: true, - revert: true, - tolerance: 'pointer', - containment: '.elgg-menu[data-menu-section="static"]', - start: function(event, ui) { - $(ui.item).find(' > a').addClass('dragged'); - }, - update: function(event, ui) { - - if (!$(this).is($(ui.item).parent())) { - // only trigger update on receiving sortable - return; - } - - var $parent = $(ui.item).parent().parent(); - var parent_guid = $parent.find(' > a').attr('rel'); - var new_order = []; - - $parent.find('> ul > li > a').each(function(index, child) { - new_order[index] = $(child).attr('rel'); - }); - - ajax.action('static/reorder', { - data: { - guid: parent_guid, - order: new_order - } - }); - } - }); - - $('.elgg-menu[data-menu-section="static"] li a').on('click', function(event) { - if (!$(this).hasClass('dragged')) { - return; - } - - event.preventDefault(); - event.stopImmediatePropagation(); - - $(this).removeClass('dragged'); - }); - - $('.elgg-menu[data-menu-section="static"] li a span').on('click', function(event) { - if ($(this).closest('a').hasClass('dragged')) { - return; - } - - event.preventDefault(); - event.stopImmediatePropagation(); - - document.location = $(this).closest('a').attr('href'); - }); -}); diff --git a/views/default/static/sidebar_menu.mjs b/views/default/static/sidebar_menu.mjs new file mode 100644 index 0000000..b6e21df --- /dev/null +++ b/views/default/static/sidebar_menu.mjs @@ -0,0 +1,61 @@ +import 'jquery'; +import 'jquery-ui'; +import Ajax from 'elgg/Ajax'; + +var ajax = new Ajax(); + +$('.elgg-menu[data-menu-section="static"] > li.static-sortable ul').sortable({ + items: '> li', + connectWith: '.elgg-menu[data-menu-section="static"] > li.static-sortable ul', + forcePlaceholderSize: true, + revert: true, + tolerance: 'pointer', + containment: '.elgg-menu[data-menu-section="static"]', + start: function(event, ui) { + $(ui.item).find(' > a').addClass('dragged'); + }, + update: function(event, ui) { + + if (!$(this).is($(ui.item).parent())) { + // only trigger update on receiving sortable + return; + } + + var $parent = $(ui.item).parent().parent(); + var parent_guid = $parent.find(' > a').attr('rel'); + var new_order = []; + + $parent.find('> ul > li > a').each(function(index, child) { + new_order[index] = $(child).attr('rel'); + }); + + ajax.action('static/reorder', { + data: { + guid: parent_guid, + order: new_order + } + }); + } +}); + +$('.elgg-menu[data-menu-section="static"] li a').on('click', function(event) { + if (!$(this).hasClass('dragged')) { + return; + } + + event.preventDefault(); + event.stopImmediatePropagation(); + + $(this).removeClass('dragged'); +}); + +$('.elgg-menu[data-menu-section="static"] li a span').on('click', function(event) { + if ($(this).closest('a').hasClass('dragged')) { + return; + } + + event.preventDefault(); + event.stopImmediatePropagation(); + + document.location = $(this).closest('a').attr('href'); +}); diff --git a/views/default/css/static/site.css b/views/default/static/site.css similarity index 78% rename from views/default/css/static/site.css rename to views/default/static/site.css index 16046ff..9f189b7 100644 --- a/views/default/css/static/site.css +++ b/views/default/static/site.css @@ -1,5 +1,4 @@ .static-edit-top-parent-select, .static-edit-sub-parent-select { max-width: 200px; - margin-bottom: .5rem; } diff --git a/views/default/widgets/static_groups/content.php b/views/default/widgets/static_groups/content.php index 4e95353..7c2fd46 100644 --- a/views/default/widgets/static_groups/content.php +++ b/views/default/widgets/static_groups/content.php @@ -11,12 +11,12 @@ return; } -$ignore_access = $group->canWriteToContainer(0, 'object', StaticPage::SUBTYPE) ? ELGG_IGNORE_ACCESS : 0; +$ignore_access = $group->canWriteToContainer(0, 'object', \StaticPage::SUBTYPE) ? ELGG_IGNORE_ACCESS : 0; echo elgg_call($ignore_access, function () use ($group) { $entities = elgg_get_entities([ 'type' => 'object', - 'subtype' => StaticPage::SUBTYPE, + 'subtype' => \StaticPage::SUBTYPE, 'metadata_name_value_pairs' => [ 'parent_guid' => 0, ],