Skip to content

Commit

Permalink
Element and Query behaviors were not getting set due to new Craft CMS…
Browse files Browse the repository at this point in the history
… register behaviors event
  • Loading branch information
nateiler committed Apr 30, 2018
1 parent ad17436 commit 2be1242
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Changelog
=========
## Unreleased
### Fixed
- Element and Query behaviors were not getting set due to new Craft CMS register behaviors event.

## 1.0.0-rc.6 - 2018-04-28
### Fixed
Expand Down
26 changes: 9 additions & 17 deletions src/Organizations.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use craft\elements\db\UserQuery;
use craft\elements\User;
use craft\events\CancelableEvent;
use craft\events\DefineBehaviorsEvent;
use craft\events\RegisterComponentTypesEvent;
use craft\events\RegisterElementSourcesEvent;
use craft\events\RegisterUrlRulesEvent;
Expand Down Expand Up @@ -69,13 +70,9 @@ function (RegisterComponentTypesEvent $event) {
// User Query (attach behavior)
Event::on(
UserQuery::class,
UserQuery::EVENT_INIT,
function (Event $e) {
/** @var UserQuery $query */
$query = $e->sender;
$query->attachBehaviors([
'organization' => OrganizationAttributesToUserQueryBehavior::class
]);
UserQuery::EVENT_DEFINE_BEHAVIORS,
function (DefineBehaviorsEvent $e) {
$e->behaviors['organization'] = OrganizationAttributesToUserQueryBehavior::class;
}
);

Expand All @@ -94,18 +91,13 @@ function (CancelableEvent $e) {
}
);

// User Query (attach behavior)
// User (attach behavior)
Event::on(
User::class,
User::EVENT_INIT,
function (Event $e) {
/** @var User $user */
$user = $e->sender;

$user->attachBehaviors([
'organizations' => UserOrganizationsBehavior::class,
'types' => UserTypesBehavior::class
]);
User::EVENT_DEFINE_BEHAVIORS,
function (DefineBehaviorsEvent $e) {
$e->behaviors['organizations'] = UserOrganizationsBehavior::class;
$e->behaviors['types'] = UserTypesBehavior::class;
}
);

Expand Down

0 comments on commit 2be1242

Please sign in to comment.