Completed
Pull Request — master (#1703)
by Robbie
02:24
created

RedirectorPageController::init()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 2
nop 0
1
<?php
2
namespace SilverStripe\CMS\Model;
3
4
use PageController;
5
6
/**
7
 * Controller for the {@link RedirectorPage}.
8
 */
9
class RedirectorPageController extends PageController
10
{
11
12
	public function init()
13
	{
14
		parent::init();
15
16
		// Check we don't already have a redirect code set
17
		/** @var RedirectorPage $page */
18
		$page = $this->data();
19
		if (!$this->getResponse()->isFinished() && $link = $page->redirectionLink()) {
20
			$this->redirect($link, 301);
21
		}
22
	}
23
24
	/**
25
	 * If we ever get this far, it means that the redirection failed.
26
	 */
27
	public function Content()
28
	{
29
		return "<p class=\"message-setupWithoutRedirect\">" .
30
		_t('RedirectorPage.HASBEENSETUP', 'A redirector page has been set up without anywhere to redirect to.') .
31
		"</p>";
32
	}
33
}
34