diff --git a/src/Extensions/ElementalAreasExtension.php b/src/Extensions/ElementalAreasExtension.php index 6a1b82d0..50415c08 100644 --- a/src/Extensions/ElementalAreasExtension.php +++ b/src/Extensions/ElementalAreasExtension.php @@ -187,7 +187,6 @@ public function updateCMSFields(FieldList $fields) /** * Make sure there is always an ElementalArea for adding Elements - * */ public function onBeforeWrite() { @@ -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(); } } diff --git a/src/Extensions/ElementalDuplicationExtension.php b/src/Extensions/ElementalDuplicationExtension.php deleted file mode 100644 index 47f8b98c..00000000 --- a/src/Extensions/ElementalDuplicationExtension.php +++ /dev/null @@ -1,60 +0,0 @@ -owner->ClassName; - - // Duplicate has_one's and has_many's - $duplicateRelations = Config::inst()->get($thisClass, 'duplicate_relations'); - if ($duplicateRelations && !empty($duplicateRelations)) { - foreach ($duplicateRelations as $relation) { - $items = $original->$relation(); - foreach ($items as $item) { - $duplicateItem = $item->duplicate(false); - $duplicateItem->{$thisClass.'ID'} = $this->owner->ID; - $duplicateItem->write(); - } - } - } - - // Duplicate many_many's - $duplicateManyManyRelations = Config::inst()->get($thisClass, 'duplicate_many_many_relations'); - if ($duplicateManyManyRelations && !empty($duplicateManyManyRelations)) { - foreach ($duplicateManyManyRelations as $relation) { - $items = $original->$relation(); - foreach ($items as $item) { - $this->owner->$relation()->add($item); - } - } - } - } - - public function onBeforeDuplicate($original, $doWrite = true) - { - $thisClass = $this->owner->ClassName; - $clearRelations = Config::inst()->get($thisClass, 'duplicate_clear_relations'); - - if ($clearRelations && !empty($clearRelations)) { - foreach ($clearRelations as $clearRelation) { - $clearRelation = $clearRelation . 'ID'; - $this->owner->$clearRelation = 0; - } - } - } -} diff --git a/src/Models/BaseElement.php b/src/Models/BaseElement.php index 552b3c61..f706133b 100644 --- a/src/Models/BaseElement.php +++ b/src/Models/BaseElement.php @@ -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; } } diff --git a/tests/ElementalAreaTest.php b/tests/ElementalAreaTest.php index d6c0edcc..606c595c 100644 --- a/tests/ElementalAreaTest.php +++ b/tests/ElementalAreaTest.php @@ -8,6 +8,7 @@ use DNADesign\Elemental\Tests\Src\TestPage; use Page; use SilverStripe\Dev\SapphireTest; +use SilverStripe\Versioned\Versioned; class ElementalAreaTest extends SapphireTest { @@ -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)); }