Skip to content

Commit

Permalink
fix: expose ShowInSearch field in access UI
Browse files Browse the repository at this point in the history
Upgrading from SilverStripe 3 to SilverStripe 5 it appears the ShowInSearch field is no longer displayed in the UI.

The File record still contains this data and the implementation was to match Page instances which contain the 'Show in search' option to CMS editors.
  • Loading branch information
wilr committed Nov 19, 2023
1 parent 4ab0da2 commit fd811f9
Showing 1 changed file with 32 additions and 18 deletions.
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'))
->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

0 comments on commit fd811f9

Please sign in to comment.