Skip to content

Commit

Permalink
Merge pull request #244 from creative-commoners/pulls/3.0/remove-depr…
Browse files Browse the repository at this point in the history
…ecated

API Remove deprecated duplication extension, remove unneeded write() calls and improve some doc blocks
  • Loading branch information
ScopeyNZ authored Jun 25, 2018
2 parents 9c00f30 + a698af7 commit 874ab94
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 72 deletions.
3 changes: 0 additions & 3 deletions src/Extensions/ElementalAreasExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ public function updateCMSFields(FieldList $fields)

/**
* Make sure there is always an ElementalArea for adding Elements
*
*/
public function onBeforeWrite()
{
Expand All @@ -207,8 +206,6 @@ public function onBeforeWrite()
$area->OwnerClassName = $this->owner->ClassName;
$area->write();
$this->owner->$areaID = $area->ID;
} elseif ($area = ElementalArea::get()->filter('ID', $this->owner->$areaID)->first()) {
$area->write();
}
}

Expand Down
60 changes: 0 additions & 60 deletions src/Extensions/ElementalDuplicationExtension.php

This file was deleted.

13 changes: 4 additions & 9 deletions src/Models/BaseElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,21 +229,16 @@ public function canCreate($member = null, $context = array())
}

/**
* @throws \SilverStripe\ORM\ValidationException
* Increment the sort order if one hasn't been already defined. This ensures that new elements are created
* at the end of the list by default.
*
* {@inheritDoc}
*/
public function onBeforeWrite()
{
parent::onBeforeWrite();

if ($areaID = $this->ParentID) {
if ($elementalArea = ElementalArea::get()->byID($areaID)) {
$elementalArea->write();
}
}

if (!$this->Sort) {
$parentID = ($this->ParentID) ? $this->ParentID : 0;

$this->Sort = static::get()->max('Sort') + 1;
}
}
Expand Down
4 changes: 4 additions & 0 deletions tests/ElementalAreaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use DNADesign\Elemental\Tests\Src\TestPage;
use Page;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Versioned\Versioned;

class ElementalAreaTest extends SapphireTest
{
Expand Down Expand Up @@ -49,12 +50,15 @@ public function testCanBePublished()
{
$member = $this->logInWithPermission('SITETREE_EDIT_ALL');

/** @var Page $page */
$page = $this->objFromFixture(TestPage::class, 'page1');
$this->assertTrue($page->canPublish($member));

/** @var ElementalArea|Versioned $area */
$area = $this->objFromFixture(ElementalArea::class, 'area1');
$this->assertTrue($area->canPublish($member));

/** @var TestElement|Versioned $element */
$element = $this->objFromFixture(TestElement::class, 'element1');
$this->assertTrue($element->canPublish($member));
}
Expand Down

0 comments on commit 874ab94

Please sign in to comment.