Permalink
Browse files

Several updates to modules system. The Module interface no longer req…

…uires init(). It also lets you use a YourModuleName.info.php or YourModuleName.info.json file instead of a getModuleInfo() method, if you prefer to keep your info separate from the module itself. See /wire/core/Module.php for more details about that. In addition, all modules now support the 'permission' property for their module info. When specified, the given permission name will be required of the user before PW will instantiate the module. Lastly, a new 'permissions' property was added to the module info. It is an associative array of ('permission-name' => 'description'). When given in module info (like getModuleInfo method), PW will automatically create and install the given permissions when the module is installed, and automatically remove them when the module is uninstalled. There have also been some other tweaks and adjustments in this commit.
  • Loading branch information...
ryancramerdesign committed Jun 4, 2014
1 parent 0e26f7a commit 2c0762d1f346a3f01171b4f65fa97242f17fd916
View
@@ -121,6 +121,7 @@
'autoRotation' => true, // automatically correct orientation?
'sharpening' => 'soft', // sharpening: none | soft | medium | strong
'quality' => 90, // quality: 1-100 where higher is better but bigger
'defaultGamma' => 2.0, // defaultGamma: 0.5 to 4.0 or -1 to disable gamma correction (default=2.0)
);
/**
View
@@ -17,14 +17,14 @@
/**
* Get information about this module
*
*/
public static function getModuleInfo() {
return array(
'title' => '',
'version' => 1,
'summary' => '',
);
}
*/
/**
* Per Module interface, this template method is called when all system classes are loaded and ready for API usage
View
@@ -520,7 +520,7 @@ function wireRelativeTimeStr($ts, $abbreviate = false) {
$lengths = array("60","60","24","7","4.35","12","10");
$now = time();
if(!ctype_digit("$ts")) $ts = strtotime($ts);
if(empty($ts)) return "Bad date";
if(empty($ts)) return "";
// is it future date or past date
if($now > $ts) {
View
@@ -129,14 +129,14 @@ public function __construct() {
/**
* Get information about this module
*
*/
public static function getModuleInfo() {
return array(
'title' => '',
'version' => 1,
'summary' => '',
);
}
*/
/**
* Per the Module interface, init() is called when the system is ready for API usage
@@ -157,8 +157,8 @@ public function init() {
*/
public function hookRender($event) {
$class = $this->className();
$info = $this->getModuleInfo();
$version = (int) $info['version'];
$info = $this->wire('modules')->getModuleInfo($this, array('verbose' => false));
$version = (int) isset($info['version']) ? $info['version'] : 0;
if(is_file($this->config->paths->$class . "$class.css")) $this->config->styles->add($this->config->urls->$class . "$class.css?v=$version");
if(is_file($this->config->paths->$class . "$class.js")) $this->config->scripts->add($this->config->urls->$class . "$class.js?v=$version");
}
View
@@ -65,12 +65,20 @@ public function setConfigData(array $data);
/**
* Return an array of module information
*
* This array of information may be returned in 1 of 3 ways:
* 1. By a static method in your module class named getModuleInfo().
* 2. By a YourModuleClass.info.php file that populates an $info array.
* 3. By a YourModuleClass.info.json file that contains an info object.
*
* Each of these are demonstrated below:
*
* Example:
* 1. Using a static getModuleInfo method:
* ---------------------------------------
*
* public static function getModuleInfo() {
* return array(
* 'title' => 'Your Module's Title',
* 'title' => 'Your Module Title',
* 'version' => 100,
* 'author' => 'Ryan Cramer',
* 'summary' => 'Description of what this module does and who made it.',
@@ -82,6 +90,32 @@ public function setConfigData(array $data);
* );
* }
*
*
* 2. Using a YourModuleClass.info.php file:
* -----------------------------------------
*
* Your file should populate an $info variable with an array exactly like described for #1 above, i.e.
*
* $info = array(
* 'title' => 'Your Module Title',
* 'version' => 100,
* // and so on, like the static version above
* );
*
* 3. Using a YourModuleClass.info.json file:
* ------------------------------------------
*
* Your JSON file should contain nothing but an object/map of the module info:
*
* {
* title: 'Your Module title',
* version: '100,
* // and so on
* }
*
*
* More details about the data your module info should return
* ----------------------------------------------------------
*
* The retured array is associative with the following fields. Fields bulleted with a "+" are required and
* fields bulleted with a "-" are optional, and fields bulleted with a "*" may be optional (see details):
@@ -115,11 +149,16 @@ public function setConfigData(array $data);
* If you don't provide an isAutoload() method, then you should provide this property here.
* - permanent: boolean, for core only. True only if the module is permanent and uninstallable.
* This is true only of PW core modules, so leave this out elsewhere.
* - permission: name of permission required of a user before PW will instantiate the module.
* Note that PW will not install this permission if it doesn't yet exist. To have it installed automatically,
* see the 'permissions' option below this.
* - permissions: array of permissions that PW will install (and uninstall) automatically.
* Permissions should be in the format: array('permission-name' => 'Permission description')
*
* @return array
*
*/
public static function getModuleInfo();
*/
/**
* Method to initialize the module.
@@ -130,8 +169,8 @@ public static function getModuleInfo();
* bootstrap process. This is before PW has started retrieving or rendering a page. If you need to have the
* API ready with the $page ready as well, then see the ready() method below this one.
*
*/
public function init();
*/
/**
* Method called when API is fully ready and the $page is determined and set, but before a page is rendered.
View
@@ -41,8 +41,8 @@ public static function getModuleInfo() {
*/
public function init() {
$class = $this->className();
$info = $this->getModuleInfo();
$version = (int) $info['version'];
$info = $this->wire('modules')->getModuleInfo($this, array('verbose' => false));
$version = (int) isset($info['version']) ? $info['version'] : 0;
if(is_file($this->config->paths->$class . "$class.css")) $this->config->styles->add($this->config->urls->$class . "$class.css?v=$version");
if(is_file($this->config->paths->$class . "$class.js")) $this->config->scripts->add($this->config->urls->$class . "$class.js?v=$version");
}
Oops, something went wrong.

0 comments on commit 2c0762d

Please sign in to comment.