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

fix: expose ShowInSearch field in access UI #1399

Merged
merged 1 commit into from
Nov 19, 2023
Merged
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
50 changes: 32 additions & 18 deletions code/Forms/AssetFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use SilverStripe\Core\Config\Configurable;
use SilverStripe\Core\Extensible;
use SilverStripe\Core\Injector\Injectable;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\FieldGroup;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
Expand Down Expand Up @@ -152,13 +153,13 @@ protected function getSaveAction($record)
{
if ($record && $record->isInDB() && $record->canEdit()) {
/** @var FormAction $action */
$action = FormAction::create('save', _t(__CLASS__.'.SAVE', 'Save'))
$action = FormAction::create('save', _t(__CLASS__ . '.SAVE', 'Save'))
GuySartorelli marked this conversation as resolved.
Show resolved Hide resolved
->setIcon('save')
->setSchemaState([
'data' => [
'pristineTitle' => _t(__CLASS__.'.SAVED', 'Saved'),
'pristineTitle' => _t(__CLASS__ . '.SAVED', 'Saved'),
'pristineIcon' => 'tick',
'dirtyTitle' => _t(__CLASS__.'.SAVE', 'Save'),
'dirtyTitle' => _t(__CLASS__ . '.SAVE', 'Save'),
'dirtyIcon' => 'save',
'pristineClass' => 'btn-outline-primary',
'dirtyClass' => '',
Expand Down Expand Up @@ -303,17 +304,28 @@ protected function getFormFieldDetailsTab($record, $context = [])
/** @var Tab $tab */
$tab = Tab::create(
'Details',
TextField::create('Name', _t(__CLASS__.'.FILENAME', 'Filename')),
TextField::create('Name', _t(__CLASS__ . '.FILENAME', 'Filename')),
$location = TreeDropdownField::create(
'ParentID',
_t(__CLASS__.'.FOLDERLOCATION', 'Location'),
_t(__CLASS__ . '.FOLDERLOCATION', 'Location'),
Folder::class
)
->setShowSelectedPath(true)
);


if (!$record instanceof Folder) {
$tab->push(
CheckboxField::create(
'ShowInSearch',
_t(__CLASS__ . '.SHOWINSEARRCH', 'Show in search?')
)
);
}


$location
->setEmptyString(_t(__CLASS__.'.ROOTNAME', '(Top level)'))
->setEmptyString(_t(__CLASS__ . '.ROOTNAME', '(Top level)'))
->setShowSearch(true);
return $tab;
}
Expand Down Expand Up @@ -358,49 +370,51 @@ protected function getFormFieldSecurityTab($record, $context = [])
{
// Get permissions
$viewersOptionsField = [
InheritedPermissions::INHERIT => _t(__CLASS__.'.INHERIT', 'Inherit from parent folder'),
InheritedPermissions::ANYONE => _t(__CLASS__.'.ANYONE', 'Anyone'),
InheritedPermissions::LOGGED_IN_USERS => _t(__CLASS__.'.LOGGED_IN', 'Logged-in users'),
InheritedPermissions::ONLY_THESE_USERS => _t(__CLASS__.'.ONLY_GROUPS', 'Only these groups (choose from list)'),
InheritedPermissions::ONLY_THESE_MEMBERS => _t(__CLASS__.'.ONLY_MEMBERS', 'Only these users (choose from list)'),
InheritedPermissions::INHERIT => _t(__CLASS__ . '.INHERIT', 'Inherit from parent folder'),
InheritedPermissions::ANYONE => _t(__CLASS__ . '.ANYONE', 'Anyone'),
InheritedPermissions::LOGGED_IN_USERS => _t(__CLASS__ . '.LOGGED_IN', 'Logged-in users'),
InheritedPermissions::ONLY_THESE_USERS => _t(__CLASS__ . '.ONLY_GROUPS', 'Only these groups (choose from list)'),
InheritedPermissions::ONLY_THESE_MEMBERS => _t(__CLASS__ . '.ONLY_MEMBERS', 'Only these users (choose from list)'),
];

// No "Anyone" editors option
$editorsOptionsField = $viewersOptionsField;
unset($editorsOptionsField[InheritedPermissions::ANYONE]);
$membersMap = Member::get()->map('ID', 'Name');

return Tab::create(
$tab = Tab::create(
'Permissions',
OptionsetField::create(
'CanViewType',
_t(__CLASS__.'.ACCESSHEADER', 'Who can view this file?')
_t(__CLASS__ . '.ACCESSHEADER', 'Who can view this file?')
)
->setSource($viewersOptionsField),
TreeMultiselectField::create(
'ViewerGroups',
_t(__CLASS__.'.VIEWERGROUPS', 'Viewer Groups')
_t(__CLASS__ . '.VIEWERGROUPS', 'Viewer Groups')
),
ListboxField::create(
'ViewerMembers',
_t(__CLASS__.'.VIEWERMEMBERS', 'Viewer Users'),
_t(__CLASS__ . '.VIEWERMEMBERS', 'Viewer Users'),
$membersMap
),
OptionsetField::create(
"CanEditType",
_t(__CLASS__.'.EDITHEADER', 'Who can edit this file?')
_t(__CLASS__ . '.EDITHEADER', 'Who can edit this file?')
)
->setSource($editorsOptionsField),
TreeMultiselectField::create(
'EditorGroups',
_t(__CLASS__.'.EDITORGROUPS', 'Editor Groups')
_t(__CLASS__ . '.EDITORGROUPS', 'Editor Groups')
),
ListboxField::create(
'EditorMembers',
_t(__CLASS__.'.EDITORMEMBERS', 'Editor Users'),
_t(__CLASS__ . '.EDITORMEMBERS', 'Editor Users'),
$membersMap
)
);

return $tab;
}

public function getRequiredContext()
Expand Down