public function onBeforeWrite()
    {
        parent::onBeforeWrite();
        /** Check if we have translatable and a NewsHolderPage. If no HolderPage available, skip (Create an orphan) */
        if (!$this->NewsHolderPages()->count()) {
            if (!class_exists('Translatable') && $page = NewsHolderPage::get()->first()) {
                $this->NewsHolderPages()->add($page);
            } elseif (class_exists('Translatable')) {
                Translatable::disable_locale_filter();
                $page = NewsHolderPage::get()->first();
                $this->NewsHolderPages()->add($page);
                Translatable::enable_locale_filter();
            }
        }
        if (!$this->Type || $this->Type === '') {
            $this->Type = 'news';
        }
        /** Set PublishFrom to today to prevent errors with sorting. New since 2.0, backward compatible. */
        if (!$this->PublishFrom) {
            $this->PublishFrom = SS_Datetime::now()->Rfc2822();
        }
        /**
         * Make sure the link is valid.
         */
        if (substr($this->External, 0, 4) !== 'http' && $this->External != '') {
            $this->External = 'http://' . $this->External;
        }
        $this->setURLValue();
        $this->setAuthorData();
    }
public function onBeforeWrite()
    {
        parent::onBeforeWrite();
        /** Check if we have translatable and a NewsHolderPage. If no HolderPage available, skip (Create an orphan) */
        if (!$this->NewsHolderPages()->count()) {
            if (!class_exists('Translatable') && $page = NewsHolderPage::get()->first()) {
                $this->NewsHolderPages()->add($page);
            } elseif (class_exists('Translatable')) {
                Translatable::disable_locale_filter();
                $page = NewsHolderPage::get()->first();
                $this->NewsHolderPages()->add($page);
                Translatable::enable_locale_filter();
            }
        }
        if (!$this->Type || $this->Type === '') {
            $this->Type = 'news';
        }
        /** Set PublishFrom to today to prevent errors with sorting. New since 2.0, backward compatible. */
        if (!$this->PublishFrom) {
            $this->PublishFrom = SS_Datetime::now()->Rfc2822();
        }
        /**
         * Make sure the link is valid.
         */
        if (substr($this->External, 0, 4) !== 'http' && $this->External != '') {
            $this->External = 'http://' . $this->External;
        }
        $this->setURLValue();
        $this->setAuthorData();
    }
public function onBeforeWrite ( ) { parent :: onBeforeWrite ( ) ; /** Check if we have translatable and a NewsHolderPage. If no HolderPage available, skip (Create an orphan) */ if ( ! $ this -> NewsHolderPages ( ) -> count ( ) ) { if ( ! class_exists ( 'Translatable' ) && $ page = NewsHolderPage :: get ( ) -> first ( ) ) { $ this -> NewsHolderPages ( ) -> add ( $ page ) ; } elseif ( class_exists ( 'Translatable' ) ) { Translatable :: disable_locale_filter ( ) ; $ page = NewsHolderPage :: get ( ) -> first ( ) ; $ this -> NewsHolderPages ( ) -> add ( $ page ) ; Translatable :: enable_locale_filter ( ) ; } } if ( ! $ this -> Type || $ this -> Type === '' ) { $ this -> Type = 'news' ; } /** Set PublishFrom to today to prevent errors with sorting. New since 2.0, backward compatible. */ if ( ! $ this -> PublishFrom ) { $ this -> PublishFrom = SS_Datetime :: now ( ) -> Rfc2822 ( ) ; } /**
         * Make sure the link is valid.
         */ if ( substr ( $ this -> External , 0 , 4 ) !== 'http' && $ this -> External != '' ) { $ this -> External = 'http://' . $ this -> External ; } $ this -> setURLValue ( ) ; $ this -> setAuthorData ( ) ; }
The holder-page ID should be set if translatable, otherwise, we just select the first available one.
The NewsHolderPage should NEVER be doubled.
The holder - page ID should be set if translatable otherwise we just select the first available one . The NewsHolderPage should NEVER be doubled .