From fd811f9567193036fb462be9cba4e49d4e360048 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Mon, 11 Sep 2023 15:48:39 +1200 Subject: [PATCH] fix: expose ShowInSearch field in access UI 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. --- code/Forms/AssetFormFactory.php | 50 +++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/code/Forms/AssetFormFactory.php b/code/Forms/AssetFormFactory.php index dbb052556..95528faae 100644 --- a/code/Forms/AssetFormFactory.php +++ b/code/Forms/AssetFormFactory.php @@ -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; @@ -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' => '', @@ -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; } @@ -358,11 +370,11 @@ 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 @@ -370,37 +382,39 @@ protected function getFormFieldSecurityTab($record, $context = []) 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()