Created
January 20, 2017 00:43
-
-
Save kferran/16ac5bedd7b9fd4e6ad4eee316c5f4fd to your computer and use it in GitHub Desktop.
Processwire module starter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class YourModule extends WireData implements Module, ConfigurableModule { | |
public static function getModuleInfo() { | |
return array('title' => 'Your Module', 'version' => 1); | |
} | |
const defaultValue = 'renobird'; | |
public function __construct() { | |
$this->set('yourname', self::defaultValue); // set default value in construct | |
} | |
public function init() { | |
// while you need this function here, you don't have to do anything with it | |
// note that $this->yourname will already be populated with the configured | |
// value (if different from default) and ready to use if you want it | |
} | |
public function execute() { | |
// will return configured value, or 'renobird' if not yet configured | |
return $this->yourname; | |
} | |
public static function getModuleConfigInputfields(array $data) { | |
// if yourname isn't yet in $data, put our default value in there | |
if(!isset($data['yourname'])) $data['yourname'] = self::defaultValue; | |
$form = new InputfieldWrapper(); | |
$f = wire('modules')->get('InputfieldText'); | |
$f->name = 'yourname'; | |
$f->label = 'Enter your name'; | |
$f->value = $data['yourname']; | |
$form->add($f); | |
return $form; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment