Completed
Branch PSR2 (143732)
by Gordon
03:07
created
code/TemplateOverrideExtension.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -6,22 +6,22 @@
 block discarded – undo
6 6
 */
7 7
 class TemplateOverrideExtension extends DataExtension
8 8
 {
9
-    private static $db = array('AlternativeTemplate' => 'Varchar');
9
+	private static $db = array('AlternativeTemplate' => 'Varchar');
10 10
 
11
-    public function updateCMSFields(FieldList $fields)
12
-    {
13
-        $templatei18n = _t('TemplateOverride.TEMPLATE', 'Template');
14
-        $fields->addFieldToTab('Root.'.$templatei18n, new TextField('AlternativeTemplate',
15
-                _t('TemplateOverride.ALTERNATIVE_TEMPLATE_NAME', 'Alternative template name')));
11
+	public function updateCMSFields(FieldList $fields)
12
+	{
13
+		$templatei18n = _t('TemplateOverride.TEMPLATE', 'Template');
14
+		$fields->addFieldToTab('Root.'.$templatei18n, new TextField('AlternativeTemplate',
15
+				_t('TemplateOverride.ALTERNATIVE_TEMPLATE_NAME', 'Alternative template name')));
16 16
 
17
-        $info_field = new LiteralField(
18
-            $name = 'infofield',
19
-            $content = '<p class="message">'._t('TemplateOverride.INFO', 'If you wish to change'.
20
-                        ' the default template, type the name of the template here.  Otherwise '.
21
-                        ' the normal default template will be used.  Normally this will not '.
22
-                        ' require changing.').'</p>'
23
-        );
17
+		$info_field = new LiteralField(
18
+			$name = 'infofield',
19
+			$content = '<p class="message">'._t('TemplateOverride.INFO', 'If you wish to change'.
20
+						' the default template, type the name of the template here.  Otherwise '.
21
+						' the normal default template will be used.  Normally this will not '.
22
+						' require changing.').'</p>'
23
+		);
24 24
 
25
-        $fields->addFieldToTab('Root.'.$templatei18n, $info_field);
26
-    }
25
+		$fields->addFieldToTab('Root.'.$templatei18n, $info_field);
26
+	}
27 27
 }
Please login to merge, or discard this patch.
code/PageControllerTemplateOverrideExtension.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -2,35 +2,35 @@
 block discarded – undo
2 2
 
3 3
 class PageControllerTemplateOverrideExtension extends Extension
4 4
 {
5
-    /*
5
+	/*
6 6
     If the alternative template exists, render that, otherwise render with the default template
7 7
     */
8
-    public function index()
9
-    {
10
-        return $this->useTemplateOverride();
11
-    }
8
+	public function index()
9
+	{
10
+		return $this->useTemplateOverride();
11
+	}
12 12
 
13
-    /**
14
-     * Render this page using the template override iff it exists.
15
-     *
16
-     * @return array An array suitable for SilverStripe to use the correct template
17
-     */
18
-    public function useTemplateOverride($data = null)
19
-    {
20
-        $template = $this->owner->AlternativeTemplate;
21
-        if (isset($template) && $template != '') {
22
-            if ($data) {
23
-                return $this->owner->customise(new ArrayData($data))
24
-                        ->renderWith(array($this->owner->AlternativeTemplate, $this->owner->ClassName, 'Page'));
25
-            } else {
26
-                return $this->owner->renderWith(array($this->owner->AlternativeTemplate, $this->owner->ClassName, 'Page'));
27
-            }
28
-        } else {
29
-            if ($data) {
30
-                return $data;
31
-            } else {
32
-                return array();
33
-            }
34
-        }
35
-    }
13
+	/**
14
+	 * Render this page using the template override iff it exists.
15
+	 *
16
+	 * @return array An array suitable for SilverStripe to use the correct template
17
+	 */
18
+	public function useTemplateOverride($data = null)
19
+	{
20
+		$template = $this->owner->AlternativeTemplate;
21
+		if (isset($template) && $template != '') {
22
+			if ($data) {
23
+				return $this->owner->customise(new ArrayData($data))
24
+						->renderWith(array($this->owner->AlternativeTemplate, $this->owner->ClassName, 'Page'));
25
+			} else {
26
+				return $this->owner->renderWith(array($this->owner->AlternativeTemplate, $this->owner->ClassName, 'Page'));
27
+			}
28
+		} else {
29
+			if ($data) {
30
+				return $data;
31
+			} else {
32
+				return array();
33
+			}
34
+		}
35
+	}
36 36
 }
Please login to merge, or discard this patch.
tests/PageControllerTemplateOverrideExtensionTest.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -2,51 +2,51 @@
 block discarded – undo
2 2
 
3 3
 class PageControllerTemplateOverrideExtensionTest extends FunctionalTest
