Merge pull request #1863 from robbieaverill/pulls/4.0/allow-redirectorpage-actions

FIX Allow RedirectorPage to have non-redirected actions, move redirection to index
This commit is contained in:
Daniel Hensby 2017-07-19 18:09:57 +01:00 committed by GitHub
commit e38a0c49dd
1 changed files with 12 additions and 6 deletions

View File

@ -1,6 +1,7 @@
<?php
namespace SilverStripe\CMS\Model;
use SilverStripe\Control\HTTPRequest;
use PageController;
/**
@ -8,26 +9,31 @@ use 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 */
$page = $this->data();
if (!$this->getResponse()->isFinished() && $link = $page->redirectionLink()) {
$this->redirect($link, 301);
}
return parent::handleAction($request, 'handleIndex');
}
/**
* If we ever get this far, it means that the redirection failed.
*/
public function Content()
public function getContent()
{
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>";
}
}