Skip to content

Commit

Permalink
Merge branch '4.13' of https://github.com/craftcms/cms into 5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Oct 23, 2024
2 parents 1a4ac19 + 9f9e61c commit 8a317b8
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
### Administration
- All relation fields can now be selected as field layouts’ thumbnail providers. ([#15651](https://github.com/craftcms/cms/discussions/15651))
- Added the “Markdown” field layout UI element type. ([#15674](https://github.com/craftcms/cms/pull/15674), [#15664](https://github.com/craftcms/cms/discussions/15664))
- Added the “Language” element condition rule. ([#15952](https://github.com/craftcms/cms/discussions/15952))
- The Sections index table can now be sorted by Name, Handle, and Type. ([#15936](https://github.com/craftcms/cms/pull/15936))
- Sections are no longer required to have unique names. ([#9829](https://github.com/craftcms/cms/discussions/9829))
- Customize Sources modals now display native sources’ handles, when known.
Expand Down Expand Up @@ -47,7 +48,6 @@
- Added `craft\filters\BasicHttpAuthLogin`. ([#15720](https://github.com/craftcms/cms/pull/15720))
- Added `craft\filters\BasicHttpAuthStatic`. ([#15720](https://github.com/craftcms/cms/pull/15720))
- Added `craft\filters\ConditionalFilterTrait`. ([#15948](https://github.com/craftcms/cms/pull/15948))
- Added `craft\filters\SiteFilterTrait::$enabled`. ([#15720](https://github.com/craftcms/cms/pull/15720))
- Added `craft\filters\UtilityAccess`.
- Added `craft\helpers\Console::indent()`.
- Added `craft\helpers\Console::indentStr()`.
Expand Down
1 change: 1 addition & 0 deletions src/elements/conditions/ElementCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ protected function selectableConditionRules(): array

if (Craft::$app->getIsMultiSite() && (!$elementType || $elementType::isLocalized())) {
$types[] = SiteConditionRule::class;
$types[] = LanguageConditionRule::class;

if (count(Craft::$app->getSites()->getAllGroups()) > 1) {
$types[] = SiteGroupConditionRule::class;
Expand Down
63 changes: 63 additions & 0 deletions src/elements/conditions/LanguageConditionRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace craft\elements\conditions;

use Craft;
use craft\base\conditions\BaseMultiSelectConditionRule;
use craft\base\ElementInterface;
use craft\elements\db\ElementQueryInterface;
use craft\helpers\ArrayHelper;
use craft\i18n\Locale;

/**
* Site condition rule.
*
* @author Pixel & Tonic, Inc. <[email protected]>
* @since 5.5.0
*/
class LanguageConditionRule extends BaseMultiSelectConditionRule implements ElementConditionRuleInterface
{
/**
* @inheritdoc
*/
public function getLabel(): string
{
return Craft::t('app', 'Language');
}

/**
* @inheritdoc
*/
public function getExclusiveQueryParams(): array
{
return ['site', 'siteId'];
}

/**
* @inheritdoc
*/
protected function options(): array
{
return ArrayHelper::map(
Craft::$app->getI18n()->getSiteLocales(),
fn(Locale $locale) => $locale->id,
fn(Locale $locale) => $locale->getDisplayName(Craft::$app->language),
);
}

/**
* @inheritdoc
*/
public function modifyQuery(ElementQueryInterface $query): void
{
$query->language($this->paramValue());
}

/**
* @inheritdoc
*/
public function matchElement(ElementInterface $element): bool
{
return $this->matchValue($element->getLanguage());
}
}

0 comments on commit 8a317b8

Please sign in to comment.