Skip to content

Commit

Permalink
Merge pull request #2 from Alxmerino/feature/craft5-support
Browse files Browse the repository at this point in the history
Add support for Craft5
  • Loading branch information
Alxmerino authored Oct 4, 2024
2 parents dcf4c8a + cb12b91 commit 230273a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
27 changes: 23 additions & 4 deletions src/LockedEntries.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit 230273a

Please sign in to comment.