Skip to content

Commit

Permalink
changed: updated for Elgg 6
Browse files Browse the repository at this point in the history
  • Loading branch information
jeabakker committed Jun 5, 2024
1 parent 5ce3bba commit 6af37d4
Show file tree
Hide file tree
Showing 17 changed files with 172 additions and 200 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,6 +1,6 @@
# Pages Tools

![Elgg 5.0](https://img.shields.io/badge/Elgg-5.0-green.svg)
![Elgg 6.0](https://img.shields.io/badge/Elgg-6.0-green.svg)
![Lint Checks](https://github.com/ColdTrick/pages_tools/actions/workflows/lint.yml/badge.svg?event=push)
[![Latest Stable Version](https://poser.pugx.org/coldtrick/pages_tools/v/stable.svg)](https://packagist.org/packages/coldtrick/pages_tools)
[![License](https://poser.pugx.org/coldtrick/pages_tools/license.svg)](https://packagist.org/packages/coldtrick/pages_tools)
Expand Down
4 changes: 2 additions & 2 deletions actions/pages/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
try {
PDFExport::toPDF($page, $format, $include_subpages, $include_index);
exit();
} catch (Exception $e) {
return elgg_error_response($e->getMessage());
} catch (\Throwable $t) {
return elgg_error_response($t->getMessage());
}
1 change: 1 addition & 0 deletions actions/pages/reorder.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
return elgg_error_response(elgg_echo('pages_tools:actions:reorder:error:subpages'));
}

/* @var $sub_page \ElggPage */
foreach ($sub_pages as $sub_page) {
$pos = array_search($sub_page->guid, $order) + 1;

Expand Down
6 changes: 4 additions & 2 deletions classes/ColdTrick/PagesTools/Menus/PagesNav.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace ColdTrick\PagesTools\Menus;

use Elgg\Menu\MenuItems;

/**
* Add menu items to the pages_nav menu
*/
Expand All @@ -17,7 +19,7 @@ class PagesNav {
public static function orderPagesNav(\Elgg\Event $event): void {
$load_js = false;

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

/* @var $item \ElggMenuItem */
Expand All @@ -40,7 +42,7 @@ public static function orderPagesNav(\Elgg\Event $event): void {
}

if ($load_js) {
elgg_require_js('pages_tools/navigation');
elgg_import_esm('pages_tools/navigation');
}
}
}
18 changes: 9 additions & 9 deletions classes/ColdTrick/PagesTools/PDFExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class PDFExport {
* @param bool $include_index add a index page
* @param bool $include_subpages include the subpages
*
* @return string contents for PDF
* @return void but streams the contents of the PDF
*/
public static function toPDF(\ElggPage $entity, string $format = 'a4', bool $include_index = false, bool $include_subpages = false) {
public static function toPDF(\ElggPage $entity, string $format = 'a4', bool $include_index = false, bool $include_subpages = false): void {
// begin of output
$html = '';

Expand Down Expand Up @@ -61,7 +61,9 @@ public static function toPDF(\ElggPage $entity, string $format = 'a4', bool $inc
}

// load library
$dompdf = new Dompdf();
$dompdf = new Dompdf([
'enable_remote' => true,
]);
// set correct page format
$dompdf->setPaper($format);
// set contents
Expand All @@ -72,13 +74,13 @@ public static function toPDF(\ElggPage $entity, string $format = 'a4', bool $inc
}

/**
* Get the ordered list sub pages
* Get the ordered list sub-pages
*
* @param \ElggPage $page the page to get subpages for
*
* @return false|\ElggPage[]
* @return null|\ElggPage[]
*/
protected static function getOrderedChildren(\ElggPage $page) {
protected static function getOrderedChildren(\ElggPage $page): ?array {
$children = elgg_get_entities([
'type' => 'object',
'subtype' => 'page',
Expand All @@ -88,7 +90,7 @@ protected static function getOrderedChildren(\ElggPage $page) {
],
]);
if (empty($children)) {
return false;
return null;
}

$result = [];
Expand Down Expand Up @@ -119,7 +121,6 @@ protected static function getOrderedChildren(\ElggPage $page) {
* @return string
*/
protected static function renderIndex(\ElggPage $page): string {

$children = self::getOrderedChildren($page);
if (empty($children)) {
return '';
Expand Down Expand Up @@ -153,7 +154,6 @@ protected static function renderIndex(\ElggPage $page): string {
* @return string
*/
protected static function renderChildPages(\ElggPage $page): string {

$children = self::getOrderedChildren($page);
if (empty($children)) {
return '';
Expand Down
21 changes: 7 additions & 14 deletions classes/ColdTrick/PagesTools/Widgets.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,21 @@ class Widgets {
/**
* Add widget title url
*
* @param \Elgg\Event $event 'register', 'menu:entity'
* @param \Elgg\Event $event 'entity:url', 'object:widget'
*
* @return void|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;
}

$widget = $event->getEntityParam();
if (!$widget instanceof \ElggWidget) {
return;
if (!$widget instanceof \ElggWidget || $widget->handler !== 'index_pages') {
return null;
}

switch ($widget->handler) {
case 'pages':
$owner = $widget->getOwnerEntity();
return $owner instanceof \ElggGroup ? 'pages/group/' . $owner->guid . '/all' : 'pages/owner/' . $owner->username;
case 'index_pages':
return 'pages/all';
}
return elgg_generate_url('collection:object:pages:all');
}
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"issues": "https://github.com/ColdTrick/pages_tools/issues"
},
"require": {
"dompdf/dompdf" : "~2.0.0"
"dompdf/dompdf" : "~3.0.0"
},
"conflict": {
"elgg/elgg": "<5.0"
"elgg/elgg": "<6.0"
}
}
Loading

0 comments on commit 6af37d4

Please sign in to comment.