Nico Knoll Posted September 28, 2014 Share Posted September 28, 2014 Hey, I really spend a lot of time to figure out how to add additional options to a config page (which are generated with the function "getConfigInputfields"). I use an autoload module for this, At first we need to create the module: <?php class ExampleModule extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'ExampleModule', 'summary' => 'Bla bla', 'version' => 1, 'autoload' => true ); } // the rest of the code should be here } ?> Then we add the init function to it which includes a hook into the config page page we want to extend. In my case it is the option page of the InputfieldDatetime: public function init() { $this->addHook('InputfieldDatetime::getConfigInputfields', $this, 'addConfig'); } The last step is of course the "addConfig" function: public function addConfig(HookEvent $event) { // get the field instance used by the config form $field = $event->object; // TRICKY PART: use it's name to get it's saved values $data = $this->fields->get($field->name)->data; // add a new field with the saved value to the form $fields = $event->return; $field = $this->modules->get("InputfieldCheckbox"); $field->name = "useSimpleDate"; $field->label = "Use \"Simple Date\"?"; $field->checked = ((@$data['useSimpleDate']) ?: 0); $fields->add($field); // return the new config form $event->return = $fields; } The only really tricky part is to get the value. In this case it works like this. In other cases you may have to get the modules config. 6 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now