From 7c95237e8da29072b37ea6ca9452740263cc8688 Mon Sep 17 00:00:00 2001 From: Andrew Aitken-Fincham Date: Mon, 15 Jun 2020 12:25:13 +0100 Subject: [PATCH] update template docs, move deprecation to 5.0, capitalise Is --- .../01_Templates/01_Syntax.md | 2 ++ src/View/SSViewer_BasicIteratorSupport.php | 28 +++++++++---------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/docs/en/02_Developer_Guides/01_Templates/01_Syntax.md b/docs/en/02_Developer_Guides/01_Templates/01_Syntax.md index 710d1cbb7..ab129b713 100644 --- a/docs/en/02_Developer_Guides/01_Templates/01_Syntax.md +++ b/docs/en/02_Developer_Guides/01_Templates/01_Syntax.md @@ -358,6 +358,8 @@ iteration. * `$Even`, `$Odd`: Returns boolean, handy for zebra striping. * `$EvenOdd`: Returns a string, either 'even' or 'odd'. Useful for CSS classes. * `$First`, `$Last`, `$Middle`: Booleans about the position in the list. + * Note: as of CMS 4.7.0 `$IsFirst` and `$IsLast` will be preferred. The original + syntax will continue to work, but will be deprecated in a future release. * `$FirstLast`: Returns a string, "first", "last", "first last" (if both), or "". Useful for CSS classes. * `$Pos`: The current position in the list (integer). Will start at 1, but can take a starting index as a parameter. diff --git a/src/View/SSViewer_BasicIteratorSupport.php b/src/View/SSViewer_BasicIteratorSupport.php index 4425326b0..9b757dd7b 100644 --- a/src/View/SSViewer_BasicIteratorSupport.php +++ b/src/View/SSViewer_BasicIteratorSupport.php @@ -26,8 +26,8 @@ class SSViewer_BasicIteratorSupport implements TemplateIteratorProvider public static function get_template_iterator_variables() { return [ - 'isFirst', - 'isLast', + 'IsFirst', + 'IsLast', 'First', 'Last', 'FirstLast', @@ -61,19 +61,19 @@ class SSViewer_BasicIteratorSupport implements TemplateIteratorProvider * * @return bool */ - public function isFirst() + public function IsFirst() { return $this->iteratorPos == 0; } /** - * @deprecated 4.7.0 Use isFirst() to avoid clashes with SS_Lists + * @deprecated 5.0 Use IsFirst() to avoid clashes with SS_Lists * @return bool */ public function First() { - Deprecation::notice('4.7.0', 'Use isFirst() to avoid clashes with SS_Lists'); - return $this->isFirst(); + Deprecation::notice('5.0', 'Use IsFirst() to avoid clashes with SS_Lists'); + return $this->IsFirst(); } /** @@ -81,19 +81,19 @@ class SSViewer_BasicIteratorSupport implements TemplateIteratorProvider * * @return bool */ - public function isLast() + public function IsLast() { return $this->iteratorPos == $this->iteratorTotalItems - 1; } /** - * @deprecated 4.7.0 Use isLast() to avoid clashes with SS_Lists + * @deprecated 5.0 Use IsLast() to avoid clashes with SS_Lists * @return bool */ public function Last() { - Deprecation::notice('4.7.0', 'Use isLast() to avoid clashes with SS_Lists'); - return $this->isLast(); + Deprecation::notice('5.0', 'Use IsLast() to avoid clashes with SS_Lists'); + return $this->IsLast(); } /** @@ -103,13 +103,13 @@ class SSViewer_BasicIteratorSupport implements TemplateIteratorProvider */ public function FirstLast() { - if ($this->isFirst() && $this->isLast()) { + if ($this->IsFirst() && $this->IsLast()) { return 'first last'; } - if ($this->isFirst()) { + if ($this->IsFirst()) { return 'first'; } - if ($this->isLast()) { + if ($this->IsLast()) { return 'last'; } return null; @@ -122,7 +122,7 @@ class SSViewer_BasicIteratorSupport implements TemplateIteratorProvider */ public function Middle() { - return !$this->isFirst() && !$this->isLast(); + return !$this->IsFirst() && !$this->IsLast(); } /**