Skip to content

Commit

Permalink
ENH Use SearchableMultiDropdownField to select Members
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Dec 8, 2023
1 parent 221b698 commit d9b39ee
Showing 1 changed file with 10 additions and 15 deletions.
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

0 comments on commit d9b39ee

Please sign in to comment.