mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
API CHANGE: Change variable expose method in TemplateGlobalProvider and TemplateIteratorProvider to (a) not clash with each other and, (b) be less generic
This commit is contained in:
parent
2c65d3a398
commit
374ed19406
@ -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',
|
||||
);
|
||||
|
@ -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',
|
||||
|
@ -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',
|
||||
|
@ -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'
|
||||
|
@ -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'
|
||||
);
|
||||
|
@ -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'
|
||||
|
@ -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'),
|
||||
|
@ -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'));
|
||||
|
@ -1,21 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* Interface that is implemented by any classes that want to expose a method that can be called in a template.
|
||||
* Interface that is implemented by any classes that want to expose a method that can be called in any scope in a template.
|
||||
*
|
||||
* Director::AbsoluteBaseURL is an example of this.
|
||||
*
|
||||
* @package sapphire
|
||||
* @subpackage core
|
||||
*/
|
||||
interface TemplateGlobalProvider {
|
||||
|
||||
/**
|
||||
* Called by SSViewer to get a list of global variables to expose to the template, the static method to call on
|
||||
* this class to get the value for those variables, and the class to use for casting the returned value for use
|
||||
* in a template
|
||||
*
|
||||
* If the method to call is not included for a particular template variable, a method named the same as the template
|
||||
* variable will be called
|
||||
*
|
||||
* If the casting class is not specified for a particular template variable, ViewableData::$default_cast is used
|
||||
*
|
||||
* The first letter of the template variable is case-insensitive. However the method name is always case sensitive.
|
||||
*
|
||||
* @abstract
|
||||
* @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. A map (template-variable-name => 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();
|
||||
}
|
||||
|
||||
?>
|
@ -1,24 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* Interface that is implemented by any classes that want to expose a method that can be called in a template.
|
||||
* Interface that is implemented by any classes that want to expose a method that can be called in any scope in a template
|
||||
* that returns values dependant on the state of the iterator of the current scope.
|
||||
*
|
||||
* SSViewer_BasicIteratorSupport is an example of this. See also @TemplateGlobalProvider
|
||||
*
|
||||
* @package sapphire
|
||||
* @subpackage core
|
||||
*/
|
||||
interface TemplateIteratorProvider {
|
||||
|
||||
/**
|
||||
* Called by SSViewer to get a list of iterator variables to expose to the template, the instance method to call on
|
||||
* an instance of this class to get the value for those variables, and the class to use for casting the returned value
|
||||
* for use in a template
|
||||
*
|
||||
* If the method to call is not included for a particular template variable, a method named the same as the template
|
||||
* variable will be called
|
||||
*
|
||||
* If the casting class is not specified for a particular template variable, ViewableData::$default_cast is used
|
||||
*
|
||||
* The first letter of the template variable is case-insensitive. However the method name is always case sensitive.
|
||||
*
|
||||
* @abstract
|
||||
* @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. A map (template-variable-name => 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user