protected function getArchiveWarningMessage($record)
    {

        $defaultMessage = _t('SilverStripe\\CMS\\Controllers\\CMSMain.ArchiveWarningWithChildren', 'Warning: This page and all of its child pages will be unpublished before being sent to the archive.\n\nAre you sure you want to proceed?');

        // Option to disable this feature as it is slow on large sites
        if (!$this->config()->enable_dynamic_archive_warning_message) {
            return $defaultMessage;
        }

        // Get all page's descendants
        $descendants = [];
        $this->collateDescendants([$record->ID], $descendants);
        if (!$descendants) {
            $descendants = [];
        }

        // Get the IDs of all changeset including at least one of the pages.
        $descendants[] = $record->ID;
        $inChangeSetIDs = ChangeSetItem::get()->filter([
            'ObjectID' => $descendants,
            'ObjectClass' => SiteTree::class
        ])->column('ChangeSetID');

        // Count number of affected change set
        $affectedChangeSetCount = 0;
        if (count($inChangeSetIDs) > 0) {
            $affectedChangeSetCount = ChangeSet::get()
                ->filter(['ID' => $inChangeSetIDs, 'State' => ChangeSet::STATE_OPEN])
                ->count();
        }

        $numCampaigns = ChangeSet::singleton()->i18n_pluralise($affectedChangeSetCount);
        $numCampaigns = mb_strtolower($numCampaigns);

        if (count($descendants) > 0 && $affectedChangeSetCount > 0) {
            $archiveWarningMsg = _t('SilverStripe\\CMS\\Controllers\\CMSMain.ArchiveWarningWithChildrenAndCampaigns', 'Warning: This page and all of its child pages will be unpublished and automatically removed from their associated {NumCampaigns} before being sent to the archive.\n\nAre you sure you want to proceed?', [ 'NumCampaigns' => $numCampaigns ]);
        } elseif (count($descendants) > 0) {
            $archiveWarningMsg = $defaultMessage;
        } elseif ($inChangeSets->count() > 0) {
            $archiveWarningMsg = _t('SilverStripe\\CMS\\Controllers\\CMSMain.ArchiveWarningWithChildren', 'Warning: This page and all of its child pages will be unpublished before being sent to the archive.\n\nAre you sure you want to proceed?');
        } elseif ($affectedChangeSetCount > 0) {
            $archiveWarningMsg = _t('SilverStripe\\CMS\\Controllers\\CMSMain.ArchiveWarningWithCampaigns', 'Warning: This page will be unpublished and automatically removed from their associated {NumCampaigns} before being sent to the archive.\n\nAre you sure you want to proceed?', [ 'NumCampaigns' => $numCampaigns ]);
        } else {
            $archiveWarningMsg = _t('SilverStripe\\CMS\\Controllers\\CMSMain.ArchiveWarning', 'Warning: This page will be unpublished before being sent to the archive.\n\nAre you sure you want to proceed?');
        }

        return $archiveWarningMsg;
    }
protected function getArchiveWarningMessage($record)
    {

        $defaultMessage = _t('SilverStripe\\CMS\\Controllers\\CMSMain.ArchiveWarningWithChildren', 'Warning: This page and all of its child pages will be unpublished before being sent to the archive.\n\nAre you sure you want to proceed?');

        // Option to disable this feature as it is slow on large sites
        if (!$this->config()->enable_dynamic_archive_warning_message) {
            return $defaultMessage;
        }

        // Get all page's descendants
        $descendants = [];
        $this->collateDescendants([$record->ID], $descendants);
        if (!$descendants) {
            $descendants = [];
        }

        // Get the IDs of all changeset including at least one of the pages.
        $descendants[] = $record->ID;
        $inChangeSetIDs = ChangeSetItem::get()->filter([
            'ObjectID' => $descendants,
            'ObjectClass' => SiteTree::class
        ])->column('ChangeSetID');

        // Count number of affected change set
        $affectedChangeSetCount = 0;
        if (count($inChangeSetIDs) > 0) {
            $affectedChangeSetCount = ChangeSet::get()
                ->filter(['ID' => $inChangeSetIDs, 'State' => ChangeSet::STATE_OPEN])
                ->count();
        }

        $numCampaigns = ChangeSet::singleton()->i18n_pluralise($affectedChangeSetCount);
        $numCampaigns = mb_strtolower($numCampaigns);

        if (count($descendants) > 0 && $affectedChangeSetCount > 0) {
            $archiveWarningMsg = _t('SilverStripe\\CMS\\Controllers\\CMSMain.ArchiveWarningWithChildrenAndCampaigns', 'Warning: This page and all of its child pages will be unpublished and automatically removed from their associated {NumCampaigns} before being sent to the archive.\n\nAre you sure you want to proceed?', [ 'NumCampaigns' => $numCampaigns ]);
        } elseif (count($descendants) > 0) {
            $archiveWarningMsg = $defaultMessage;
        } elseif ($inChangeSets->count() > 0) {
            $archiveWarningMsg = _t('SilverStripe\\CMS\\Controllers\\CMSMain.ArchiveWarningWithChildren', 'Warning: This page and all of its child pages will be unpublished before being sent to the archive.\n\nAre you sure you want to proceed?');
        } elseif ($affectedChangeSetCount > 0) {
            $archiveWarningMsg = _t('SilverStripe\\CMS\\Controllers\\CMSMain.ArchiveWarningWithCampaigns', 'Warning: This page will be unpublished and automatically removed from their associated {NumCampaigns} before being sent to the archive.\n\nAre you sure you want to proceed?', [ 'NumCampaigns' => $numCampaigns ]);
        } else {
            $archiveWarningMsg = _t('SilverStripe\\CMS\\Controllers\\CMSMain.ArchiveWarning', 'Warning: This page will be unpublished before being sent to the archive.\n\nAre you sure you want to proceed?');
        }

        return $archiveWarningMsg;
    }
