Fix reset of the space homepage settings (#5307)

* Fix reset of the space homepage settings

* Update CHANGELOG.md

Co-authored-by: Lucas Bartholemy <luke-@users.noreply.github.com>
This commit is contained in:
Yuriy Bakhtin 2021-09-24 18:58:03 +03:00 committed by GitHub
parent c8a82db5ac
commit 26de985b08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 26 deletions

View File

@ -5,6 +5,7 @@ HumHub Changelog
1.9.2 (Unreleased)
------------------
- Fix #5265: Fix logging filter "Error" when not entries
- Fix #5307: Fix reset of the space homepage settings
- Fix #5301: Change people default sorting

View File

@ -8,7 +8,6 @@
namespace humhub\modules\space\widgets;
use humhub\modules\content\components\ContentContainerController;
use humhub\modules\content\helpers\ContentContainerHelper;
use humhub\modules\space\models\Space;
use humhub\modules\space\Module;
@ -114,44 +113,41 @@ class Menu extends LeftNavigation
*/
public static function getDefaultPageUrl($space)
{
$settings = Yii::$app->getModule('space')->settings;
$indexUrl = $settings->contentContainer($space)->get('indexUrl');
if ($indexUrl !== null) {
$pages = static::getAvailablePages();
if (isset($pages[$indexUrl])) {
return $indexUrl;
}
//Either the module was deactivated or url changed
$settings->contentContainer($space)->delete('indexUrl');
}
return null;
return static::getAvailablePageUrl($space, 'indexUrl');
}
/**
* Returns space default / homepage
* Returns space default / homepage for guests
*
* @param $space Space
* @return string|null the url to redirect or null for default home
*/
public static function getGuestsDefaultPageUrl($space)
{
$settings = Yii::$app->getModule('space')->settings;
return static::getAvailablePageUrl($space, 'indexGuestUrl');
}
$indexUrl = $settings->contentContainer($space)->get('indexGuestUrl');
if ($indexUrl !== null) {
$pages = static::getAvailablePages();
if (isset($pages[$indexUrl])) {
return $indexUrl;
}
//Either the module was deactivated or url changed
$settings->contentContainer($space)->delete('indexGuestUrl');
/**
* Get default Space page URL by setting name
*
* @param Space $space
* @param string $pageSettingName
* @return string|null
*/
public static function getAvailablePageUrl(Space $space, string $pageSettingName): ?string
{
/* @var Module $spaceModule */
$spaceModule = Yii::$app->getModule('space');
$indexUrl = $spaceModule->settings->contentContainer($space)->get($pageSettingName);
if ($indexUrl === null) {
return null;
}
return null;
$pages = static::getAvailablePages();
return isset($pages[$indexUrl]) ? $indexUrl : null;
}
}