Merge branch '4.1' into 4

This commit is contained in:
Daniel Hensby 2018-02-21 14:02:52 +00:00
commit d02c15150b
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E
17 changed files with 130 additions and 52 deletions

View File

@ -992,6 +992,9 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
'Title' => CMSPagesController::menu_title(),
'Link' => ($unlinked) ? false : $this->LinkPages()
)));
$this->extend('updateBreadcrumbs', $items);
return $items;
}
@ -1009,6 +1012,8 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
)));
}
$this->extend('updateBreadcrumbs', $items);
return $items;
}

View File

@ -4,6 +4,7 @@ namespace SilverStripe\CMS\Controllers;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Controller;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataObject;
use SilverStripe\View\ArrayData;
use stdClass;
@ -33,33 +34,32 @@ class CMSPagesController extends CMSMain
public function Breadcrumbs($unlinked = false)
{
$items = parent::Breadcrumbs($unlinked);
$this->beforeExtending('updateBreadcrumbs', function (ArrayList $items) {
//special case for building the breadcrumbs when calling the listchildren Pages ListView action
if ($parentID = $this->getRequest()->getVar('ParentID')) {
$page = SiteTree::get()->byID($parentID);
//special case for building the breadcrumbs when calling the listchildren Pages ListView action
if ($parentID = $this->getRequest()->getVar('ParentID')) {
$page = SiteTree::get()->byID($parentID);
//build a reversed list of the parent tree
$pages = array();
while ($page) {
array_unshift($pages, $page); //add to start of array so that array is in reverse order
$page = $page->Parent;
}
//build a reversed list of the parent tree
$pages = array();
while ($page) {
array_unshift($pages, $page); //add to start of array so that array is in reverse order
$page = $page->Parent;
//turns the title and link of the breadcrumbs into template-friendly variables
$params = array_filter(array(
'view' => $this->getRequest()->getVar('view'),
'q' => $this->getRequest()->getVar('q')
));
foreach ($pages as $page) {
$params['ParentID'] = $page->ID;
$item = new stdClass();
$item->Title = $page->Title;
$item->Link = Controller::join_links($this->Link(), '?' . http_build_query($params));
$items->push(new ArrayData($item));
}
}
//turns the title and link of the breadcrumbs into template-friendly variables
$params = array_filter(array(
'view' => $this->getRequest()->getVar('view'),
'q' => $this->getRequest()->getVar('q')
));
foreach ($pages as $page) {
$params['ParentID'] = $page->ID;
$item = new stdClass();
$item->Title = $page->Title;
$item->Link = Controller::join_links($this->Link(), '?' . http_build_query($params));
$items->push(new ArrayData($item));
}
}
return $items;
});
return parent::Breadcrumbs($unlinked);
}
}

View File

@ -13,7 +13,7 @@ class CMSSiteTreeFilter_ChangedPages extends CMSSiteTreeFilter
public static function title()
{
return _t('SilverStripe\\CMS\\Controllers\\CMSSiteTreeFilter_ChangedPages.Title', "Modified pages");
return _t(__CLASS__ . '.Title', "Modified pages");
}
public function getFilteredPages()

View File

@ -25,7 +25,7 @@ class CMSSiteTreeFilter_DeletedPages extends CMSSiteTreeFilter
public static function title()
{
return _t('SilverStripe\\CMS\\Controllers\\CMSSiteTreeFilter_DeletedPages.Title', "All pages, including archived");
return _t(__CLASS__ . '.Title', "All pages, including archived");
}
public function getFilteredPages()

View File

