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;
            }
        }
    }
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;
            }
        }
    }
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 ; } } }
Event handler called before writing to the database.
If the title is empty, set a default based on the link.
Event handler called before writing to the database . If the title is empty set a default based on the link .