Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH Use SearchableMultiDropdownField to select Members #2906

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions code/Model/SiteTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use SilverStripe\Forms\ListboxField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\OptionsetField;
use SilverStripe\Forms\SearchableMultiDropdownField;
use SilverStripe\Forms\Tab;
use SilverStripe\Forms\TabSet;
use SilverStripe\Forms\TextareaField;
Expand Down Expand Up @@ -2256,16 +2257,6 @@ public function getSettingsFields()
$viewAllGroupsMap = $mapFn(Permission::get_groups_by_permission(['SITETREE_VIEW_ALL', 'ADMIN']));
$editAllGroupsMap = $mapFn(Permission::get_groups_by_permission(['SITETREE_EDIT_ALL', 'ADMIN']));

// $membersMap is limited to 100 records specifically so that it does not crash the front-end
// if the website has a large number of Members, which is likely to happen if the website also
// uses the Member table for non-cms public users
// This limit should be removed if the ListboxField front-end component is switched out or
// modified so that it does not load all users at once and instead uses XHR to fetch a subset
// of users based on what the user types in
$membersMap = Member::get()
->limit(100)
->map('ID', 'Name');

$fields = new FieldList(
$rootTab = new TabSet(
"Root",
Expand Down Expand Up @@ -2296,11 +2287,13 @@ public function getSettingsFields()
_t(__CLASS__.'.VIEWERGROUPS', "Viewer Groups"),
Group::class
),
$viewerMembersField = ListboxField::create(
$viewerMembersField = SearchableMultiDropdownField::create(
"ViewerMembers",
_t(__CLASS__.'.VIEWERMEMBERS', "Viewer Users"),
$membersMap,
),
Member::get(),
)
->setIsLazyLoaded(true)
->setUseSearchContext(true),
$editorsOptionsField = new OptionsetField(
"CanEditType",
_t(__CLASS__.'.EDITHEADER', "Who can edit this page?")
Expand All @@ -2310,11 +2303,13 @@ public function getSettingsFields()
_t(__CLASS__.'.EDITORGROUPS', "Editor Groups"),
Group::class
),
$editorMembersField = ListboxField::create(
$editorMembersField = SearchableMultiDropdownField::create(
"EditorMembers",
_t(__CLASS__.'.EDITORMEMBERS', "Editor Users"),
$membersMap
Member::get()
)
->setIsLazyLoaded(true)
->setUseSearchContext(true)
)
)
);
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
],
"require": {
"php": "^8.1",
"silverstripe/admin": "^2",
"silverstripe/admin": "^2.2",
"silverstripe/campaign-admin": "^2",
"silverstripe/framework": "^5.1",
"silverstripe/framework": "^5.2",
"silverstripe/reports": "^5",
"silverstripe/siteconfig": "^5",
"silverstripe/versioned": "^2",
Expand Down