diff --git a/modules/backend/formwidgets/Relation.php b/modules/backend/formwidgets/Relation.php index 6397c7afe..c5f4699e5 100644 --- a/modules/backend/formwidgets/Relation.php +++ b/modules/backend/formwidgets/Relation.php @@ -43,6 +43,11 @@ class Relation extends FormWidgetBase */ public $emptyOption; + /** + * @var string Use a custom scope method for the list query. + */ + public $scope; + // // Object properties // @@ -66,6 +71,7 @@ class Relation extends FormWidgetBase 'nameFrom', 'descriptionFrom', 'emptyOption', + 'scope', ]); if (isset($this->config->select)) { @@ -118,6 +124,10 @@ class Relation extends FormWidgetBase $query->where($relationModel->getKeyName(), '<>', $model->getKey()); } + if ($scopeMethod = $this->scope) { + $query->$scopeMethod($model); + } + // Even though "no constraints" is applied, belongsToMany constrains the query // by joining its pivot table. Remove all joins from the query. $query->getQuery()->getQuery()->joins = []; @@ -139,6 +149,7 @@ class Relation extends FormWidgetBase $result = $query->getQuery()->get(); } + // Some simpler relations can specify a custom local or foreign "other" key, // which can be detected and implemented here automagically. $primaryKeyName = in_array($relationType, ['hasMany', 'belongsTo', 'hasOne']) diff --git a/modules/backend/widgets/form/partials/_field_checkboxlist.htm b/modules/backend/widgets/form/partials/_field_checkboxlist.htm index 569834f10..de60f260d 100644 --- a/modules/backend/widgets/form/partials/_field_checkboxlist.htm +++ b/modules/backend/widgets/form/partials/_field_checkboxlist.htm @@ -3,6 +3,7 @@ $checkedValues = (array) $field->value; $isScrollable = count($fieldOptions) > 10; $readOnly = $this->previewMode || $field->readOnly || $field->disabled; + $quickselectEnabled = $field->getConfig('quickselect'); ?> value): ?> @@ -37,14 +38,15 @@
- + : , - + +