diff --git a/control/Controller.php b/control/Controller.php index f77e56868..b8882d4f4 100644 --- a/control/Controller.php +++ b/control/Controller.php @@ -584,7 +584,7 @@ class Controller extends RequestHandler implements TemplateGlobalProvider { return $result; } - public static function get_exposed_variables() { + public static function get_template_global_variables() { return array( 'CurrentPage' => 'curr', ); diff --git a/control/Director.php b/control/Director.php index 95642dabd..403b01bc1 100644 --- a/control/Director.php +++ b/control/Director.php @@ -870,7 +870,7 @@ class Director implements TemplateGlobalProvider { * @return array Returns an array of strings of the method names of methods on the call that should be exposed * as global variables in the templates. */ - public static function get_exposed_variables() { + public static function get_template_global_variables() { return array( 'absoluteBaseURL', 'baseURL', diff --git a/i18n/i18n.php b/i18n/i18n.php index a305d818d..4834e8271 100644 --- a/i18n/i18n.php +++ b/i18n/i18n.php @@ -1957,7 +1957,7 @@ class i18n extends Object implements TemplateGlobalProvider { } } - public static function get_exposed_variables() { + public static function get_template_global_variables() { return array( 'i18nLocale' => 'get_locale', 'get_locale', diff --git a/security/Member.php b/security/Member.php index 039cddb0d..14825d8c1 100644 --- a/security/Member.php +++ b/security/Member.php @@ -1379,7 +1379,7 @@ class Member extends DataObject implements TemplateGlobalProvider { return $currentName ? $currentName : 'cms'; } - public static function get_exposed_variables() { + public static function get_template_global_variables() { return array( 'CurrentMember' => 'currentUser', 'currentUser' diff --git a/security/Permission.php b/security/Permission.php index d130c2219..a1157e682 100644 --- a/security/Permission.php +++ b/security/Permission.php @@ -622,7 +622,7 @@ class Permission extends DataObject implements TemplateGlobalProvider { Permission::flush_permission_cache(); } - public static function get_exposed_variables() { + public static function get_template_global_variables() { return array( 'HasPerm' => 'check' ); diff --git a/security/SecurityToken.php b/security/SecurityToken.php index 04e3cf4f3..dbcbf19dc 100644 --- a/security/SecurityToken.php +++ b/security/SecurityToken.php @@ -218,7 +218,7 @@ class SecurityToken extends Object implements TemplateGlobalProvider { return $generator->generateHash('sha1'); } - public static function get_exposed_variables() { + public static function get_template_global_variables() { return array( 'getSecurityID', 'SecurityID' => 'getSecurityID' diff --git a/tests/view/SSViewerTest.php b/tests/view/SSViewerTest.php index eb1820da3..362367050 100644 --- a/tests/view/SSViewerTest.php +++ b/tests/view/SSViewerTest.php @@ -990,7 +990,7 @@ class SSViewerTest_Page extends SiteTree { class SSViewerTest_GlobalProvider implements TemplateGlobalProvider, TestOnly { - public static function get_exposed_variables() { + public static function get_template_global_variables() { return array( 'SSViewerTest_GlobalHTMLFragment' => array('method' => 'get_html'), 'SSViewerTest_GlobalHTMLEscaped' => array('method' => 'get_html', 'casting' => 'Varchar'), diff --git a/view/SSViewer.php b/view/SSViewer.php index 948368aca..409ce93ca 100644 --- a/view/SSViewer.php +++ b/view/SSViewer.php @@ -134,7 +134,7 @@ class SSViewer_BasicIteratorSupport implements TemplateIteratorProvider { protected $iteratorPos; protected $iteratorTotalItems; - public static function get_exposed_variables() { + public static function get_template_iterator_variables() { return array( 'First', 'Last', @@ -307,20 +307,20 @@ class SSViewer_DataPresenter extends SSViewer_Scope { if (self::$globalProperties === null) { self::$globalProperties = array(); // Get all the exposed variables from all classes that implement the TemplateGlobalProvider interface - $this->createCallableArray(self::$globalProperties, "TemplateGlobalProvider"); + $this->createCallableArray(self::$globalProperties, "TemplateGlobalProvider", "get_template_global_variables"); } // Build up iterator property providers array only once per request if (self::$iteratorProperties === null) { self::$iteratorProperties = array(); // Get all the exposed variables from all classes that implement the TemplateIteratorProvider interface - $this->createCallableArray(self::$iteratorProperties, "TemplateIteratorProvider", true); //call non-statically + $this->createCallableArray(self::$iteratorProperties, "TemplateIteratorProvider", "get_template_iterator_variables", true); //call non-statically } $this->extras = $extras; } - protected function createCallableArray(&$extraArray, $interfaceToQuery, $createObject = false) { + protected function createCallableArray(&$extraArray, $interfaceToQuery, $variableMethod, $createObject = false) { $implementers = ClassInfo::implementorsOf($interfaceToQuery); if($implementers) foreach($implementers as $implementer) { @@ -328,7 +328,7 @@ class SSViewer_DataPresenter extends SSViewer_Scope { if ($createObject) $implementer = new $implementer(); // Get the exposed variables - $exposedVariables = $implementer::get_exposed_variables(); + $exposedVariables = $implementer::$variableMethod(); foreach($exposedVariables as $varName => $details) { if (!is_array($details)) $details = array('method' => $details, 'casting' => Object::get_static('ViewableData', 'default_cast')); diff --git a/view/TemplateGlobalProvider.php b/view/TemplateGlobalProvider.php index 5f8716ab6..f70856223 100644 --- a/view/TemplateGlobalProvider.php +++ b/view/TemplateGlobalProvider.php @@ -1,21 +1,35 @@ method-name) can optionally be supplied - * if the template variable name is different from the name of the method to call. The case of the first character - * in the method name called from the template does not matter, although names specified in the map should - * correspond to the actual method name in the relevant class. - * Note that the template renderer must be able to call these methods statically. + * @return array Returns an array of items. Each key => value pair is one of three forms: + * - template name (no key) + * - template name => method name + * - template name => array(), where the array can contain these key => value pairs + * - "method" => method name + * - "casting" => casting class to use (i.e., Varchar, HTMLText, etc) */ - public static function get_exposed_variables(); + public static function get_template_global_variables(); } ?> \ No newline at end of file diff --git a/view/TemplateIteratorProvider.php b/view/TemplateIteratorProvider.php index 706f14250..22603b916 100644 --- a/view/TemplateIteratorProvider.php +++ b/view/TemplateIteratorProvider.php @@ -1,24 +1,43 @@ method-name) can optionally be supplied - * if the template variable name is different from the name of the method to call. The case of the first character - * in the method name called from the template does not matter, although names specified in the map should - * correspond to the actual method name in the relevant class. - * Note that the template renderer must be able to call these methods statically. + * @return array Returns an array of items. Each key => value pair is one of three forms: + * - template name (no key) + * - template name => method name + * - template name => array(), where the array can contain these key => value pairs + * - "method" => method name + * - "casting" => casting class to use (i.e., Varchar, HTMLText, etc) */ - public static function get_exposed_variables(); + public static function get_template_iterator_variables(); /** * Set the current iterator properties - where we are on the iterator. + * + * This is called by SSViewer prior to calling any of the variables exposed to the template (that is, as returned + * from a call to get_template_iterator_variables) + * * @abstract * @param int $pos position in iterator * @param int $totalItems total number of items