4 4
 {
5
-    protected static $fixture_file = 'template-override/tests/pages.yml';
5
+	protected static $fixture_file = 'template-override/tests/pages.yml';
6 6
 
7
-    public function testLayoutTemplateOveride()
8
-    {
9
-        $this->logInWithPermission('ADMIN');
10
-        $page = $this->objFromFixture('Page', 'page1');
11
-        $page->AlternativeTemplate = 'PageInnerTest';
12
-        $page->write();
13
-        $page->doPublish();
14
-        $response = $this->get('/'.$page->URLSegment);
15
-        $this->assertEquals(200, $response->getStatusCode());
7
+	public function testLayoutTemplateOveride()
8
+	{
9
+		$this->logInWithPermission('ADMIN');
10
+		$page = $this->objFromFixture('Page', 'page1');
11
+		$page->AlternativeTemplate = 'PageInnerTest';
12
+		$page->write();
13
+		$page->doPublish();
14
+		$response = $this->get('/'.$page->URLSegment);
15
+		$this->assertEquals(200, $response->getStatusCode());
16 16
 
17
-        // assert the the inner layout template has been used
18
-        $this->assertExactMatchBySelector('div.marker', array(
19
-            'INNER LAYOUT',
20
-        ));
21
-    }
17
+		// assert the the inner layout template has been used
18
+		$this->assertExactMatchBySelector('div.marker', array(
19
+			'INNER LAYOUT',
20
+		));
21
+	}
22 22
 
23
-    public function testOuterTemplateOveride()
24
-    {
25
-        $this->logInWithPermission('ADMIN');
26
-        $page = $this->objFromFixture('Page', 'page1');
27
-        $page->AlternativeTemplate = 'PageOuterTest';
28
-        $page->write();
29
-        $page->doPublish();
30
-        $response = $this->get('/'.$page->URLSegment);
31
-        $this->assertEquals(200, $response->getStatusCode());
23
+	public function testOuterTemplateOveride()
24
+	{
25
+		$this->logInWithPermission('ADMIN');
26
+		$page = $this->objFromFixture('Page', 'page1');
27
+		$page->AlternativeTemplate = 'PageOuterTest';
28
+		$page->write();
29
+		$page->doPublish();
30
+		$response = $this->get('/'.$page->URLSegment);
31
+		$this->assertEquals(200, $response->getStatusCode());
32 32
 
33
-        // show the the outer layout template has been used
34
-        $this->assertExactMatchBySelector('div.marker', array(
35
-            'OUTER OF LAYOUT',
36
-        ));
37
-    }
33
+		// show the the outer layout template has been used
34
+		$this->assertExactMatchBySelector('div.marker', array(
35
+			'OUTER OF LAYOUT',
36
+		));
37
+	}
38 38
 
39
-    public function testNoTemplateOverride()
40
-    {
41
-        $this->logInWithPermission('ADMIN');
42
-        $page = $this->objFromFixture('Page', 'page1');
43
-        $page->AlternativeTemplate = null;
44
-        $page->write();
45
-        $page->doPublish();
46
-        $response = $this->get('/'.$page->URLSegment);
47
-        $this->assertEquals(200, $response->getStatusCode());
48
-        $body = $response->getBody();
49
-        $this->assertNotContains('OUTER OF LAYOUT', $body);
50
-        $this->assertNotContains('INNER LAYOUT', $body);
51
-    }
39
+	public function testNoTemplateOverride()
40
+	{
41
+		$this->logInWithPermission('ADMIN');
42
+		$page = $this->objFromFixture('Page', 'page1');
43
+		$page->AlternativeTemplate = null;
44
+		$page->write();
45
+		$page->doPublish();
46
+		$response = $this->get('/'.$page->URLSegment);
47
+		$this->assertEquals(200, $response->getStatusCode());
48
+		$body = $response->getBody();
49
+		$this->assertNotContains('OUTER OF LAYOUT', $body);
50
+		$this->assertNotContains('INNER LAYOUT', $body);
51
+	}
52 52
 }
Please login to merge, or discard this patch.
tests/TemplateOverrideExtensionTest.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -2,19 +2,19 @@
 block discarded – undo
2 2
 
3 3
 class TemplateOverrideExtensionTest extends SapphireTest
4 4
 {
5
-    protected static $fixture_file = 'template-override/tests/pages.yml';
5
+	protected static $fixture_file = 'template-override/tests/pages.yml';
6 6
 
7
-    public function testUpdateCMSFields()
8
-    {
9
-        $page = $this->objFromFixture('Page', 'page1');
10
-        $fields = $page->getCMSFields();
11
-        $tab = $fields->findOrMakeTab('Root.Template');
12
-        $fields = $tab->FieldList();
13
-        $names = array();
14
-        foreach ($fields as $field) {
15
-            $names[] = $field->getName();
16
-        }
17
-        $expected = array('AlternativeTemplate', 'infofield');
18
-        $this->assertEquals($expected, $names);
19
-    }
7
+	public function testUpdateCMSFields()
8
+	{
9
+		$page = $this->objFromFixture('Page', 'page1');
10
+		$fields = $page->getCMSFields();
11
+		$tab = $fields->findOrMakeTab('Root.Template');
12
+		$fields = $tab->FieldList();
13
+		$names = array();
14
+		foreach ($fields as $field) {
15
+			$names[] = $field->getName();
16
+		}
17
+		$expected = array('AlternativeTemplate', 'infofield');
18
+		$this->assertEquals($expected, $names);
19
+	}
20 20
 }
Please login to merge, or discard this patch.