diff --git a/src/Models/BaseElement.php b/src/Models/BaseElement.php index daf287e8..3a4bcaa6 100644 --- a/src/Models/BaseElement.php +++ b/src/Models/BaseElement.php @@ -1232,21 +1232,41 @@ public function getPageTitle() } /** - * @return boolean + * Returns true if this is the first element rendered in the ElementalArea + * @return bool */ - public function First() + public function IsFirst(): bool { return ($this->Parent()->Elements()->first()->ID === $this->ID); } /** - * @return boolean + * @deprecated 5.4.0 Use IsFirst() instead. */ - public function Last() + public function First() + { + Deprecation::notice('5.4.0', 'Use IsFirst() instead'); + return $this->IsFirst(); + } + + /** + * Returns true if this is the last element rendered in the ElementalArea + * @return bool + */ + public function IsLast(): bool { return ($this->Parent()->Elements()->last()->ID === $this->ID); } + /** + * @deprecated 5.4.0 Use IsLast() instead. + */ + public function Last() + { + Deprecation::notice('5.4.0', 'Use IsLast() instead'); + return $this->IsLast(); + } + /** * @return int */ diff --git a/tests/BaseElementTest.php b/tests/BaseElementTest.php index ad6ce471..70a17102 100644 --- a/tests/BaseElementTest.php +++ b/tests/BaseElementTest.php @@ -190,6 +190,15 @@ public function testStyleVariants() $this->assertEquals('', $element->getStyleVariant()); } + public function testIsFirst() + { + $element = $this->objFromFixture(ElementContent::class, 'content1'); + $element2 = $this->objFromFixture(ElementContent::class, 'content2'); + + $this->assertTrue($element->IsFirst()); + $this->assertFalse($element2->IsFirst()); + } + public function testFirst() { $element = $this->objFromFixture(ElementContent::class, 'content1'); @@ -199,6 +208,15 @@ public function testFirst() $this->assertFalse($element2->First()); } + public function testIsLast() + { + $element = $this->objFromFixture(ElementContent::class, 'content1'); + $element2 = $this->objFromFixture(ElementContent::class, 'content2'); + + $this->assertFalse($element->Last()); + $this->assertTrue($element2->Last()); + } + public function testLast() { $element = $this->objFromFixture(ElementContent::class, 'content1');