src/ImportField.php
protected function writeContent($subtitle, $subdoc, $subnode, $sort = null, $publishPages = false)
    {
        $record = $this->form->getRecord();

        if ($subtitle) {
            // Write the chapter page to a subpage.
            $page = DataObject::get_one(
                'Page',
                sprintf('"Title" = \'%s\' AND "ParentID" = %d', $subtitle, $record->ID)
            );
            if (!$page) {
                $page = Page::create();
                $page->ParentID = $record->ID;
                $page->Title = $subtitle;
            }

            unset($this->unusedChildren[$page->ID]);
            file_put_contents(ASSETS_PATH . '/index-' . $sort . '.html', $this->getBodyText($subdoc, $subnode));

            if ($sort) {
                $page->Sort = $sort;
            }
            $page->Content = $this->getBodyText($subdoc, $subnode);
            $page->write();
            if ($publishPages) {
                $page->publishRecursive();
            }
        } else {
            // Write to the master page.
            $record->Content = $this->getBodyText($subdoc, $subnode);
            $record->write();

            if ($publishPages) {
                $record->publishRecursive();
            }
        }
    }
protected function writeContent($subtitle, $subdoc, $subnode, $sort = null, $publishPages = false)
    {
        $record = $this->form->getRecord();

        if ($subtitle) {
            // Write the chapter page to a subpage.
            $page = DataObject::get_one(
                'Page',
                sprintf('"Title" = \'%s\' AND "ParentID" = %d', $subtitle, $record->ID)
            );
            if (!$page) {
                $page = Page::create();
                $page->ParentID = $record->ID;
                $page->Title = $subtitle;
            }

            unset($this->unusedChildren[$page->ID]);
            file_put_contents(ASSETS_PATH . '/index-' . $sort . '.html', $this->getBodyText($subdoc, $subnode));

            if ($sort) {
                $page->Sort = $sort;
            }
            $page->Content = $this->getBodyText($subdoc, $subnode);
            $page->write();
            if ($publishPages) {
                $page->publishRecursive();
            }
        } else {
            // Write to the master page.
            $record->Content = $this->getBodyText($subdoc, $subnode);
            $record->write();

            if ($publishPages) {
                $record->publishRecursive();
            }
        }
    }
protected function writeContent ( $ subtitle , $ subdoc , $ subnode , $ sort = null , $ publishPages = false ) { $ record = $ this -> form -> getRecord ( ) ; if ( $ subtitle ) { // Write the chapter page to a subpage. $ page = DataObject :: get_one ( 'Page' , sprintf ( '"Title" = \'%s\' AND "ParentID" = %d' , $ subtitle , $ record -> ID ) ) ; if ( ! $ page ) { $ page = Page :: create ( ) ; $ page -> ParentID = $ record -> ID ; $ page -> Title = $ subtitle ; } unset ( $ this -> unusedChildren [ $ page -> ID ] ) ; file_put_contents ( ASSETS_PATH . '/index-' . $ sort . '.html' , $ this -> getBodyText ( $ subdoc , $ subnode ) ) ; if ( $ sort ) { $ page -> Sort = $ sort ; } $ page -> Content = $ this -> getBodyText ( $ subdoc , $ subnode ) ; $ page -> write ( ) ; if ( $ publishPages ) { $ page -> publishRecursive ( ) ; } } else { // Write to the master page. $ record -> Content = $ this -> getBodyText ( $ subdoc , $ subnode ) ; $ record -> write ( ) ; if ( $ publishPages ) { $ record -> publishRecursive ( ) ; } } }
Used only when writing the document that has been split by headers.
Can write both to the chapter pages as well as the master page.

@param string $subtitle Title of the chapter - if missing, it will write to the master page.
@param $subdoc
@param $subnode
@param int $sort Order of the chapter page.
@param $publishPages Whether to publish the resulting child/master pages.
Used only when writing the document that has been split by headers . Can write both to the chapter pages as well as the master page .