Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX Do not update LeftAndMain link with Stage param #173

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/VersionedStateExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SilverStripe\Versioned;

use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Control\Controller;
use SilverStripe\Control\RequestHandler;
use SilverStripe\Core\Extension;
Expand Down Expand Up @@ -48,6 +49,11 @@ public function updateLink(&$link)
return;
}

// Don't touch Admin/CMS links
if (class_exists(LeftAndMain::class) && $this->getOwner() instanceof LeftAndMain) {
return;
}

// Decorate
$link = Controller::join_links(
$link,
Expand Down
16 changes: 16 additions & 0 deletions tests/php/VersionedStateExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SilverStripe\Versioned\Tests;

use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Versioned\Versioned;
use SilverStripe\Versioned\VersionedStateExtension;
Expand Down Expand Up @@ -61,4 +62,19 @@ public function testUpdateLinkRespectsQueryArgs()
->byID($obj1ID);
$this->assertEquals('item/myobject/', $obj1Live->Link());
}

public function testDontUpdateLeftAndMainLinks()
{
$controller = new LeftAndMain();

$liveClientConfig = $controller->getClientConfig();
Versioned::set_stage(Versioned::DRAFT);
$stageClientConfig = $controller->getClientConfig();

$this->assertEquals(
$liveClientConfig,
$stageClientConfig,
'LeftAndMain Client config should not be affected by versionned stage.'
);
}
}