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 14ac1bc commit fa4c76e
Show file tree
Hide file tree
Showing 32 changed files with 279 additions and 300 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 Pack
===========

![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_pack/actions/workflows/lint.yml/badge.svg?event=push)
[![Latest Stable Version](https://poser.pugx.org/coldtrick/widget_pack/v/stable.svg)](https://packagist.org/packages/coldtrick/widget_pack)
[![License](https://poser.pugx.org/coldtrick/widget_pack/license.svg)](https://packagist.org/packages/coldtrick/widget_pack)
Expand Down
6 changes: 3 additions & 3 deletions classes/ColdTrick/WidgetPack/Bookmarks.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ class Bookmarks {
*
* @param \Elgg\Event $event 'view_vars', 'widgets/content_by_tag/display/[simple|slim]'
*
* @return void|array
* @return null|array
*/
public static function changeEntityURL(\Elgg\Event $event) {
public static function changeEntityURL(\Elgg\Event $event): ?array {

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

$return_value = $event->getValue();
Expand Down
5 changes: 2 additions & 3 deletions classes/ColdTrick/WidgetPack/ContentByTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ class ContentByTag {
*
* @return array
*/
public static function getSupportedContent() {
public static function getSupportedContent(): array {
$result = [
'blog' => 'blog',
'file' => 'file',
'pages' => 'page',
'bookmarks' => 'bookmarks',
'thewire' => 'thewire',
'event_manager' => 'event',
'tasks' => 'task_top',
'discussions' => 'discussion',
'poll' => 'poll',
'questions' => 'question',
Expand All @@ -35,6 +34,6 @@ public static function getSupportedContent() {
unset($result[$plugin]);
}

return elgg_trigger_event_results('supported_content', 'widgets:content_by_tag', $result, $result);
return (array) elgg_trigger_event_results('supported_content', 'widgets:content_by_tag', $result, $result);
}
}
2 changes: 1 addition & 1 deletion classes/ColdTrick/WidgetPack/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Cron {
*
* @return void
*/
public static function fetchRssServerWidgets(\Elgg\Event $event) {
public static function fetchRssServerWidgets(\Elgg\Event $event): void {

if (elgg_get_plugin_setting('rss_cron', 'widget_pack') !== 'yes') {
return;
Expand Down
51 changes: 26 additions & 25 deletions classes/ColdTrick/WidgetPack/Widgets.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Widgets {
*
* @param \Elgg\Event $event 'cacheable_handlers', 'widget_manager'
*
* @return bool
* @return array
*/
public static function getCacheableWidgets(\Elgg\Event $event) {
$return_value = $event->getValue();
Expand All @@ -38,7 +38,7 @@ public static function getCacheableWidgets(\Elgg\Event $event) {
*
* @return void
*/
public static function disableFreeHTMLInputFilter(\Elgg\Event $event) {
public static function disableFreeHTMLInputFilter(\Elgg\Event $event): void {
if (!elgg_is_admin_logged_in()) {
return;
}
Expand Down Expand Up @@ -67,15 +67,15 @@ public static function disableFreeHTMLInputFilter(\Elgg\Event $event) {
*
* @param \Elgg\Event $event 'format', 'friendly:time'
*
* @return string
* @return null|string
*/
public static function rssFriendlyTime(\Elgg\Event $event) {
public static function rssFriendlyTime(\Elgg\Event $event): ?string {
if (empty($event->getParam('time'))) {
return;
return null;
}

if (!elgg_in_context('rss_date')) {
return;
return null;
}

$date_info = getdate($event->getParam('time'));
Expand All @@ -94,19 +94,19 @@ public static function rssFriendlyTime(\Elgg\Event $event) {
*
* @param \Elgg\Event $event 'entity:url', 'object'
*
* @return string
* @return null|string
*/
public static function getTitleURLs(\Elgg\Event $event) {
public static function getTitleURLs(\Elgg\Event $event): ?string {
$return = $event->getValue();
if ($return) {
// someone else provided already a result
return;
return null;
}

$widget = $event->getEntityParam();
if (!$widget instanceof \ElggWidget) {
// not a widget
return;
return null;
}

switch ($widget->handler) {
Expand All @@ -132,6 +132,8 @@ public static function getTitleURLs(\Elgg\Event $event) {
}
break;
}

return null;
}

/**
Expand All @@ -141,14 +143,13 @@ public static function getTitleURLs(\Elgg\Event $event) {
*
* @return void
*/
public static function twitterSearchGetWidgetID(\Elgg\Event $event) {
public static function twitterSearchGetWidgetID(\Elgg\Event $event): void {

$widget = get_entity((int) get_input('guid'));
if (!$widget instanceof \ElggWidget || $widget->handler !== 'twitter_search') {
return;
}

// get embed code

$embed_code = get_input('embed_code', [], false); // do not strip code
if (empty($embed_code)) {
return;
Expand Down Expand Up @@ -181,11 +182,11 @@ public static function twitterSearchGetWidgetID(\Elgg\Event $event) {
*
* @param \Elgg\Event $event 'search:fields', 'user'
*
* @return array
* @return null|array
*/
public static function userSearchByEmail(\Elgg\Event $event) {
public static function userSearchByEmail(\Elgg\Event $event): ?array {
if ($event->getParam('widget') !== 'user_search') {
return;
return null;
}

$value = (array) $event->getValue();
Expand All @@ -208,7 +209,7 @@ public static function userSearchByEmail(\Elgg\Event $event) {
*
* @return void
*/
public static function rssServerInvalidateCache(\Elgg\Event $event) {
public static function rssServerInvalidateCache(\Elgg\Event $event): void {

$widget = $event->getObject();
if (!$widget instanceof \ElggWidget || $widget->handler !== 'rss_server') {
Expand All @@ -223,11 +224,11 @@ public static function rssServerInvalidateCache(\Elgg\Event $event) {
*
* @param \Elgg\Event $event 'entity:{$type}:sizes', 'object'
*
* @return array
* @return null|array
*/
public static function getSlideshowIconSizes(\Elgg\Event $event) {
public static function getSlideshowIconSizes(\Elgg\Event $event): ?array {
if (!preg_match('/^entity:slider_image_[\d]+:sizes$/', $event->getName())) {
return;
return null;
}

$result = $event->getValue();
Expand Down Expand Up @@ -256,22 +257,22 @@ public static function getSlideshowIconSizes(\Elgg\Event $event) {
*
* @param \Elgg\Event $event 'response', 'action:widgets/save'
*
* @return void|OkResponse
* @return null|OkResponse
*/
public static function saveSlideshowConfig(\Elgg\Event $event) {
public static function saveSlideshowConfig(\Elgg\Event $event): ?OkResponse {

$result = $event->getValue();
if ($result instanceof ErrorResponse) {
return;
return null;
}

$widget = get_entity((int) get_input('guid'));
if (!$widget instanceof \ElggWidget) {
return;
return null;
}

if ($widget->handler !== 'image_slideshow') {
return;
return null;
}

$old_config = $widget->slides_config ?: [];
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"simplepie/simplepie": "~1.8.0"
},
"conflict": {
"elgg/elgg": "<5.1"
"elgg/elgg": "<6.0"
}
}
4 changes: 2 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion views/default/widgets/content_by_tag/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
return $qb->compare("{$joined_alias}.entity_guid", '=', "{$main_alias}.guid");
};

$options['joins'][] = new JoinClause(QueryBuilder::TABLE_METADATA, $alias, $on);
$options['joins'][] = new JoinClause(\Elgg\Database\MetadataTable::TABLE_NAME, $alias, $on);

$options['wheres'][] = function(QueryBuilder $qb) use ($alias, $value) {
$md = new MetadataWhereClause();
Expand Down
13 changes: 0 additions & 13 deletions views/default/widgets/content_by_tag/edit.js

This file was deleted.

7 changes: 7 additions & 0 deletions views/default/widgets/content_by_tag/edit.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import 'jquery';

$(document).on('change', '.elgg-form-widgets-save-content-by-tag [name="params[display_option]"]', function() {
var $edit_form = $(this).parents('.elgg-form-widgets-save-content-by-tag');
$edit_form.find('.widgets-content-by-tag-display-options > div').hide();
$edit_form.find('.widgets-content-by-tag-display-options-' + $(this).val()).show();
});
76 changes: 42 additions & 34 deletions views/default/widgets/content_by_tag/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
$content_type = $keys[0];
}

elgg_import_esm('widgets/content_by_tag/edit');

echo elgg_view_field([
'#type' => 'userpicker',
'#label' => elgg_echo('widgets:content_by_tag:owner_guids'),
Expand All @@ -36,12 +38,14 @@
'value' => 'yes',
'switch' => true,
]);
} elseif (elgg_view_exists('input/grouppicker')) {
$container_guids = elgg_echo('widgets:content_by_tag:container_guids') . '<br />';
$container_guids .= elgg_view('input/hidden', ['name' => 'params[container_guids]', 'value' => 0]);
$container_guids .= elgg_view('input/grouppicker', ['name' => 'params[container_guids]', 'values' => $widget->container_guids]);
$container_guids .= elgg_format_element('div', ['class' => 'elgg-subtext'], elgg_echo('widgets:content_by_tag:container_guids:description'));
echo elgg_format_element('div', [], $container_guids);
} else {
echo elgg_view_field([
'#type' => 'grouppicker',
'#label' => elgg_echo('widgets:content_by_tag:container_guids'),
'#help' => elgg_echo('widgets:content_by_tag:container_guids:description'),
'name' => 'params[container_guids]',
'values' => $widget->container_guids,
]);
}

echo elgg_view('object/widget/edit/num_display', [
Expand Down Expand Up @@ -106,34 +110,40 @@
],
]);

$display_options = '';

$content = elgg_view_field([
'#type' => 'checkbox',
'#label' => elgg_echo('widgets:content_by_tag:show_avatar'),
'name' => 'params[show_avatar]',
'checked' => $widget->show_avatar !== 'no',
'default' => 'no',
'value' => 'yes',
'switch' => true,
]);

$display_options .= elgg_format_element('div', ['class' => 'widgets-content-by-tag-display-options-simple'], $content);

$content = elgg_view_field([
'#type' => 'checkbox',
'#label' => elgg_echo('widgets:content_by_tag:show_timestamp'),
'name' => 'params[show_timestamp]',
'checked' => $widget->show_timestamp !== 'no',
'default' => 'no',
'value' => 'yes',
'switch' => true,
echo elgg_view_field([
'#type' => 'fieldset',
'class' => 'widgets-content-by-tag-display-options',
'fields' => [
[
'#type' => 'checkbox',
'#label' => elgg_echo('widgets:content_by_tag:show_avatar'),
'#class' => [
'widgets-content-by-tag-display-options-simple',
$widget->display_option !== 'simple' ? 'hidden' : null,
],
'name' => 'params[show_avatar]',
'checked' => $widget->show_avatar !== 'no',
'default' => 'no',
'value' => 'yes',
'switch' => true,
],
[
'#type' => 'checkbox',
'#label' => elgg_echo('widgets:content_by_tag:show_timestamp'),
'#class' => [
'widgets-content-by-tag-display-options-simple',
'widgets-content-by-tag-display-options-slim',
!in_array($widget->display_option, ['simple', 'slim']) ? 'hidden' : null,
],
'name' => 'params[show_timestamp]',
'checked' => $widget->show_timestamp !== 'no',
'default' => 'no',
'value' => 'yes',
'switch' => true,
],
],
]);

$display_options .= elgg_format_element('div', ['class' => 'widgets-content-by-tag-display-options-simple widgets-content-by-tag-display-options-slim'], $content);

echo elgg_format_element('div', ['class' => 'widgets-content-by-tag-display-options'], $display_options);

echo elgg_view_field([
'#type' => 'select',
'#label' => elgg_echo('widgets:content_by_tag:order_by'),
Expand All @@ -144,5 +154,3 @@
'alpha' => elgg_echo('widgets:content_by_tag:order_by:alpha'),
],
]);

echo elgg_format_element('script', [], 'require(["widgets/content_by_tag/edit"], function() { init(); })');
Loading

0 comments on commit fa4c76e

Please sign in to comment.