From 62596ca4e2cf98f5a63f01e59d4d40f7305c3e22 Mon Sep 17 00:00:00 2001 From: Yuriy Bakhtin Date: Tue, 19 Sep 2023 13:14:44 +0200 Subject: [PATCH] Improve a sort order of wall entry creating tab menu and form --- CHANGELOG.md | 1 + protected/humhub/libs/Sort.php | 21 +++++++++++++------ .../WallCreateContentFormContainer.php | 4 +--- .../content/widgets/WallCreateContentMenu.php | 6 ++---- .../widgets/stream/WallStreamEntryWidget.php | 2 +- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8dc811cf4a..37f0d3744f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ HumHub Changelog - Fix #6349: Fix error on login new user from external service when maintenance is enabled - Fix #6557: Fix not initialized groups array on the module administration - Fix #6556: Fix command `theme/switch` +- Fix #6574: Improve a sort order of wall entry creating tab menu and form 1.14.3 (July 27, 2023) ---------------------- diff --git a/protected/humhub/libs/Sort.php b/protected/humhub/libs/Sort.php index a425e0f393..0034172657 100644 --- a/protected/humhub/libs/Sort.php +++ b/protected/humhub/libs/Sort.php @@ -29,13 +29,22 @@ class Sort $sortA = static::getSortValue($a, $field, $default); $sortB = static::getSortValue($b, $field, $default); - if ($sortA == $sortB) { - return 0; - } elseif ($sortA < $sortB) { - return -1; - } else { - return 1; + if (!is_array($sortA)) { + $sortA = [$sortA]; } + if (!is_array($sortB)) { + $sortB = [$sortB]; + } + + foreach ($sortA as $s => $sortAItem) { + $sortBItem = $sortB[$s] ?? $default; + if ($sortAItem == $sortBItem) { + // Go to compare next sort value + continue; + } + return $sortAItem < $sortBItem ? -1 : 1; + } + return 0; }); return $arr; diff --git a/protected/humhub/modules/content/widgets/WallCreateContentFormContainer.php b/protected/humhub/modules/content/widgets/WallCreateContentFormContainer.php index 831dcc738c..7b1a7377fa 100644 --- a/protected/humhub/modules/content/widgets/WallCreateContentFormContainer.php +++ b/protected/humhub/modules/content/widgets/WallCreateContentFormContainer.php @@ -11,8 +11,6 @@ use humhub\libs\Sort; use humhub\modules\content\widgets\stream\WallStreamEntryWidget; use humhub\components\Widget; use humhub\modules\content\components\ContentContainerActiveRecord; -use humhub\modules\content\components\ContentActiveRecord; -use Yii; use yii\web\HttpException; /** @@ -71,7 +69,7 @@ class WallCreateContentFormContainer extends Widget $forms[] = [ 'class' => $wallEntryWidget->createFormClass, - 'sortOrder' => $wallEntryWidget->createFormSortOrder ?? '9999999-' . $content->getContentName(), + 'sortOrder' => [$wallEntryWidget->createFormSortOrder, ucfirst($content->getContentName())] ]; } diff --git a/protected/humhub/modules/content/widgets/WallCreateContentMenu.php b/protected/humhub/modules/content/widgets/WallCreateContentMenu.php index 57d6ef1353..edb4fd79e3 100644 --- a/protected/humhub/modules/content/widgets/WallCreateContentMenu.php +++ b/protected/humhub/modules/content/widgets/WallCreateContentMenu.php @@ -7,12 +7,10 @@ namespace humhub\modules\content\widgets; -use humhub\modules\content\components\ContentActiveRecord; use humhub\modules\content\components\ContentContainerActiveRecord; use humhub\modules\content\widgets\stream\WallStreamEntryWidget; use humhub\modules\ui\menu\MenuLink; use humhub\modules\ui\menu\widgets\Menu; -use Yii; /** * WallCreateContentMenu is the widget for Menu above wall create content Form @@ -80,10 +78,10 @@ class WallCreateContentMenu extends Menu } $menuOptions = [ - 'label' => ucfirst($content->getContentName()), + 'label' => $label = ucfirst($content->getContentName()), 'icon' => $content->getIcon(), 'url' => '#', - 'sortOrder' => $wallEntryWidget->createFormSortOrder ?? '9999999-' . $content->getContentName(), + 'sortOrder' => [$wallEntryWidget->createFormSortOrder, $label] ]; $url = $this->contentContainer->createUrl($wallEntryWidget->createRoute); diff --git a/protected/humhub/modules/content/widgets/stream/WallStreamEntryWidget.php b/protected/humhub/modules/content/widgets/stream/WallStreamEntryWidget.php index 05156a469b..fc346999ce 100644 --- a/protected/humhub/modules/content/widgets/stream/WallStreamEntryWidget.php +++ b/protected/humhub/modules/content/widgets/stream/WallStreamEntryWidget.php @@ -163,7 +163,7 @@ abstract class WallStreamEntryWidget extends StreamEntryWidget /** * @var int Sort order of create form and tab menu on wall stream */ - public $createFormSortOrder; + public $createFormSortOrder = 1000000; /** * @var string Class name of the Form to create a Content from wall stream,