Fix #5903: ContentContainerModule::getEnabledContentContainers() returns an empty array (#5907)

This commit is contained in:
Marc Farré 2022-10-25 15:45:53 +02:00 committed by GitHub
parent ec5aac5b76
commit 1fae0b8ca8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 3 deletions

View File

@ -10,3 +10,4 @@ HumHub Changelog
- Enh #5872: Invalidate active sessions after password changing - Enh #5872: Invalidate active sessions after password changing
- Enh #5820: Selftest for base URL - Enh #5820: Selftest for base URL
- Enh #5891: Improve select2 width on people filters - Enh #5891: Improve select2 width on people filters
- Fix #5903: ContentContainerModule::getEnabledContentContainers() returns an empty array

View File

@ -9,6 +9,7 @@
namespace humhub\modules\content\components; namespace humhub\modules\content\components;
use humhub\components\Module; use humhub\components\Module;
use humhub\modules\content\models\ContentContainer;
use humhub\modules\content\models\ContentContainerModuleState; use humhub\modules\content\models\ContentContainerModuleState;
use humhub\modules\content\models\ContentContainerPermission; use humhub\modules\content\models\ContentContainerPermission;
@ -158,11 +159,22 @@ class ContentContainerModule extends Module
* Returns an array of all content containers where this module is enabled. * Returns an array of all content containers where this module is enabled.
* *
* @param string $containerClass optional filter to specific container class * @param string $containerClass optional filter to specific container class
* @return array of content container instances * @return ContentContainer[]
*/ */
public function getEnabledContentContainers($containerClass = "") public function getEnabledContentContainers($containerClass = null)
{ {
return []; $enabledContentContainers = [];
$contentContainerModuleStates = ContentContainerModuleState::findAll(['module_id' => $this->id, 'module_state' => [ContentContainerModuleState::STATE_ENABLED, ContentContainerModuleState::STATE_FORCE_ENABLED]]);
foreach ($contentContainerModuleStates as $contentContainerModuleState) {
$contentContainer = $contentContainerModuleState->contentContainer;
if (
$contentContainer !== null
&& (!$containerClass || $contentContainer->class === $containerClass)
) {
$enabledContentContainers[] = $contentContainer;
}
}
return $enabledContentContainers;
} }
/** /**

View File

@ -10,6 +10,7 @@ namespace humhub\modules\content\models;
use Yii; use Yii;
use yii\db\ActiveRecord; use yii\db\ActiveRecord;
use yii\db\ActiveQuery;
/** /**
* This is the model class for table "contentcontainer_module". * This is the model class for table "contentcontainer_module".
@ -17,6 +18,8 @@ use yii\db\ActiveRecord;
* @property integer $contentcontainer_id * @property integer $contentcontainer_id
* @property string $module_id * @property string $module_id
* @property integer $module_state * @property integer $module_state
*
* @property ContentContainer $contentContainer
*/ */
class ContentContainerModuleState extends ActiveRecord class ContentContainerModuleState extends ActiveRecord
{ {
@ -51,4 +54,13 @@ class ContentContainerModuleState extends ActiveRecord
return $labels ? $states : array_keys($states); return $labels ? $states : array_keys($states);
} }
/**
* @return ActiveQuery
*/
public function getContentContainer()
{
return $this
->hasOne(ContentContainer::class, ['id' => 'contentcontainer_id']);
}
} }