2012-04-15 10:48:50 +12:00
|
|
|
<?php
|
2016-06-15 16:03:16 +12:00
|
|
|
|
2016-08-19 10:51:35 +12:00
|
|
|
namespace SilverStripe\View;
|
|
|
|
|
2016-06-15 16:03:16 +12:00
|
|
|
use SilverStripe\ORM\DataList;
|
|
|
|
use SilverStripe\ORM\DataModel;
|
2016-08-19 10:51:35 +12:00
|
|
|
use InvalidArgumentException;
|
|
|
|
|
2016-11-29 12:31:16 +13:00
|
|
|
class GenericTemplateGlobalProvider implements TemplateGlobalProvider
|
|
|
|
{
|
2012-04-15 10:48:50 +12:00
|
|
|
|
2016-11-29 12:31:16 +13:00
|
|
|
public static function get_template_global_variables()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
'ModulePath',
|
|
|
|
'List' => 'getDataList'
|
|
|
|
);
|
|
|
|
}
|
2012-04-15 10:48:50 +12:00
|
|
|
|
2016-11-29 12:31:16 +13:00
|
|
|
/**
|
|
|
|
* @var array Module paths
|
|
|
|
*/
|
|
|
|
public static $modules = array(
|
|
|
|
'framework' => FRAMEWORK_DIR,
|
|
|
|
'frameworkadmin' => FRAMEWORK_ADMIN_DIR,
|
|
|
|
'thirdparty' => THIRDPARTY_DIR,
|
|
|
|
'assets' => ASSETS_DIR
|
|
|
|
);
|
2012-04-15 10:48:50 +12:00
|
|
|
|
2016-11-29 12:31:16 +13:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
2012-05-19 12:55:49 +12:00
|
|
|
|
2016-11-29 12:31:16 +13:00
|
|
|
/**
|
|
|
|
* 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>
|
|
|
|
*
|
|
|
|
* @param string $className
|
|
|
|
* @return DataList
|
|
|
|
*/
|
|
|
|
public static function getDataList($className)
|
|
|
|
{
|
|
|
|
$list = new DataList($className);
|
|
|
|
$list->setDataModel(DataModel::inst());
|
|
|
|
return $list;
|
|
|
|
}
|
2012-04-15 10:48:50 +12:00
|
|
|
}
|