diff --git a/composer.json b/composer.json index 286ea14..a37bd6e 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ }, "require": { "php": ">=8.0.2", - "craftcms/cms": "^4.0.0" + "craftcms/cms": "^4.0.0|^5.0.0" }, "require-dev": { "craftcms/ecs": "dev-main", diff --git a/src/LockedEntries.php b/src/LockedEntries.php index b918f6e..a33d5c6 100644 --- a/src/LockedEntries.php +++ b/src/LockedEntries.php @@ -8,15 +8,17 @@ use craft\base\Element; use craft\base\Model; use craft\base\Plugin; -use craft\elements\db\ElementQuery; use craft\elements\Entry; +use craft\elements\db\ElementQuery; use craft\events\AuthorizationCheckEvent; use craft\events\CancelableEvent; use craft\events\DefineHtmlEvent; use craft\events\ModelEvent; +use craft\events\UserGroupEvent; use craft\helpers\Cp; use craft\helpers\Html; use craft\services\Elements; +use craft\services\UserGroups; use yii\base\Event; /** @@ -160,9 +162,7 @@ function(AuthorizationCheckEvent $event) { } ); - /** - * Modify query to exclude entries that are 'locked' - */ + // Modify query to exclude entries that are 'locked' Event::on( ElementQuery::class, ElementQuery::EVENT_BEFORE_PREPARE, @@ -186,6 +186,25 @@ function(CancelableEvent $event) { } } ); + + // Reset Plugin `userGroup` settings if the selected group was deleted + Event::on( + UserGroups::class, + UserGroups::EVENT_BEFORE_APPLY_GROUP_DELETE, + function (UserGroupEvent $e) { + if ($e->userGroup->id == (int)$this->getSettings()->userGroup) { + $settings = array_merge( + $this->getSettings()->toArray(), + ['userGroup' => ''] + ); + + // Emmit message if saved successfully + if (Craft::$app->getPlugins()->savePluginSettings($this, $settings)) { + Craft::$app->getSession()->setSuccess('Locked Entries plugin settings updated!', $settings); + } + } + } + ); } protected function createSettingsModel(): ?Model