public function onBeforeWrite()
    {
        parent::onBeforeWrite();
        if (empty($this->Title)) {
            $type = $this->Type;
            switch ($type) {
                case 'URL':
                case 'Email':
                case 'Phone':
                    $this->Title = $this->getField($type);
                    break;
                case 'SiteTree':
                    $this->Title = $this->SiteTree()->MenuTitle;
                    break;
                default:
                    if ($this->getRelationType($type) == 'has_one' && $component = $this->getComponent($type)) {
                        $this->Title = $component->Title;
                    } else {
                        $this->Title = 'Link-' . $this->ID;
                    }
                    break;
            }
        }
    }