mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
deprecate First and Last in order to disambiguate for array lists
This commit is contained in:
parent
1d6a6247a3
commit
bac826bc06
@ -2,6 +2,8 @@
|
||||
|
||||
namespace SilverStripe\View;
|
||||
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
|
||||
/**
|
||||
* Defines an extra set of basic methods that can be used in templates
|
||||
* that are not defined on sub-classes of {@link ViewableData}.
|
||||
@ -24,6 +26,8 @@ class SSViewer_BasicIteratorSupport implements TemplateIteratorProvider
|
||||
public static function get_template_iterator_variables()
|
||||
{
|
||||
return [
|
||||
'isFirst',
|
||||
'isLast',
|
||||
'First',
|
||||
'Last',
|
||||
'FirstLast',
|
||||
@ -57,21 +61,41 @@ class SSViewer_BasicIteratorSupport implements TemplateIteratorProvider
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function First()
|
||||
public function isFirst()
|
||||
{
|
||||
return $this->iteratorPos == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @return bool
|
||||
*/
|
||||
public function First()
|
||||
{
|
||||
Deprecation::notice("5.0.0 please use isFirst() to avoid clashes with SS_Lists");
|
||||
return $this->isFirst();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this object is the last in a set.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function Last()
|
||||
public function isLast()
|
||||
{
|
||||
return $this->iteratorPos == $this->iteratorTotalItems - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @return bool
|
||||
*/
|
||||
public function Last()
|
||||
{
|
||||
Deprecation::notice("5.0.0 please use isLast() to avoid clashes with SS_Lists");
|
||||
return $this->isLast();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns 'first' or 'last' if this is the first or last object in the set.
|
||||
*
|
||||
@ -79,13 +103,13 @@ class SSViewer_BasicIteratorSupport implements TemplateIteratorProvider
|
||||
*/
|
||||
public function FirstLast()
|
||||
{
|
||||
if ($this->First() && $this->Last()) {
|
||||
if ($this->isFirst() && $this->isLast()) {
|
||||
return 'first last';
|
||||
}
|
||||
if ($this->First()) {
|
||||
if ($this->isFirst()) {
|
||||
return 'first';
|
||||
}
|
||||
if ($this->Last()) {
|
||||
if ($this->isLast()) {
|
||||
return 'last';
|
||||
}
|
||||
return null;
|
||||
@ -98,7 +122,7 @@ class SSViewer_BasicIteratorSupport implements TemplateIteratorProvider
|
||||
*/
|
||||
public function Middle()
|
||||
{
|
||||
return !$this->First() && !$this->Last();
|
||||
return !$this->isFirst() && !$this->isLast();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user