function onBeforeWrite() { parent::onBeforeWrite(); $mainGroup = MerchantGroupDOD::get_main_group(); if ($mainGroup && $this->MerchantGroupCode()) { $merchantGroup = DataObject::get_one("Group", "\"Code\" = '" . $this->MerchantGroupCode() . "'", false); if (!$merchantGroup) { $merchantGroup = new Group(); $merchantGroup->Code = $this->MerchantGroupCode(); $merchantGroup->ParentID = $mainGroup->ID; } $merchantGroup->Title = $this->Title; $merchantGroup->write(); //adding permissions $this->CanEditType = 'OnlyTheseUsers'; $existingEditors = $this->EditorGroups(); $existingEditors->add($merchantGroup); } $this->MetaTitle = $this->Title; $this->MetaDescription = strip_tags($this->Content); }
function onBeforeWrite() { //add URLSegment first so that parent (SiteTree) //has a change to adjust the URLSegment //if needed. $this->URLSegment = strtolower($this->Address2); if (!$this->ImageID) { $parent = DataObject::get_by_id('MerchantPage', $this->ParentID); if ($parent && $parent->exists()) { $this->ImageID = $parent->ImageID; } } parent::onBeforeWrite(); }