From f88d4006f8b75bc13e334afeebf9b4398728bd4b Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 14 Feb 2012 16:01:07 +0100 Subject: [PATCH] ENHANCEMENT CMSMain->Breadcrumbs() --- code/controllers/CMSMain.php | 14 ++++++++++++++ templates/Includes/AssetAdmin_Content.ss | 4 +++- .../Includes/CMSPagesController_Content.ss | 4 +++- tests/controller/CMSMainTest.php | 19 +++++++++++++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/code/controllers/CMSMain.php b/code/controllers/CMSMain.php index 50e9da9a..fff249c8 100644 --- a/code/controllers/CMSMain.php +++ b/code/controllers/CMSMain.php @@ -222,6 +222,20 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr return $this->getsubtree($this->request); } + /** + * @return ArrayList + */ + public function Breadcrumbs($unlinked = false) { + $items = parent::Breadcrumbs($unlinked); + + // The root element should point to the pages tree view, + // rather than the actual controller (which would just show an empty edit form) + $items[0]->Title = self::menu_title_for_class('CMSPagesController'); + $items[0]->Link = singleton('CMSPagesController')->Link(); + + return $items; + } + /** * Create serialized JSON string with site tree hints data to be injected into * 'data-hints' attribute of root node of jsTree. diff --git a/templates/Includes/AssetAdmin_Content.ss b/templates/Includes/AssetAdmin_Content.ss index a6c9d0b1..c647b543 100644 --- a/templates/Includes/AssetAdmin_Content.ss +++ b/templates/Includes/AssetAdmin_Content.ss @@ -2,7 +2,9 @@
-

<% _t('AssetAdmin.Title', 'Find & Organize') %>

+

+ <% include CMSBreadcrumbs %> +

  • diff --git a/templates/Includes/CMSPagesController_Content.ss b/templates/Includes/CMSPagesController_Content.ss index 096f21b8..d6de0d21 100644 --- a/templates/Includes/CMSPagesController_Content.ss +++ b/templates/Includes/CMSPagesController_Content.ss @@ -2,7 +2,9 @@
    -

    <% _t('CMSPagesController.Title','Edit & Organize') %>

    +

    + <% include CMSBreadcrumbs %> +

      diff --git a/tests/controller/CMSMainTest.php b/tests/controller/CMSMainTest.php index c68f850c..1f4c0d33 100644 --- a/tests/controller/CMSMainTest.php +++ b/tests/controller/CMSMainTest.php @@ -221,4 +221,23 @@ class CMSMainTest extends FunctionalTest { // TODO Logout $this->session()->inst_set('loggedInAs', NULL); } + + function testBreadcrumbs() { + $page3 = $this->objFromFixture('Page', 'page3'); + $page31 = $this->objFromFixture('Page', 'page31'); + $adminuser = $this->objFromFixture('Member', 'admin'); + $this->session()->inst_set('loggedInAs', $adminuser->ID); + + $response = $this->get('admin/page/edit/show/' . $page31->ID); + $parser = new CSSContentParser($response->getBody()); + $crumbs = $parser->getBySelector('#page-title-heading .crumb'); + + $this->assertNotNull($crumbs); + $this->assertEquals(3, count($crumbs)); + $this->assertEquals('Pages', (string)$crumbs[0]); + $this->assertEquals('Page 3', (string)$crumbs[1]); + $this->assertEquals('Page 3.1', (string)$crumbs[2]); + + $this->session()->inst_set('loggedInAs', null); + } }