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 #1424

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/Forms/AssetFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use SilverStripe\Security\InheritedPermissions;
use SilverStripe\Security\Member;
use SilverStripe\VersionedAdmin\Extensions\FileArchiveExtension;
use SilverStripe\Forms\SearchableMultiDropdownField;

abstract class AssetFormFactory implements FormFactory
{
Expand Down Expand Up @@ -381,16 +382,6 @@ protected function getFormFieldSecurityTab($record, $context = [])
$editorsOptionsField = $viewersOptionsField;
unset($editorsOptionsField[InheritedPermissions::ANYONE]);

// $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');

$tab = Tab::create(
'Permissions',
OptionsetField::create(
Expand All @@ -402,11 +393,13 @@ protected function getFormFieldSecurityTab($record, $context = [])
'ViewerGroups',
_t(__CLASS__ . '.VIEWERGROUPS', 'Viewer Groups')
),
ListboxField::create(
SearchableMultiDropdownField::create(
'ViewerMembers',
_t(__CLASS__ . '.VIEWERMEMBERS', 'Viewer Users'),
$membersMap
),
Member::get()
)
->setIsLazyLoaded(true)
->setUseSearchContext(true),
OptionsetField::create(
"CanEditType",
_t(__CLASS__ . '.EDITHEADER', 'Who can edit this file?')
Expand All @@ -416,11 +409,13 @@ protected function getFormFieldSecurityTab($record, $context = [])
'EditorGroups',
_t(__CLASS__ . '.EDITORGROUPS', 'Editor Groups')
),
ListboxField::create(
SearchableMultiDropdownField::create(
'EditorMembers',
_t(__CLASS__ . '.EDITORMEMBERS', 'Editor Users'),
$membersMap
Member::get()
)
->setIsLazyLoaded(true)
->setUseSearchContext(true)
);

return $tab;
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"license": "BSD-3-Clause",
"require": {
"php": "^8.1",
"silverstripe/framework": "^5.1",
"silverstripe/admin": "^2",
"silverstripe/framework": "^5.2",
"silverstripe/admin": "^2.2",
"silverstripe/graphql": "^5"
},
"require-dev": {
Expand Down