For this, I would create the TeamReport
in an onAfterWrite
method on TeamPage
, after checking for creation in onBeforeWrite
.
public function onBeforeWrite() {
parent::onBeforeWrite();
$this->IsCreating = !$this->ID;
}
public function onAfterWrite() {
parent::onAfterWrite();
if ($this->IsCreating) {
$child = new TeamReport();
$child->ParentID = $this->ID;
$child->URLSegment = 'report';
$child->Title = 'Report';
$child->write();
}
}