Skip to content

Instantly share code, notes, and snippets.

@yckart
Last active August 8, 2016 21:05
Show Gist options
  • Save yckart/7040320 to your computer and use it in GitHub Desktop.
Save yckart/7040320 to your computer and use it in GitHub Desktop.
ModuleBoilerplate.module for ProcessWire
<?php
/**
* A simple module-boilerplate
*
* @see https://gist.github.com/yckart/7040320
* @see http://wiki.processwire.com/index.php/Module_Creation
*/
class ModuleBoilerplate extends WireData implements Module, ConfigurableModule {
/**
* getModuleInfo is a module required by all modules to tell ProcessWire about them
*
* @return array
*
*/
public static function getModuleInfo() {
return array(
'title' => 'Module Boilerplate',
'summary' => 'Foo is not equal to bar.',
'href' => 'http://domain.tld',
'version' => 1,
'singular' => true,
'autoload' => true
);
}
/**
* getDefaultData
*
* @return array
*
*/
public static function getDefaultData() {
return array(
'key' => 'value'
);
}
public function __construct() {
foreach(self::getDefaultData() as $key => $value) {
$this->$key = $value;
}
}
/**
* Initialize the module
*
* ProcessWire calls this when the module is loaded. For 'autoload' modules, this will be called
* when ProcessWire's API is ready. As a result, this is a good place to attach hooks.
*
*/
public function init() {
}
/**
* API is ready
*
* When present on an 'autoload' module, ProcessWire will call this function
* when the API is fully ready and the $page API variable has been set.
*
*/
public function ready() {
}
public static function getModuleConfigInputfields(array $data) {
$data = array_merge(self::getDefaultData(), $data);
$modules = wire('modules');
$inputfields = new InputfieldWrapper();
// add some fields
$field = $modules->get('InputfieldText');
$field->name = 'key';
$field->label = 'Whohoo, a sample label';
$field->value = $data['key'];
$inputfields->add($field);
return $inputfields;
}
/**
* Called only when your module is installed
*
* This version creates a new page with this Process module assigned.
*
*/
public function ___install() {
}
/**
* Called only when your module is uninstalled
*
* This should return the site to the same state it was in before the module was installed.
*
*/
public function ___uninstall() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment