diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index b2562aa5..f2477a55 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,6 +1,10 @@ Changelog ========= +1.6.3 (Unreleased) +--------------------- +- Fix #477: Hide the settings button when module is not available for a container + 1.6.2 (July 16, 2024) --------------------- - Enh #495: Fix column `exdate` to delete more than 16 recurrence event entries diff --git a/module.json b/module.json index 2aebfb22..e804d0a5 100644 --- a/module.json +++ b/module.json @@ -3,7 +3,7 @@ "name": "Calendar", "description": "Create one-time or recurring events, invite and manage attendees, and keep track of all your events with the Calendar module.", "keywords": ["calendar"], - "version": "1.6.2", + "version": "1.6.3", "humhub": { "minVersion": "1.16.1" }, diff --git a/widgets/ConfigureButton.php b/widgets/ConfigureButton.php index ddea284c..f044d9d1 100644 --- a/widgets/ConfigureButton.php +++ b/widgets/ConfigureButton.php @@ -7,15 +7,17 @@ namespace humhub\modules\calendar\widgets; -use humhub\modules\calendar\helpers\Url; -use humhub\modules\user\models\User; -use humhub\widgets\ModalButton; -use Yii; use humhub\components\Widget; +use humhub\modules\calendar\helpers\Url; use humhub\modules\content\components\ContentContainerActiveRecord; +use humhub\modules\content\components\ContentContainerModuleManager; use humhub\modules\content\helpers\ContentContainerHelper; +use humhub\modules\content\models\ContentContainerModuleState; use humhub\modules\space\models\Space; +use humhub\modules\user\models\User; use humhub\widgets\Button; +use humhub\widgets\ModalButton; +use Yii; class ConfigureButton extends Widget { @@ -28,20 +30,43 @@ public function init() { $this->container = ContentContainerHelper::getCurrent(); - if(!$this->container) { + if (!$this->container) { $this->container = Yii::$app->user->getIdentity(); } - parent::init(); // TODO: Change the autogenerated stub + parent::init(); } - public function run() + /** + * @inheritdoc + */ + public function beforeRun() { - if(Yii::$app->user->isGuest) { - return ''; + if (!parent::beforeRun()) { + return false; + } + + if (Yii::$app->user->isGuest) { + return false; } - if($this->container instanceof User && !Yii::$app->user->getIdentity()->moduleManager->isEnabled('calendar')) { + if ($this->container instanceof User) { + return ContentContainerModuleManager::getDefaultState(User::class, 'calendar') !== ContentContainerModuleState::STATE_NOT_AVAILABLE; + } + + if ($this->container instanceof Space) { + return ContentContainerModuleManager::getDefaultState(Space::class, 'calendar') !== ContentContainerModuleState::STATE_NOT_AVAILABLE; + } + + return true; + } + + /** + * @inheritdoc + */ + public function run() + { + if ($this->container instanceof User && !Yii::$app->user->getIdentity()->moduleManager->isEnabled('calendar')) { return ModalButton::defaultType()->load(Url::toEnableModuleOnProfileConfig())->icon('fa-cog')->visible($this->canConfigure()); } @@ -52,22 +77,17 @@ private function getConfigUrl() { $menu = new ContainerConfigMenu(); $first = $menu->getFirstVisibleItem(); - if(!$first) { - return ''; - } - return $first['url']; + return $first ? $first['url'] : ''; } - public function canConfigure() + public function canConfigure(): bool { - if($this->container instanceof Space) { + if ($this->container instanceof Space) { $menu = new ContainerConfigMenu(); return !empty($menu->getFirstVisibleItem()); } else { return $this->container->isCurrentUser(); } } - - }