@ -20,7 +20,7 @@ class CMSSiteTreeFilter_PublishedPages extends CMSSiteTreeFilter
*/
public static function title()
{
return _t('SilverStripe\\CMS\\Controllers\\CMSSIteTreeFilter_PublishedPages.Title', "Published pages");
return _t(__CLASS__ . '.Title', "Published pages");
}
/**

View File

@ -1,4 +1,5 @@
<?php
namespace SilverStripe\CMS\Controllers;
use SilverStripe\CMS\Model\SiteTree;
@ -10,7 +11,7 @@ class CMSSiteTreeFilter_Search extends CMSSiteTreeFilter
public static function title()
{
return _t('SilverStripe\\CMS\\Controllers\\CMSSiteTreeFilter_Search.Title', "All pages");
return _t(__CLASS__ . '.Title', "All pages");
}
/**

View File

@ -24,7 +24,7 @@ class CMSSiteTreeFilter_StatusDeletedPages extends CMSSiteTreeFilter
public static function title()
{
return _t('SilverStripe\\CMS\\Controllers\\CMSSiteTreeFilter_StatusDeletedPages.Title', 'Archived pages');
return _t(__CLASS__ . '.Title', 'Archived pages');
}
/**

View File

@ -14,7 +14,7 @@ class CMSSiteTreeFilter_StatusDraftPages extends CMSSiteTreeFilter
public static function title()
{
return _t('SilverStripe\\CMS\\Controllers\\CMSSiteTreeFilter_StatusDraftPages.Title', 'Draft pages');
return _t(__CLASS__ . '.Title', 'Draft pages');
}
/**

View File

@ -14,7 +14,7 @@ class CMSSiteTreeFilter_StatusRemovedFromDraftPages extends CMSSiteTreeFilter
public static function title()
{
return _t('SilverStripe\\CMS\\Controllers\\CMSSiteTreeFilter_StatusRemovedFromDraftPages.Title', 'Live but removed from draft');
return _t(__CLASS__ . '.Title', 'Live but removed from draft');
}
/**

View File

@ -121,22 +121,23 @@ abstract class SilverStripeNavigatorItem extends ViewableData
*/
public function isArchived()
{
$recordClass = get_class($this->record);
if (!$recordClass::has_extension(Versioned::class)) {
/** @var Versioned|DataObject $record */
$record = $this->record;
if (!$record->hasExtension(Versioned::class) || !$record->hasStages()) {
return false;
}
if (!isset($this->record->_cached_isArchived)) {
$baseClass = $this->record->baseClass();
$currentDraft = Versioned::get_by_stage($baseClass, Versioned::DRAFT)->byID($this->record->ID);
$currentLive = Versioned::get_by_stage($baseClass, Versioned::LIVE)->byID($this->record->ID);
if (!isset($record->_cached_isArchived)) {
$baseClass = $record->baseClass();
$currentDraft = Versioned::get_by_stage($baseClass, Versioned::DRAFT)->byID($record->ID);
$currentLive = Versioned::get_by_stage($baseClass, Versioned::LIVE)->byID($record->ID);
$this->record->_cached_isArchived = (
(!$currentDraft || ($currentDraft && $this->record->Version != $currentDraft->Version))
&& (!$currentLive || ($currentLive && $this->record->Version != $currentLive->Version))
$record->_cached_isArchived = (
(!$currentDraft || ($currentDraft && $record->Version != $currentDraft->Version))
&& (!$currentLive || ($currentLive && $record->Version != $currentLive->Version))
);
}
return $this->record->_cached_isArchived;
return $record->_cached_isArchived;
}
}

View File

@ -4,6 +4,7 @@ namespace SilverStripe\CMS\Controllers;
use SilverStripe\CMS\Model\RedirectorPage;
use SilverStripe\Control\Controller;
use SilverStripe\Core\Convert;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\Versioned\Versioned;
@ -53,12 +54,14 @@ class SilverStripeNavigatorItem_ArchiveLink extends SilverStripeNavigatorItem
public function canView($member = null)
{
$recordClass = get_class($this->record);
/** @var Versioned|DataObject $record */
$record = $this->record;
return (
$recordClass::has_extension(Versioned::class)
$record->hasExtension(Versioned::class)
&& $record->hasStages()
&& $this->isArchived()
// Don't follow redirects in preview, they break the CMS editing form
&& !($this->record instanceof RedirectorPage)
&& !($record instanceof RedirectorPage)
);
}

View File

@ -4,6 +4,7 @@ namespace SilverStripe\CMS\Controllers;
use SilverStripe\CMS\Model\RedirectorPage;
use SilverStripe\Control\Controller;
use SilverStripe\Core\Convert;
use SilverStripe\ORM\DataObject;
use SilverStripe\Versioned\Versioned;
class SilverStripeNavigatorItem_LiveLink extends SilverStripeNavigatorItem
@ -51,9 +52,11 @@ class SilverStripeNavigatorItem_LiveLink extends SilverStripeNavigatorItem
public function canView($member = null)
{
$recordClass = get_class($this->record);
/** @var Versioned|DataObject $record */
$record = $this->record;
return (
$recordClass::has_extension(Versioned::class)
$record->hasExtension(Versioned::class)
&& $record->hasStages()
&& $this->getLivePage()
// Don't follow redirects in preview, they break the CMS editing form
&& !($this->record instanceof RedirectorPage)

View File

@ -5,6 +5,7 @@ use SilverStripe\CMS\Model\RedirectorPage;
use SilverStripe\Control\Controller;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Convert;
use SilverStripe\ORM\DataObject;
use SilverStripe\Versioned\Versioned;
use SiteTreeFutureState;
@ -57,11 +58,14 @@ class SilverStripeNavigatorItem_StageLink extends SilverStripeNavigatorItem
public function canView($member = null)
{
/** @var Versioned|DataObject $record */
$record = $this->record;
return (
$this->record->hasExtension(Versioned::class)
$record->hasExtension(Versioned::class)
&& $record->hasStages()
&& $this->getDraftPage()
// Don't follow redirects in preview, they break the CMS editing form
&& !($this->record instanceof RedirectorPage)
&& !($record instanceof RedirectorPage)
);
}

View File

@ -58,7 +58,7 @@ en:
ROLLEDBACKPUBv2: 'Rolled back to published version.'
ROLLEDBACKVERSIONv2: 'Rolled back to version #{version}.'
SAVED: 'Saved ''{title}'' successfully.'
SAVEDRAFT: 'Save'
SAVEDRAFT: Save
SHOW_AS_LIST: 'show as list'
TOO_MANY_PAGES: 'Too many pages'
TabContent: Content
@ -180,7 +180,7 @@ en:
BUTTONDELETEDESC: 'Remove from draft/live and send to archive'
BUTTONPUBLISHED: Published
BUTTONSAVED: Saved
BUTTONSAVEPUBLISH: 'Publish'
BUTTONSAVEPUBLISH: Publish
BUTTONUNPUBLISH: Unpublish
BUTTONUNPUBLISHDESC: 'Remove this page from the published site'
Comments: Comments

View File

@ -2,6 +2,7 @@
namespace SilverStripe\CMS\Tests\Controllers;
use Page;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Versioned\Versioned;
use SilverStripe\CMS\Controllers\CMSSiteTreeFilter_Search;
@ -65,14 +66,17 @@ class CMSSiteTreeFilterTest extends SapphireTest
public function testChangedPagesFilter()
{
/** @var Page $unchangedPage */
$unchangedPage = $this->objFromFixture('Page', 'page1');
$unchangedPage->publishRecursive();
/** @var Page $changedPage */
$changedPage = $this->objFromFixture('Page', 'page2');
$changedPage->Title = 'Original';
$changedPage->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$changedPage->Title = 'Changed';
$changedPage->write();
$changedPageVersion = $changedPage->Version;
// Check that only changed pages are returned
$f = new CMSSiteTreeFilter_ChangedPages(array('Term' => 'Changed'));
@ -93,8 +97,9 @@ class CMSSiteTreeFilterTest extends SapphireTest
// If we roll back to an earlier version than what's on the published site, we should still show the changed
$changedPage->Title = 'Changed 2';
$changedPage->write();
$changedPage->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$changedPage->doRollbackTo(1);
$changedPage->doRollbackTo($changedPageVersion);
$f = new CMSSiteTreeFilter_ChangedPages(array('Term' => 'Changed'));
$results = $f->pagesIncluded();

View File

@ -3,6 +3,8 @@
namespace SilverStripe\CMS\Tests\Controllers;
use SilverStripe\CMS\Controllers\SilverStripeNavigator;
use SilverStripe\CMS\Controllers\SilverStripeNavigatorItem_ArchiveLink;
use SilverStripe\CMS\Controllers\SilverStripeNavigatorItem_LiveLink;
use SilverStripe\CMS\Controllers\SilverStripeNavigatorItem_StageLink;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Security\Member;
@ -11,6 +13,10 @@ class SilverStripeNavigatorTest extends SapphireTest
{
protected static $fixture_file = 'CMSMainTest.yml';
protected static $extra_dataobjects = [
SilverStripeNavigatorTest\UnstagedRecord::class,
];
public function testGetItems()
{
$page = $this->objFromFixture('Page', 'page1');
@ -29,6 +35,8 @@ class SilverStripeNavigatorTest extends SapphireTest
$classes,
'Autodiscovers new classes'
);
// Non-versioned items don't have stage / live
}
public function testCanView()
@ -47,5 +55,13 @@ class SilverStripeNavigatorTest extends SapphireTest
$items = $navigator->getItems();
$classes = array_map('get_class', $items->toArray());
$this->assertContains(SilverStripeNavigatorTest_ProtectedTestItem::class, $classes);
// Unversioned record shouldn't be viewable in stage / live specific views
$unversioned = new SilverStripeNavigatorTest\UnstagedRecord();
$navigator2 = new SilverStripeNavigator($unversioned);
$classes = array_map('get_class', $navigator2->getItems()->toArray());
$this->assertNotContains(SilverStripeNavigatorItem_LiveLink::class, $classes);
$this->assertNotContains(SilverStripeNavigatorItem_StageLink::class, $classes);
$this->assertNotContains(SilverStripeNavigatorItem_ArchiveLink::class, $classes);
}
}

View File

@ -0,0 +1,40 @@
<?php
namespace SilverStripe\CMS\Tests\Controllers\SilverStripeNavigatorTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\CMSPreviewable;
use SilverStripe\ORM\DataObject;
use SilverStripe\Versioned\Versioned;
/**
* Versioned but not staged
*/
class UnstagedRecord extends DataObject implements TestOnly, CMSPreviewable
{
private static $table_name = 'SilverStripeNavigatorTest_UnversionedRecord';
private static $extensions = [
Versioned::class . '.versioned',
];
public function PreviewLink($action = null)
{
return null;
}
/**
* To determine preview mechanism (e.g. embedded / iframe)
*
* @return string
*/
public function getMimeType()
{
return 'text/html';
}
public function CMSEditLink()
{
return null;
}
}