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;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function get_exposed_variables() {
|
public static function get_template_global_variables() {
|
||||||
return array(
|
return array(
|
||||||
'CurrentPage' => 'curr',
|
'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
|
* @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.
|
* as global variables in the templates.
|
||||||
*/
|
*/
|
||||||
public static function get_exposed_variables() {
|
public static function get_template_global_variables() {
|
||||||
return array(
|
return array(
|
||||||
'absoluteBaseURL',
|
'absoluteBaseURL',
|
||||||
'baseURL',
|
'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(
|
return array(
|
||||||
'i18nLocale' => 'get_locale',
|
'i18nLocale' => 'get_locale',
|
||||||
'get_locale',
|
'get_locale',
|
||||||
|
@ -1379,7 +1379,7 @@ class Member extends DataObject implements TemplateGlobalProvider {
|
|||||||
return $currentName ? $currentName : 'cms';
|
return $currentName ? $currentName : 'cms';
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function get_exposed_variables() {
|
public static function get_template_global_variables() {
|
||||||
return array(
|
return array(
|
||||||
'CurrentMember' => 'currentUser',
|
'CurrentMember' => 'currentUser',
|
||||||
'currentUser'
|
'currentUser'
|
||||||
|
@ -622,7 +622,7 @@ class Permission extends DataObject implements TemplateGlobalProvider {
|
|||||||
Permission::flush_permission_cache();
|
Permission::flush_permission_cache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function get_exposed_variables() {
|
public static function get_template_global_variables() {
|
||||||
return array(
|
return array(
|
||||||
'HasPerm' => 'check'
|
'HasPerm' => 'check'
|
||||||
);
|
);
|
||||||
|
@ -218,7 +218,7 @@ class SecurityToken extends Object implements TemplateGlobalProvider {
|
|||||||
return $generator->generateHash('sha1');
|
return $generator->generateHash('sha1');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function get_exposed_variables() {
|
public static function get_template_global_variables() {
|
||||||
return array(
|
return array(
|
||||||
'getSecurityID',
|
'getSecurityID',
|
||||||
'SecurityID' => 'getSecurityID'
|
'SecurityID' => 'getSecurityID'
|
||||||
|
@ -990,7 +990,7 @@ class SSViewerTest_Page extends SiteTree {
|
|||||||
|
|
||||||
class SSViewerTest_GlobalProvider implements TemplateGlobalProvider, TestOnly {
|
class SSViewerTest_GlobalProvider implements TemplateGlobalProvider, TestOnly {
|
||||||
|
|
||||||
public static function get_exposed_variables() {
|
public static function get_template_global_variables() {
|
||||||
return array(
|
return array(
|
||||||
'SSViewerTest_GlobalHTMLFragment' => array('method' => 'get_html'),
|
'SSViewerTest_GlobalHTMLFragment' => array('method' => 'get_html'),
|
||||||
'SSViewerTest_GlobalHTMLEscaped' => array('method' => 'get_html', 'casting' => 'Varchar'),
|
'SSViewerTest_GlobalHTMLEscaped' => array('method' => 'get_html', 'casting' => 'Varchar'),
|
||||||
|
@ -134,7 +134,7 @@ class SSViewer_BasicIteratorSupport implements TemplateIteratorProvider {
|
|||||||
protected $iteratorPos;
|
protected $iteratorPos;
|
||||||
protected $iteratorTotalItems;
|
protected $iteratorTotalItems;
|
||||||
|
|
||||||
public static function get_exposed_variables() {
|
public static function get_template_iterator_variables() {
|
||||||
return array(
|
return array(
|
||||||
'First',
|
'First',
|
||||||
'Last',
|
'Last',
|
||||||
@ -307,20 +307,20 @@ class SSViewer_DataPresenter extends SSViewer_Scope {
|
|||||||
if (self::$globalProperties === null) {
|
if (self::$globalProperties === null) {
|
||||||
self::$globalProperties = array();
|
self::$globalProperties = array();
|
||||||
// Get all the exposed variables from all classes that implement the TemplateGlobalProvider interface
|
// 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
|
// Build up iterator property providers array only once per request
|
||||||
if (self::$iteratorProperties === null) {
|
if (self::$iteratorProperties === null) {
|
||||||
self::$iteratorProperties = array();
|
self::$iteratorProperties = array();
|
||||||
// Get all the exposed variables from all classes that implement the TemplateIteratorProvider interface
|
// 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;
|
$this->extras = $extras;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createCallableArray(&$extraArray, $interfaceToQuery, $createObject = false) {
|
protected function createCallableArray(&$extraArray, $interfaceToQuery, $variableMethod, $createObject = false) {
|
||||||
$implementers = ClassInfo::implementorsOf($interfaceToQuery);
|
$implementers = ClassInfo::implementorsOf($interfaceToQuery);
|
||||||
if($implementers) foreach($implementers as $implementer) {
|
if($implementers) foreach($implementers as $implementer) {
|
||||||
|
|
||||||
@ -328,7 +328,7 @@ class SSViewer_DataPresenter extends SSViewer_Scope {
|
|||||||
if ($createObject) $implementer = new $implementer();
|
if ($createObject) $implementer = new $implementer();
|
||||||
|
|
||||||
// Get the exposed variables
|
// Get the exposed variables
|
||||||
$exposedVariables = $implementer::get_exposed_variables();
|
$exposedVariables = $implementer::$variableMethod();
|
||||||
|
|
||||||
foreach($exposedVariables as $varName => $details) {
|
foreach($exposedVariables as $varName => $details) {
|
||||||
if (!is_array($details)) $details = array('method' => $details, 'casting' => Object::get_static('ViewableData', 'default_cast'));
|
if (!is_array($details)) $details = array('method' => $details, 'casting' => Object::get_static('ViewableData', 'default_cast'));
|
||||||
|
@ -1,21 +1,35 @@
|
|||||||
<?php
|
<?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.
|
* Director::AbsoluteBaseURL is an example of this.
|
||||||
|
*
|
||||||
* @package sapphire
|
* @package sapphire
|
||||||
* @subpackage core
|
* @subpackage core
|
||||||
*/
|
*/
|
||||||
interface TemplateGlobalProvider {
|
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
|
* @abstract
|
||||||
* @return array Returns an array of strings of the method names of methods on the call that should be exposed
|
* @return array Returns an array of items. Each key => value pair is one of three forms:
|
||||||
* as global variables in the templates. A map (template-variable-name => method-name) can optionally be supplied
|
* - template name (no key)
|
||||||
* if the template variable name is different from the name of the method to call. The case of the first character
|
* - template name => method name
|
||||||
* in the method name called from the template does not matter, although names specified in the map should
|
* - template name => array(), where the array can contain these key => value pairs
|
||||||
* correspond to the actual method name in the relevant class.
|
* - "method" => method name
|
||||||
* Note that the template renderer must be able to call these methods statically.
|
* - "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
|
<?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
|
* SSViewer_BasicIteratorSupport is an example of this. See also @TemplateGlobalProvider
|
||||||
|
*
|
||||||
* @package sapphire
|
* @package sapphire
|
||||||
* @subpackage core
|
* @subpackage core
|
||||||
*/
|
*/
|
||||||
interface TemplateIteratorProvider {
|
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
|
* @abstract
|
||||||
* @return array Returns an array of strings of the method names of methods on the call that should be exposed
|
* @return array Returns an array of items. Each key => value pair is one of three forms:
|
||||||
* as global variables in the templates. A map (template-variable-name => method-name) can optionally be supplied
|
* - template name (no key)
|
||||||
* if the template variable name is different from the name of the method to call. The case of the first character
|
* - template name => method name
|
||||||
* in the method name called from the template does not matter, although names specified in the map should
|
* - template name => array(), where the array can contain these key => value pairs
|
||||||
* correspond to the actual method name in the relevant class.
|
* - "method" => method name
|
||||||
* Note that the template renderer must be able to call these methods statically.
|
* - "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.
|
* 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
|
* @abstract
|
||||||
* @param int $pos position in iterator
|
* @param int $pos position in iterator
|
||||||
* @param int $totalItems total number of items
|
* @param int $totalItems total number of items
|
||||||
|
Loading…
x
Reference in New Issue
Block a user