-
Notifications
You must be signed in to change notification settings - Fork 638
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16174 from craftcms/feature/cms-1349-track-user-s…
…ite-affiliations Track user/site affiliations
- Loading branch information
Showing
18 changed files
with
507 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/elements/conditions/users/AffiliatedSiteConditionRule.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace craft\elements\conditions\users; | ||
|
||
use Craft; | ||
use craft\base\conditions\BaseMultiSelectConditionRule; | ||
use craft\base\ElementInterface; | ||
use craft\elements\conditions\ElementConditionRuleInterface; | ||
use craft\elements\db\ElementQueryInterface; | ||
use craft\elements\db\UserQuery; | ||
use craft\elements\User; | ||
use craft\models\Site; | ||
|
||
/** | ||
* Site condition rule. | ||
* | ||
* @author Pixel & Tonic, Inc. <[email protected]> | ||
* @since 5.6.0 | ||
*/ | ||
class AffiliatedSiteConditionRule extends BaseMultiSelectConditionRule implements ElementConditionRuleInterface | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getLabel(): string | ||
{ | ||
return Craft::t('app', 'Affiliated Site'); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getExclusiveQueryParams(): array | ||
{ | ||
return ['affiliatedSite', 'affiliatedSiteId']; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function options(): array | ||
{ | ||
return array_map(fn(Site $site) => [ | ||
'label' => $site->getUiLabel(), | ||
'value' => $site->uid, | ||
], Craft::$app->getSites()->getAllSites()); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function modifyQuery(ElementQueryInterface $query): void | ||
{ | ||
$sites = Craft::$app->getSites(); | ||
/** @var UserQuery $query */ | ||
$query->affiliatedSiteId($this->paramValue(fn($uid) => $sites->getSiteByUid($uid, true)->id ?? null)); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function matchElement(ElementInterface $element): bool | ||
{ | ||
/** @var User $element */ | ||
return $this->matchValue($element->getAffiliatedSite()?->uid); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.