FIX Allow RedirectorPage to have non-redirected actions, move redirection to index

This commit is contained in:
Robbie Averill 2017-06-23 10:59:25 +12:00
parent ecbd778547
commit c2ad41ef1b
2 changed files with 12 additions and 7 deletions

View File

@ -1,6 +1,7 @@
<?php <?php
namespace SilverStripe\CMS\Model; namespace SilverStripe\CMS\Model;
use SilverStripe\Control\HTTPRequest;
use PageController; use PageController;
/** /**
@ -8,26 +9,31 @@ use PageController;
*/ */
class RedirectorPageController extends PageController class RedirectorPageController extends PageController
{ {
private static $allowed_actions = ['index'];
protected function init() /**
* Check we don't already have a redirect code set
*
* @param HTTPRequest $request
* @return \SilverStripe\Control\HTTPResponse
*/
public function index(HTTPRequest $request)
{ {
parent::init();
// Check we don't already have a redirect code set
/** @var RedirectorPage $page */ /** @var RedirectorPage $page */
$page = $this->data(); $page = $this->data();
if (!$this->getResponse()->isFinished() && $link = $page->redirectionLink()) { if (!$this->getResponse()->isFinished() && $link = $page->redirectionLink()) {
$this->redirect($link, 301); $this->redirect($link, 301);
} }
return parent::handleAction($request, 'handleIndex');
} }
/** /**
* If we ever get this far, it means that the redirection failed. * If we ever get this far, it means that the redirection failed.
*/ */
public function Content() public function getContent()
{ {
return "<p class=\"message-setupWithoutRedirect\">" . return "<p class=\"message-setupWithoutRedirect\">" .
_t('SilverStripe\\CMS\\Model\\RedirectorPage.HASBEENSETUP', 'A redirector page has been set up without anywhere to redirect to.') . _t(__CLASS__ . '.HASBEENSETUP', 'A redirector page has been set up without anywhere to redirect to.') .
"</p>"; "</p>";
} }
} }

View File

@ -204,4 +204,3 @@ class ContentControllerTest extends FunctionalTest
}); });
} }
} }