Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
easy settings class
y2kbg
New
Is there anyone who has the need or want for a class that will greatly simplify the process of adding admin settings to an extension?
instead of a hundred lines of code to make an admin area, just include easysettings.php and 2 other lines of code and then 1 for each setting you want to add?
I would make this if anyone wants it.
instead of a hundred lines of code to make an admin area, just include easysettings.php and 2 other lines of code and then 1 for each setting you want to add?
I would make this if anyone wants it.
0
This discussion has been closed.
Comments
I would love that
ok heres a question, should I make it an extension that has to be enabled and then all extensions that use this Would require this extension? I could also use this dependence to create continuity between extensions. This was noted to be desire by someone who said they they wanted ALL extension option to be under the 'Extension Options' category.
I hope to make this work well and efficient so that it will be the (Vanilla) Industry standard for saving settings. Any tips from some gurus on how to accomplish this.
ok I have already started so anticipate, but don't hold your breath.
Could you give some examples of both options you're asking about as I don't completely understand what you're asking.
$Context->Dictionary['Friends_AllowGuests_Description'] = ' Allow Guest to View People Page'; $Context->Dictionary['Friends_Request_Description'] = ' Uncheck to Disable Request'; $EasySettingsForm->ExtensionName = "Friends"; $EasySettingsForm->AddEasySetting('AllowGuests'); $EasySettingsForm->AddEasySetting('Request');
or
$EasySettingsForm->ExtensionName = "Friends"; $EasySettingsForm->AddEasySetting('AllowGuests, ' Allow Guest to View People Page''; $EasySettingsForm->AddEasySetting('Request', ' Uncheck to Disable Request';
so i got kinda far but i don't really know if I am on the right track!
Here is a preview of how to add a settings page:
if ($Context->SelfUrl == "settings.php" && $Context->Session->User->Permission('PERMISSION_CHANGE_APPLICATION_SETTINGS') && array_key_exists('Friends_Settings_V', $Configuration)) { include 'php/easysetting.php'; $EasySettingsForm = $Context->ObjectFactory->NewContextObject($Context,'EasySettingsForm'); $EasySettingsForm->ExtensionName = 'Friends'; $EasySettingsForm->AddAnEasySetting('AllowGuests'); $EasySettingsForm->AddAnEasySetting('Request') $EasySettingsForm->AddAnEasySetting('PeoplesTab') $EasySettingsForm->AddEasySettingHeader('Select the Columns you would like to display:') $EasySettingsForm->AddAnEasySetting('NameCell') $EasySettingsForm->AddAnEasySetting('DateRegistered') $EasySettingsForm->AddAnEasySetting('MemberIcons') $EasySettingsForm->AddAnEasySetting('VisitCount') $EasySettingsForm->AddAnEasySetting('Email') $EasySettingsForm->AddAnEasySetting('PostCount') $EasySettingsForm->AddAnEasySetting('Role') $Page->AddRenderControl($EasySettingsForm,$Configuration["CONTROL_POSITION_BODY_ITEM"] + 1); $Panel->AddList('Extension Options', 10); $Panel->AddListItem('Extension Options',$ExtensionName.' Settings,GetUrl($Context->Configuration, 'settings.php', '', '', '', '', 'PostBackAction='.$ExtensionName)); }
Does this look like I am using the object created by the object factory correctly?
As of right now it only creates checkboxs as those are the only kind I know how to do at the moment, could someone enlighten me as how to do this correctly? I need some help on this and if I don't it will delay the release of Friends 2.0.
Here is the class:
<?php class EasySettingsForm extends PostBackControl { var $ConfigurationManager; var $ExtensionName; var $EasySettingDisplay = ''; var $EasySettingGet; function AddAnEasySetting($NewSetting){ $EasySettingDisplay .= GetDynamicCheckBox($ExtensionName.'_'.$NewSetting, 1,$this->ConfigurationManager->GetSetting($ExtensionName.'_'.$NewSetting),'',$this->Context->GetDefinition($ExtensionName.'_'.$NewSetting.'_Description')); } function AddEasySettingHeader($Header){ $EasySettingDisplay .= '</br><H2>'.$Header.'</H2>' } function EasySettingsForm(&$Context) { $this->Name = $ExtensionName.'SettingsForm'; $this->ValidActions = array($ExtensionName, 'Process'.$ExtensionName); $this->Constructor($Context); if (!$this->Context->Session->User->Permission('PERMISSION_CHANGE_APPLICATION_SETTINGS')) { $this->IsPostBack = 0; } elseif( $this->IsPostBack ) { $SettingsFile = $this->Context->Configuration['APPLICATION_PATH'].'conf/settings.php'; $this->ConfigurationManager = $this->Context->ObjectFactory->NewContextObject($this->Context,'ConfigurationManager'); if ($this->PostBackAction == 'Process'.$ExtensionName) { $this->ConfigurationManager->GetSettingsFromForm($SettingsFile); // Forces checkbox result and saves all submitted fields $this->ConfigurationManager->DefineSetting('Friends_AllowGuests',ForceIncomingBool('Friends_AllowGuests', 0), 0); $this->ConfigurationManager->DefineSetting('Friends_Request',ForceIncomingBool('Friends_Request', 0), 0); $this->ConfigurationManager->DefineSetting('Friends_NameCell',ForceIncomingBool('Friends_NameCell', 0), 0); $this->ConfigurationManager->DefineSetting('Friends_DateRegistered',ForceIncomingBool('Friends_DateRegistered', 0), 0); $this->ConfigurationManager->DefineSetting('Friends_MemberIcons',ForceIncomingBool('Friends_MemberIcons', 0), 0); $this->ConfigurationManager->DefineSetting('Friends_VisitCount',ForceIncomingBool('Friends_VisitCount', 0), 0); $this->ConfigurationManager->DefineSetting('Friends_Email',ForceIncomingBool('Friends_Email', 0), 0); $this->ConfigurationManager->DefineSetting('Friends_PostCount',ForceIncomingBool('Friends_PostCount', 0), 0); $this->ConfigurationManager->DefineSetting('Friends_Role',ForceIncomingBool('Friends_Role', 0), 0); $this->ConfigurationManager->DefineSetting('Friends_PeoplesTab',ForceIncomingBool('Friends_PeoplesTab', 0), 0); if($this->ConfigurationManager->SaveSettingsToFile($SettingsFile)) { header('location:'.GetUrl($this->Context->Configuration, 'settings.php', '', '', '', '', 'PostBackAction='.$ExtensionName.'Success=1')); } else { $this->PostBackAction = $ExtensionName; } } } $this->CallDelegate('Constructor'); } function Render() { if ($this->IsPostBack) { $this->CallDelegate('PreRender'); $this->PostBackParams->Clear(); if ($this->PostBackAction == $ExtensionName) { $this->PostBackParams->Set('PostBackAction', "Process".$ExtensionName); echo ' <div id="Form" class="Account '.$ExtensionName.'Settings"> <fieldset> <legend>'.$ExtensionName.' Settings</legend> '.$this->Get_Warnings().' '.$this->Get_PostBackForm('frm'.$ExtensionName).' <H2>'.$ExtensionName.' Options:</H2>'.$EasySettingDisplay).' <div class="Submit"> <input type="submit" name="btnSave" value="'.$this->Context->GetDefinition('Save').'" class="Button SubmitButton" /> <a href="'.GetUrl($this->Context->Configuration,$this->Context->SelfUrl).'"class="CancelButton">'.$this->Context->GetDefinition('Cancel').'</a> </div> </form> </fieldset> </div>'; } } $this->CallDelegate('PostRender'); } } ?>
I am new to classes and this was meant to be a learning experience. So if a "Great and Power One(coder)" could help me out it would be appreciated. I haven't even test this code yet because I don't think it is even ready to be tested.
Fatal error: Call to a member function GetSetting() on a non-object in C:\Documents and Settings\Kaz\Desktop\server\mysite\extensions\Friends\php\easysetting.php on line 8
line 8 is the middle line:
function AddAnEasySetting($NewSetting){ $EasySettingDisplay .= GetDynamicCheckBox($ExtensionName.'_'.$NewSetting, 1,$this->ConfigurationManager->GetSetting($ExtensionName.'_'.$NewSetting),'',$this->Context->GetDefinition($ExtensionName.'_'.$NewSetting.'_Description')); }
is how to add one. it has a lot of settings so it looks long. I also added the feature to add heading to the page such.