protected function getArchiveWarningMessage ( $ record ) { $ defaultMessage = _t ( 'SilverStripe\\CMS\\Controllers\\CMSMain.ArchiveWarningWithChildren' , 'Warning: This page and all of its child pages will be unpublished before being sent to the archive.\n\nAre you sure you want to proceed?' ) ; // Option to disable this feature as it is slow on large sites if ( ! $ this -> config ( ) -> enable_dynamic_archive_warning_message ) { return $ defaultMessage ; } // Get all page's descendants $ descendants = [ ] ; $ this -> collateDescendants ( [ $ record -> ID ] , $ descendants ) ; if ( ! $ descendants ) { $ descendants = [ ] ; } // Get the IDs of all changeset including at least one of the pages. $ descendants [ ] = $ record -> ID ; $ inChangeSetIDs = ChangeSetItem :: get ( ) -> filter ( [ 'ObjectID' => $ descendants , 'ObjectClass' => SiteTree :: class ] ) -> column ( 'ChangeSetID' ) ; // Count number of affected change set $ affectedChangeSetCount = 0 ; if ( count ( $ inChangeSetIDs ) > 0 ) { $ affectedChangeSetCount = ChangeSet :: get ( ) -> filter ( [ 'ID' => $ inChangeSetIDs , 'State' => ChangeSet :: STATE_OPEN ] ) -> count ( ) ; } $ numCampaigns = ChangeSet :: singleton ( ) -> i18n_pluralise ( $ affectedChangeSetCount ) ; $ numCampaigns = mb_strtolower ( $ numCampaigns ) ; if ( count ( $ descendants ) > 0 && $ affectedChangeSetCount > 0 ) { $ archiveWarningMsg = _t ( 'SilverStripe\\CMS\\Controllers\\CMSMain.ArchiveWarningWithChildrenAndCampaigns' , 'Warning: This page and all of its child pages will be unpublished and automatically removed from their associated {NumCampaigns} before being sent to the archive.\n\nAre you sure you want to proceed?' , [ 'NumCampaigns' => $ numCampaigns ] ) ; } elseif ( count ( $ descendants ) > 0 ) { $ archiveWarningMsg = $ defaultMessage ; } elseif ( $ inChangeSets -> count ( ) > 0 ) { $ archiveWarningMsg = _t ( 'SilverStripe\\CMS\\Controllers\\CMSMain.ArchiveWarningWithChildren' , 'Warning: This page and all of its child pages will be unpublished before being sent to the archive.\n\nAre you sure you want to proceed?' ) ; } elseif ( $ affectedChangeSetCount > 0 ) { $ archiveWarningMsg = _t ( 'SilverStripe\\CMS\\Controllers\\CMSMain.ArchiveWarningWithCampaigns' , 'Warning: This page will be unpublished and automatically removed from their associated {NumCampaigns} before being sent to the archive.\n\nAre you sure you want to proceed?' , [ 'NumCampaigns' => $ numCampaigns ] ) ; } else { $ archiveWarningMsg = _t ( 'SilverStripe\\CMS\\Controllers\\CMSMain.ArchiveWarning' , 'Warning: This page will be unpublished before being sent to the archive.\n\nAre you sure you want to proceed?' ) ; } return $ archiveWarningMsg ; }
Build an archive warning message based on the page's children

@param SiteTree $record
@return string
Build an archive warning message based on the page s children