public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     if (!$this->Title) {
         $this->Title = Config::inst()->get($this->class, 'title');
     }
     if (Widget::has_extension('Versioned') && Versioned::current_stage() == 'Stage') {
         $this->publishAfterWrite = true;
     }
 }
 public function onBeforeDelete()
 {
     if (Widget::has_extension('Versioned')) {
         $currentStage = Versioned::current_stage();
         Versioned::reading_stage('Stage');
         parent::onBeforeDelete();
         Versioned::reading_stage('Live');
         parent::onBeforeDelete();
         Versioned::reading_stage($currentStage);
     } else {
         parent::onBeforeDelete();
     }
 }
 public function createDashboard($name, $createDefault = false)
 {
     $url = preg_replace('/ +/', '-', trim($name));
     // Replace any spaces
     $url = preg_replace('/[^A-Za-z0-9.+_\\-]/', '', $url);
     // Replace non alphanumeric characters
     $url = strtolower($url);
     $existing = $this->getNamedDashboard($url);
     if ($existing) {
         return $existing;
     }
     $dashboard = new DashboardPage();
     $dashboard->URLSegment = $url;
     $dashboard->Title = trim($name);
     $dashboard->OwnerID = $this->owner->ID;
     $dashboard->write();
     if ($createDefault) {
         $currentStage = null;
         if (Widget::has_extension('Versioned')) {
             $currentStage = Versioned::current_stage();
             Versioned::reading_stage('Stage');
         }
         $layout = Config::inst()->get('DashboardUser', 'default_layout');
         if (count($layout)) {
             foreach ($layout as $type => $properties) {
                 if (class_exists($type)) {
                     $dashlet = $type::create();
                     /* @var $dashlet Dashlet */
                     $dashletColumn = isset($properties['DashletColumn']) ? $properties['DashletColumn'] : 0;
                     $db = $dashboard->getDashboard($dashletColumn);
                     if ($db && $dashlet->canCreate()) {
                         $dashlet->ParentID = $db->ID;
                         if (is_array($properties)) {
                             $dashlet->update($properties);
                         }
                         $dashlet->write();
                     }
                 }
             }
         }
         if ($currentStage) {
             Versioned::reading_stage($currentStage);
         }
         $dashboard = $this->getNamedDashboard($url);
         $this->owner->extend('updateCreatedDashboard', $dashboard);
     }
     return $dashboard;
 }