From 482c23f18e2cd33766ff762ae5bcb4f3d4e6f074 Mon Sep 17 00:00:00 2001 From: Stig Lindqvist Date: Mon, 28 Jul 2014 18:57:09 +1200 Subject: [PATCH] NEW Adding CMS sitetree filter to see the current 'live' site This adds a new filter that will show a content editor what the current published site-tree looks like for a visitor. This helps when there is a lot of drafted content that get included in the default filter 'All Pages' --- code/controllers/CMSSiteTreeFilter.php | 41 +++++++++++++++++++ .../behat/features/search-for-a-page.feature | 15 +++++++ 2 files changed, 56 insertions(+) diff --git a/code/controllers/CMSSiteTreeFilter.php b/code/controllers/CMSSiteTreeFilter.php index 54423f3b..1c13947f 100644 --- a/code/controllers/CMSSiteTreeFilter.php +++ b/code/controllers/CMSSiteTreeFilter.php @@ -202,6 +202,47 @@ abstract class CMSSiteTreeFilter extends Object { } } +/** + * This filter will display the SiteTree as a site visitor might see the site, i.e only the + * pages that is currently published. + * + * Note that this does not check canView permissions that might hide pages from certain visitors + */ +class CMSSIteTreeFilter_PublishedPages extends CMSSiteTreeFilter { + + /** + * @return string + */ + static public function title() { + return _t('CMSSIteTreeFilter_PublishedPages.Title', "Published pages"); + } + + /** + * @var string + */ + protected $childrenMethod = "AllHistoricalChildren"; + + /** + * @var string + */ + protected $numChildrenMethod = 'numHistoricalChildren'; + + /** + * Filters out all pages who's status who's status that doesn't exist on live + * + * @see {@link SiteTree::getStatusFlags()} + * @return array + */ + public function pagesIncluded() { + $pages = Versioned::get_including_deleted('SiteTree'); + $pages = $this->applyDefaultFilters($pages); + $pages = $pages->filterByCallback(function($page) { + return $page->ExistsOnLive; + }); + return $this->mapIDs($pages); + } +} + /** * Works a bit different than the other filters: * Shows all pages *including* those deleted from stage and live. diff --git a/tests/behat/features/search-for-a-page.feature b/tests/behat/features/search-for-a-page.feature index e48c2967..5d799160 100644 --- a/tests/behat/features/search-for-a-page.feature +++ b/tests/behat/features/search-for-a-page.feature @@ -96,3 +96,18 @@ Feature: Search for a page And I press the "Apply Filter" button Then I should see "Live Page" in the tree And I should not see "About Us" in the tree + + Scenario: I can include only live pages in my search + Given a "page" "Live Page" + And the "page" "Live Page" is published + And a "page" "Draft Page" + And a "page" "Draft Page" is unpublished + And a "page" "Deleted Page" + And the "page" "Deleted Page" is unpublished + And the "page" "Deleted Page" is deleted + + When I select "Published pages" from "Pages" + And I press the "Apply Filter" button + Then I should not see "Draft Page" in the tree + And I should not see "Deleted Page" in the tree + But I should see "Live Page" in the tree \ No newline at end of file