public function getCMSFields()
    {
        $this->beforeUpdateCMSFields(function (FieldList $fields) {
            // Setup the linking to the original page.
            $copyContentFromField = TreeDropdownField::create(
                'CopyContentFromID',
                _t(self::class . '.CHOOSE', "Linked Page"),
                SiteTree::class
            );

            // Setup virtual fields
            if ($virtualFields = $this->getVirtualFields()) {
                $roTransformation = new ReadonlyTransformation();
                foreach ($virtualFields as $virtualField) {
                    if ($fields->dataFieldByName($virtualField)) {
                        $fields->replaceField(
                            $virtualField,
                            $fields->dataFieldByName($virtualField)->transform($roTransformation)
                        );
                    }
                }
            }

            $msgs = array();

            $fields->addFieldToTab('Root.Main', $copyContentFromField, 'Title');

            // Create links back to the original object in the CMS
            if ($this->CopyContentFrom()->exists()) {
                $link = HTML::createTag(
                    'a',
                    [
                        'class' => 'cmsEditlink',
                        'href' => 'admin/pages/edit/show/' . $this->CopyContentFromID,
                    ],
                    _t(self::class . '.EditLink', 'edit')
                );
                $msgs[] = _t(
                    self::class . '.HEADERWITHLINK',
                    "This is a virtual page copying content from \"{title}\" ({link})",
                    [
                        'title' => $this->CopyContentFrom()->obj('Title'),
                        'link'  => $link,
                    ]
                );
            } else {
                $msgs[] = _t(self::class . '.HEADER', "This is a virtual page");
                $msgs[] = _t(
                    'SilverStripe\\CMS\\Model\\SiteTree.VIRTUALPAGEWARNING',
                    'Please choose a linked page and save first in order to publish this page'
                );
            }
            if ($this->CopyContentFromID && !Versioned::get_versionnumber_by_stage(
                SiteTree::class,
                Versioned::LIVE,
                $this->CopyContentFromID
            )) {
                $msgs[] = _t(
                    'SilverStripe\\CMS\\Model\\SiteTree.VIRTUALPAGEDRAFTWARNING',
                    'Please publish the linked page in order to publish the virtual page'
                );
            }

            $fields->addFieldToTab("Root.Main", new LiteralField(
                'VirtualPageMessage',
                '<div class="message notice">' . implode('. ', $msgs) . '.</div>'
            ), 'CopyContentFromID');
        });

        return parent::getCMSFields();
    }
public function getCMSFields()
    {
        $this->beforeUpdateCMSFields(function (FieldList $fields) {
            // Setup the linking to the original page.
            $copyContentFromField = TreeDropdownField::create(
                'CopyContentFromID',
                _t(self::class . '.CHOOSE', "Linked Page"),
                SiteTree::class
            );

            // Setup virtual fields
            if ($virtualFields = $this->getVirtualFields()) {
                $roTransformation = new ReadonlyTransformation();
                foreach ($virtualFields as $virtualField) {
                    if ($fields->dataFieldByName($virtualField)) {
                        $fields->replaceField(
                            $virtualField,
                            $fields->dataFieldByName($virtualField)->transform($roTransformation)
                        );
                    }
                }
            }

            $msgs = array();

            $fields->addFieldToTab('Root.Main', $copyContentFromField, 'Title');

            // Create links back to the original object in the CMS
            if ($this->CopyContentFrom()->exists()) {
                $link = HTML::createTag(
                    'a',
                    [
                        'class' => 'cmsEditlink',
                        'href' => 'admin/pages/edit/show/' . $this->CopyContentFromID,
                    ],
                    _t(self::class . '.EditLink', 'edit')
                );
                $msgs[] = _t(
                    self::class . '.HEADERWITHLINK',
                    "This is a virtual page copying content from \"{title}\" ({link})",
                    [
                        'title' => $this->CopyContentFrom()->obj('Title'),
                        'link'  => $link,
                    ]
                );
            } else {
                $msgs[] = _t(self::class . '.HEADER', "This is a virtual page");
                $msgs[] = _t(
                    'SilverStripe\\CMS\\Model\\SiteTree.VIRTUALPAGEWARNING',
                    'Please choose a linked page and save first in order to publish this page'
                );
            }
            if ($this->CopyContentFromID && !Versioned::get_versionnumber_by_stage(
                SiteTree::class,
                Versioned::LIVE,
                $this->CopyContentFromID
            )) {
                $msgs[] = _t(
                    'SilverStripe\\CMS\\Model\\SiteTree.VIRTUALPAGEDRAFTWARNING',
                    'Please publish the linked page in order to publish the virtual page'
                );
            }

            $fields->addFieldToTab("Root.Main", new LiteralField(
                'VirtualPageMessage',
                '<div class="message notice">' . implode('. ', $msgs) . '.</div>'
            ), 'CopyContentFromID');
        });

        return parent::getCMSFields();
    }
public function getCMSFields ( ) { $ this -> beforeUpdateCMSFields ( function ( FieldList $ fields ) { // Setup the linking to the original page. $ copyContentFromField = TreeDropdownField :: create ( 'CopyContentFromID' , _t ( self :: class . '.CHOOSE' , "Linked Page" ) , SiteTree :: class ) ; // Setup virtual fields if ( $ virtualFields = $ this -> getVirtualFields ( ) ) { $ roTransformation = new ReadonlyTransformation ( ) ; foreach ( $ virtualFields as $ virtualField ) { if ( $ fields -> dataFieldByName ( $ virtualField ) ) { $ fields -> replaceField ( $ virtualField , $ fields -> dataFieldByName ( $ virtualField ) -> transform ( $ roTransformation ) ) ; } } } $ msgs = array ( ) ; $ fields -> addFieldToTab ( 'Root.Main' , $ copyContentFromField , 'Title' ) ; // Create links back to the original object in the CMS if ( $ this -> CopyContentFrom ( ) -> exists ( ) ) { $ link = HTML :: createTag ( 'a' , [ 'class' => 'cmsEditlink' , 'href' => 'admin/pages/edit/show/' . $ this -> CopyContentFromID , ] , _t ( self :: class . '.EditLink' , 'edit' ) ) ; $ msgs [ ] = _t ( self :: class . '.HEADERWITHLINK' , "This is a virtual page copying content from \"{title}\" ({link})" , [ 'title' => $ this -> CopyContentFrom ( ) -> obj ( 'Title' ) , 'link' => $ link , ] ) ; } else { $ msgs [ ] = _t ( self :: class . '.HEADER' , "This is a virtual page" ) ; $ msgs [ ] = _t ( 'SilverStripe\\CMS\\Model\\SiteTree.VIRTUALPAGEWARNING' , 'Please choose a linked page and save first in order to publish this page' ) ; } if ( $ this -> CopyContentFromID && ! Versioned :: get_versionnumber_by_stage ( SiteTree :: class , Versioned :: LIVE , $ this -> CopyContentFromID ) ) { $ msgs [ ] = _t ( 'SilverStripe\\CMS\\Model\\SiteTree.VIRTUALPAGEDRAFTWARNING' , 'Please publish the linked page in order to publish the virtual page' ) ; } $ fields -> addFieldToTab ( "Root.Main" , new LiteralField ( 'VirtualPageMessage' , '<div class="message notice">' . implode ( '. ' , $ msgs ) . '.</div>' ) , 'CopyContentFromID' ) ; } ) ; return parent :: getCMSFields ( ) ; }
Generate the CMS fields from the fields from the original page.
Generate the CMS fields from the fields from the original page .