public function getNewItem($id, $setID = true) { list($dummy, $className, $parentID, $suffix) = explode('-', $id); if (!Translatable::is_default_lang()) { $originalItem = Translatable::get_original($className, Session::get("{$id}_originalLangID")); if ($setID) { $originalItem->ID = $id; } else { $originalItem->ID = null; Translatable::creating_from(Session::get($id . '_originalLangID')); } return $originalItem; } $newItem = new $className(); if (!$suffix) { $sessionTag = "NewItems." . $parentID . "." . $className; if (Session::get($sessionTag)) { $suffix = '-' . Session::get($sessionTag); Session::set($sessionTag, Session::get($sessionTag) + 1); } else { Session::set($sessionTag, 1); } $id = $id . $suffix; } $newItem->Title = _t('CMSMain.NEW', "New ", PR_MEDIUM, '"New " followed by a className') . $className; $newItem->URLSegment = "new-" . strtolower($className); $newItem->ClassName = $className; $newItem->ParentID = $parentID; // DataObject::fieldExists only checks the current class, not the hierarchy // This allows the CMS to set the correct sort value if ($newItem->castingHelperPair('Sort')) { $newItem->Sort = DB::query("SELECT MAX(Sort) FROM SiteTree WHERE ParentID = '" . Convert::raw2sql($parentID) . "'")->value() + 1; } if (Member::currentUser()) { $newItem->OwnerID = Member::currentUser()->ID; } if ($setID) { $newItem->ID = $id; } # Some modules like subsites add extra fields that need to be set when the new item is created $this->extend('augmentNewSiteTreeItem', $newItem); return $newItem; }