From 8ee7d3f5ae0e56b1e332ad18a8e6162365e4e4d7 Mon Sep 17 00:00:00 2001 From: Priit Perna Date: Wed, 17 May 2017 13:00:40 +0300 Subject: [PATCH 1/2] Added scope support to the Relation formwidget --- modules/backend/formwidgets/Relation.php | 11 +++++++++++ 1 file changed, 11 insertions(+) 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']) From 2b3b6ece466129cf4f2faab06538a297a348bf0f Mon Sep 17 00:00:00 2001 From: Priit Perna Date: Thu, 18 May 2017 15:16:42 +0300 Subject: [PATCH 2/2] Made checkbox quick selection configurable With this change the following configuration will show the quick selection links: "quickselect" => true --- .../backend/widgets/form/partials/_field_checkboxlist.htm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 @@
- + : , - + +