protected static $defaultConfig = array(
// example with just one option
'prettySetting' => array(
// the label for the form
'label' => 'Pretty Setting',
// the default value
'value' => 'I am pretty',
// optional, defaults to 'InputfieldText'
'inputfieldType' => 'InputfieldText'
),
// example with multiple options
'awesomeSetting' => array(
// the label for the form
'label' => 'Awesome Setting',
// the default value
'value' => 2,
// optional, defaults to 'InputfieldRadios'
'inputfieldType' => 'InputfieldRadios',
// each key is for the input label, each value will be saved if selected
'options' => array(
'Option 1' => 1,
'Option 2' => 2,
'Option 3' => 3
),
// set any additional attribute to the input field
'attributes' => array(
'optionColumns' => 1
)
)
);
public function __construct() {
PWModuleConfigHelper::apply($this, self::$defaultConfig);
}
public static function getPWModuleConfigInputfields(array $data) {
return PWModuleConfigHelper::renderForm($data, self::$defaultConfig);
}
$this->awesomeSetting;
If you're using this in your module and you don't want it to clash with other modules using it, you have the following options to include it:
- use
spl_autoload_register
to autoload it, so it only gets loaded once - only include the class if it has not been loaded yet, via
class_exists('PWModuleConfigHelper')
- Option 1 and 2 require the class not to change (updates etc.) so the following options are more stable:
- Namespace to class via renaming it, prefixing it with you module's name
- Namespace it with PHP namespaces
- I could make a module out of this but this might be overkill
- v0.0.1 initial version
This software is licensed under The MIT License (MIT)