silverstripe-framework/view/GenericTemplateGlobalProvider.php
Sam Minnee 1f7fc1f76a FIX Remove instances of lines longer than 120c
The entire framework repo (with the exception of system-generated files) has been amended to respect the 120c line-length limit.  This is in preparation for the enforcement of this rule with PHP_CodeSniffer.
2012-09-30 17:18:13 +13:00

56 lines
1.3 KiB
PHP

<?php
class GenericTemplateGlobalProvider implements TemplateGlobalProvider {
public static function get_template_global_variables() {
return array(
'ModulePath',
'List' => 'getDataList'
);
}
/**
* @var array Module paths
*/
public static $modules = array(
'framework' => FRAMEWORK_DIR,
'frameworkadmin' => FRAMEWORK_ADMIN_DIR,
'thirdparty' => THIRDPARTY_DIR,
'assets' => ASSETS_DIR
);
/**
* Given some pre-defined modules, return the filesystem path of the module.
* @param string $name Name of module to find path of
* @return string
*/
public static function ModulePath($name) {
if(isset(self::$modules[$name])) {
return self::$modules[$name];
} else {
throw new InvalidArgumentException(sprintf('%s is not a supported argument. Possible values: %s', $name,
implode(', ', self::$modules)));
}
}
/**
* This allows templates to create a new `DataList` from a known
* DataObject class name, and call methods such as aggregates.
*
* The common use case is for partial caching:
* <code>
* <% cached List(Member).max(LastEdited) %>
* loop members here
* <% end_cached %>
* </code>
*
* @return DataList
*/
public static function getDataList($className) {
$list = new DataList($className);
$list->setDataModel(DataModel::inst());
return $list;
}
}