Completed
Push — master ( fbacac...628455 )
by Sam
02:56
created
code/controller/SiteConfigLeftAndMain.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -107,7 +107,7 @@
 block discarded – undo
107 107
 	/**
108 108
 	 * Used for preview controls, mainly links which switch between different states of the page.
109 109
 	 *
110
-	 * @return ArrayData
110
+	 * @return SilverStripe\Model\FieldType\DBField
111 111
 	 */
112 112
     public function getSilverStripeNavigator()
113 113
     {
Please login to merge, or discard this patch.
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
 	 *
43 43
 	 * @return Form
44 44
 	 */
45
-    public function getEditForm($id = null, $fields = null)
46
-    {
45
+	public function getEditForm($id = null, $fields = null)
46
+	{
47 47
 		$siteConfig = SiteConfig::current_site_config();
48 48
 		$fields = $siteConfig->getCMSFields();
49 49
 
@@ -84,20 +84,20 @@  discard block
 block discarded – undo
84 84
 		$form->addExtraClass('cms-content center cms-edit-form');
85 85
 		$form->setAttribute('data-pjax-fragment', 'CurrentForm');
86 86
 
87
-        if ($form->Fields()->hasTabset()) {
88
-            $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
89
-        }
87
+		if ($form->Fields()->hasTabset()) {
88
+			$form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
89
+		}
90 90
 		$form->setHTMLID('Form_EditForm');
91 91
 		$form->loadDataFrom($siteConfig);
92 92
 		$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
93 93
 
94 94
 		// Use <button> to allow full jQuery UI styling
95 95
 		$actions = $actions->dataFields();
96
-        if ($actions) {
97
-            foreach ($actions as $action) {
98
-                $action->setUseButtonTag(true);
99
-            }
100
-        }
96
+		if ($actions) {
97
+			foreach ($actions as $action) {
98
+				$action->setUseButtonTag(true);
99
+			}
100
+		}
101 101
 
102 102
 		$this->extend('updateEditForm', $form);
103 103
 
@@ -109,8 +109,8 @@  discard block
 block discarded – undo
109 109
 	 *
110 110
 	 * @return ArrayData
111 111
 	 */
112
-    public function getSilverStripeNavigator()
113
-    {
112
+	public function getSilverStripeNavigator()
113
+	{
114 114
 		return $this->renderWith('CMSSettingsController_SilverStripeNavigator');
115 115
 	}
116 116
 
@@ -121,8 +121,8 @@  discard block
 block discarded – undo
121 121
 	 * @param Form $form 
122 122
 	 * @return String
123 123
 	 */
124
-    public function save_siteconfig($data, $form)
125
-    {
124
+	public function save_siteconfig($data, $form)
125
+	{
126 126
 		$siteConfig = SiteConfig::current_site_config();
127 127
 		$form->saveInto($siteConfig);
128 128
 		
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
 	}
140 140
 	
141 141
 
142
-    public function Breadcrumbs($unlinked = false)
143
-    {
142
+	public function Breadcrumbs($unlinked = false)
143
+	{
144 144
 		$defaultTitle = self::menu_title_for_class(get_class($this));
145 145
 
146 146
 		return new ArrayList(array(
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 		)->setHTMLID('Form_EditForm');
71 71
 		$form->setValidationResponseCallback(function() use ($negotiator, $form) {
72 72
 			$request = $this->getRequest();
73
-			if($request->isAjax() && $negotiator) {
73
+			if ($request->isAjax() && $negotiator) {
74 74
 				$form->setupFormErrors();
75 75
 				$result = $form->forTemplate();
76 76
 
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 		
129 129
 		try {
130 130
 			$siteConfig->write();
131
-		} catch(ValidationException $ex) {
131
+		} catch (ValidationException $ex) {
132 132
 			$form->sessionMessage($ex->getResult()->message(), 'bad');
133 133
 			return $this->getResponseNegotiator()->respond($this->request);
134 134
 		}
Please login to merge, or discard this patch.
tests/behat/features/bootstrap/Context/FeatureContext.php 3 patches
Unused Use Statements   -3 removed lines patch added patch discarded remove patch
@@ -2,9 +2,6 @@
 block discarded – undo
2 2
 
3 3
 namespace SilverStripe\Siteconfig\Test\Behaviour;
4 4
 
5
-use SilverStripe\BehatExtension\Context\SilverStripeContext;
6
-use SilverStripe\BehatExtension\Context\BasicContext;
7
-use SilverStripe\BehatExtension\Context\LoginContext;
8 5
 use SilverStripe\BehatExtension\Context\FixtureContext;
9 6
 use SilverStripe\Cms\Test\Behaviour;
10 7
 
Please login to merge, or discard this patch.
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -16,35 +16,35 @@
 block discarded – undo
16 16
  */
17 17
 class FeatureContext extends \SilverStripe\Framework\Test\Behaviour\FeatureContext
18 18
 {
19
-    /**
20
-     * Initializes context.
21
-     * Every scenario gets it's own context object.
22
-     *
23
-     * @param   array   $parameters     context parameters (set them up through behat.yml)
24
-     */
25
-    public function __construct(array $parameters)
26
-    {
27
-        parent::__construct($parameters);
19
+	/**
20
+	 * Initializes context.
21
+	 * Every scenario gets it's own context object.
22
+	 *
23
+	 * @param   array   $parameters     context parameters (set them up through behat.yml)
24
+	 */
25
+	public function __construct(array $parameters)
26
+	{
27
+		parent::__construct($parameters);
28 28
 
29
-        // Override existing fixture context with more specific one
30
-        $fixtureContext = new \SilverStripe\Siteconfig\Test\Behaviour\FixtureContext($parameters);
31
-        $fixtureContext->setFixtureFactory($this->getFixtureFactory());
32
-        $this->useContext('FixtureContext', $fixtureContext);
29
+		// Override existing fixture context with more specific one
30
+		$fixtureContext = new \SilverStripe\Siteconfig\Test\Behaviour\FixtureContext($parameters);
31
+		$fixtureContext->setFixtureFactory($this->getFixtureFactory());
32
+		$this->useContext('FixtureContext', $fixtureContext);
33 33
 
34
-        // Add extra contexts with more steps
35
-        $this->useContext('ThemeContext', new \SilverStripe\Siteconfig\Test\Behaviour\ThemeContext($parameters));
36
-        if(!class_exists('SiteTree')) {
37
-            return;
38
-        }
34
+		// Add extra contexts with more steps
35
+		$this->useContext('ThemeContext', new \SilverStripe\Siteconfig\Test\Behaviour\ThemeContext($parameters));
36
+		if(!class_exists('SiteTree')) {
37
+			return;
38
+		}
39 39
 
40
-        // Use blueprints which auto-publish all subclasses of SiteTree
41
-        $factory = $fixtureContext->getFixtureFactory();
42
-        foreach (\ClassInfo::subclassesFor('SiteTree') as $id => $class) {
43
-            $blueprint = \Injector::inst()->create('FixtureBlueprint', $class);
44
-            $blueprint->addCallback('afterCreate', function ($obj, $identifier, &$data, &$fixtures) {
45
-                $obj->publish('Stage', 'Live');
46
-            });
47
-            $factory->define($class, $blueprint);
48
-        }
49
-    }
40
+		// Use blueprints which auto-publish all subclasses of SiteTree
41
+		$factory = $fixtureContext->getFixtureFactory();
42
+		foreach (\ClassInfo::subclassesFor('SiteTree') as $id => $class) {
43
+			$blueprint = \Injector::inst()->create('FixtureBlueprint', $class);
44
+			$blueprint->addCallback('afterCreate', function ($obj, $identifier, &$data, &$fixtures) {
45
+				$obj->publish('Stage', 'Live');
46
+			});
47
+			$factory->define($class, $blueprint);
48
+		}
49
+	}
50 50
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 
34 34
         // Add extra contexts with more steps
35 35
         $this->useContext('ThemeContext', new \SilverStripe\Siteconfig\Test\Behaviour\ThemeContext($parameters));
36
-        if(!class_exists('SiteTree')) {
36
+        if (!class_exists('SiteTree')) {
37 37
             return;
38 38
         }
39 39
 
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
         $factory = $fixtureContext->getFixtureFactory();
42 42
         foreach (\ClassInfo::subclassesFor('SiteTree') as $id => $class) {
43 43
             $blueprint = \Injector::inst()->create('FixtureBlueprint', $class);
44
-            $blueprint->addCallback('afterCreate', function ($obj, $identifier, &$data, &$fixtures) {
44
+            $blueprint->addCallback('afterCreate', function($obj, $identifier, &$data, &$fixtures) {
45 45
                 $obj->publish('Stage', 'Live');
46 46
             });
47 47
             $factory->define($class, $blueprint);
Please login to merge, or discard this patch.
features/bootstrap/SilverStripe/SiteConfig/Test/Behaviour/ThemeContext.php 4 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -54,6 +54,9 @@  discard block
 block discarded – undo
54 54
         $this->requireFile(BASE_PATH . '/themes/' . $theme . '/templates/' . $template, $content);
55 55
     }
56 56
 
57
+    /**
58
+     * @param string $filename
59
+     */
57 60
     protected function requireFile($filename, $content)
58 61
     {
59 62
         // Already exists
@@ -71,6 +74,9 @@  discard block
 block discarded – undo
71 74
         }
72 75
     }
73 76
 
77
+    /**
78
+     * @param string $dirname
79
+     */
74 80
     protected function requireDir($dirname)
75 81
     {
76 82
         // Directory doesn't exist, create it and mark it for deletion
Please login to merge, or discard this patch.
Unused Use Statements   -8 removed lines patch added patch discarded remove patch
@@ -2,15 +2,7 @@
 block discarded – undo
2 2
 
3 3
 namespace SilverStripe\Siteconfig\Test\Behaviour;
4 4
 
5
-use Behat\Behat\Context\ClosuredContextInterface;
6
-use Behat\Behat\Context\TranslatedContextInterface;
7 5
 use Behat\Behat\Context\BehatContext;
8
-use Behat\Behat\Context\Step;
9
-use Behat\Behat\Event\StepEvent;
10
-use Behat\Behat\Exception\PendingException;
11
-use Behat\Mink\Driver\Selenium2Driver;
12
-use Behat\Gherkin\Node\PyStringNode;
13
-use Behat\Gherkin\Node\TableNode;
14 6
 
15 7
 /**
16 8
  * Context used to create fixtures in the SilverStripe ORM.
Please login to merge, or discard this patch.
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -17,100 +17,100 @@
 block discarded – undo
17 17
  */
18 18
 class ThemeContext extends BehatContext
19 19
 {
20
-    protected $restoreFiles = array();
21
-    protected $restoreDirectories = array();
20
+	protected $restoreFiles = array();
21
+	protected $restoreDirectories = array();
22 22
 
23
-    /**
24
-     * Create a test theme
25
-     *
26
-     * @Given /^a theme "(?<theme>[^"]+)"/
27
-     */
28
-    public function stepCreateTheme($theme)
29
-    {
30
-        if (!preg_match('/^[0-9a-zA-Z_-]+$/', $theme)) {
31
-            throw new \InvalidArgumentException("Bad theme '$theme'");
32
-        }
23
+	/**
24
+	 * Create a test theme
25
+	 *
26
+	 * @Given /^a theme "(?<theme>[^"]+)"/
27
+	 */
28
+	public function stepCreateTheme($theme)
29
+	{
30
+		if (!preg_match('/^[0-9a-zA-Z_-]+$/', $theme)) {
31
+			throw new \InvalidArgumentException("Bad theme '$theme'");
32
+		}
33 33
 
34
-        $this->requireDir(BASE_PATH . '/themes');
35
-        $this->requireDir(BASE_PATH . '/themes/' . $theme);
36
-        $this->requireDir(BASE_PATH . '/themes/' . $theme . '/templates');
37
-    }
34
+		$this->requireDir(BASE_PATH . '/themes');
35
+		$this->requireDir(BASE_PATH . '/themes/' . $theme);
36
+		$this->requireDir(BASE_PATH . '/themes/' . $theme . '/templates');
37
+	}
38 38
 
39
-    /**
40
-     * Create a template within a test theme
41
-     *
42
-     * @Given /^a template "(?<template>[^"]+)" in theme "(?<theme>[^"]+)" with content "(?<content>[^"]+)"/
43
-     */
44
-    public function stepCreateTemplate($template, $theme, $content)
45
-    {
46
-        if (!preg_match('/^[0-9a-zA-Z_-]+$/', $theme)) {
47
-            throw new \InvalidArgumentException("Bad theme '$theme'");
48
-        }
49
-        if (!preg_match('/^(Layout\/)?[0-9a-zA-Z_-]+\.ss$/', $template)) {
50
-            throw new \InvalidArgumentException("Bad template '$template'");
51
-        }
39
+	/**
40
+	 * Create a template within a test theme
41
+	 *
42
+	 * @Given /^a template "(?<template>[^"]+)" in theme "(?<theme>[^"]+)" with content "(?<content>[^"]+)"/
43
+	 */
44
+	public function stepCreateTemplate($template, $theme, $content)
45
+	{
46
+		if (!preg_match('/^[0-9a-zA-Z_-]+$/', $theme)) {
47
+			throw new \InvalidArgumentException("Bad theme '$theme'");
48
+		}
49
+		if (!preg_match('/^(Layout\/)?[0-9a-zA-Z_-]+\.ss$/', $template)) {
50
+			throw new \InvalidArgumentException("Bad template '$template'");
51
+		}
52 52
 
53
-        $this->stepCreateTheme($theme);
54
-        $this->requireFile(BASE_PATH . '/themes/' . $theme . '/templates/' . $template, $content);
55
-    }
53
+		$this->stepCreateTheme($theme);
54
+		$this->requireFile(BASE_PATH . '/themes/' . $theme . '/templates/' . $template, $content);
55
+	}
56 56
 
57
-    protected function requireFile($filename, $content)
58
-    {
59
-        // Already exists
60
-        if (file_exists($filename)) {
61
-            // If the content is different, remember old content for restoration
62
-            $origContent = file_get_contents($filename);
63
-            if ($origContent != $content) {
64
-                file_put_contents($filename, $content);
65
-                $this->restoreFiles[$filename] = $origContent;
66
-            }
67
-        // Doesn't exist, mark it for deletion after test
68
-        } else {
69
-            file_put_contents($filename, $content);
70
-            $this->restoreFiles[$filename] = null;
71
-        }
72
-    }
57
+	protected function requireFile($filename, $content)
58
+	{
59
+		// Already exists
60
+		if (file_exists($filename)) {
61
+			// If the content is different, remember old content for restoration
62
+			$origContent = file_get_contents($filename);
63
+			if ($origContent != $content) {
64
+				file_put_contents($filename, $content);
65
+				$this->restoreFiles[$filename] = $origContent;
66
+			}
67
+		// Doesn't exist, mark it for deletion after test
68
+		} else {
69
+			file_put_contents($filename, $content);
70
+			$this->restoreFiles[$filename] = null;
71
+		}
72
+	}
73 73
 
74
-    protected function requireDir($dirname)
75
-    {
76
-        // Directory doesn't exist, create it and mark it for deletion
77
-        if (!file_exists($dirname)) {
78
-            mkdir($dirname);
79
-            $this->restoreDirectories[] = $dirname;
80
-        }
81
-    }
74
+	protected function requireDir($dirname)
75
+	{
76
+		// Directory doesn't exist, create it and mark it for deletion
77
+		if (!file_exists($dirname)) {
78
+			mkdir($dirname);
79
+			$this->restoreDirectories[] = $dirname;
80
+		}
81
+	}
82 82
 
83
-    /**
84
-     * Clean up any theme manipulation
85
-     *
86
-     * @AfterScenario
87
-     */
88
-    public function cleanThemesAfterScenario()
89
-    {
90
-        // Restore any created/modified files.
91
-        //  - If modified, revert then to original contnet
92
-        //  - If created, delete them
93
-        if ($this->restoreFiles) {
94
-            foreach ($this->restoreFiles as $file => $origContent) {
95
-                if ($origContent === null) {
96
-                    unlink($file);
97
-                } else {
98
-                    file_put_contents($file, $origContent);
99
-                }
100
-            }
83
+	/**
84
+	 * Clean up any theme manipulation
85
+	 *
86
+	 * @AfterScenario
87
+	 */
88
+	public function cleanThemesAfterScenario()
89
+	{
90
+		// Restore any created/modified files.
91
+		//  - If modified, revert then to original contnet
92
+		//  - If created, delete them
93
+		if ($this->restoreFiles) {
94
+			foreach ($this->restoreFiles as $file => $origContent) {
95
+				if ($origContent === null) {
96
+					unlink($file);
97
+				} else {
98
+					file_put_contents($file, $origContent);
99
+				}
100
+			}
101 101
 
102
-            $this->restoreFiles = array();
103
-        }
102
+			$this->restoreFiles = array();
103
+		}
104 104
 
105
-        // Restore any created directories: that is, delete them
106
-        if ($this->restoreDirectories) {
107
-            // Flip the order so that nested direcotires are unlinked() first
108
-            $this->restoreDirectories = array_reverse($this->restoreDirectories);
109
-            foreach ($this->restoreDirectories as $dir) {
110
-                rmdir($dir);
111
-            }
105
+		// Restore any created directories: that is, delete them
106
+		if ($this->restoreDirectories) {
107
+			// Flip the order so that nested direcotires are unlinked() first
108
+			$this->restoreDirectories = array_reverse($this->restoreDirectories);
109
+			foreach ($this->restoreDirectories as $dir) {
110
+				rmdir($dir);
111
+			}
112 112
 
113
-            $this->restoreDirectories = array();
114
-        }
115
-    }
113
+			$this->restoreDirectories = array();
114
+		}
115
+	}
116 116
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -31,9 +31,9 @@  discard block
 block discarded – undo
31 31
             throw new \InvalidArgumentException("Bad theme '$theme'");
32 32
         }
33 33
 
34
-        $this->requireDir(BASE_PATH . '/themes');
35
-        $this->requireDir(BASE_PATH . '/themes/' . $theme);
36
-        $this->requireDir(BASE_PATH . '/themes/' . $theme . '/templates');
34
+        $this->requireDir(BASE_PATH.'/themes');
35
+        $this->requireDir(BASE_PATH.'/themes/'.$theme);
36
+        $this->requireDir(BASE_PATH.'/themes/'.$theme.'/templates');
37 37
     }
38 38
 
39 39
     /**
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
         }
52 52
 
53 53
         $this->stepCreateTheme($theme);
54
-        $this->requireFile(BASE_PATH . '/themes/' . $theme . '/templates/' . $template, $content);
54
+        $this->requireFile(BASE_PATH.'/themes/'.$theme.'/templates/'.$template, $content);
55 55
     }
56 56
 
57 57
     protected function requireFile($filename, $content)
Please login to merge, or discard this patch.
tests/SiteConfigTest.php 2 patches
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -6,92 +6,92 @@
 block discarded – undo
6 6
  */
7 7
 class SiteConfigTest extends SapphireTest
8 8
 {
9
-    protected static $fixture_file = 'SiteConfigTest.yml';
9
+	protected static $fixture_file = 'SiteConfigTest.yml';
10 10
     
11
-    protected $illegalExtensions = array(
12
-        'SiteTree' => array('SiteTreeSubsites')
13
-    );
11
+	protected $illegalExtensions = array(
12
+		'SiteTree' => array('SiteTreeSubsites')
13
+	);
14 14
 
15
-    public function setUpOnce()
16
-    {
17
-        // Fix issue with tests failing without CMS module
18
-        if (!class_exists('SiteTree')) {
19
-            unset($this->illegalExtensions['SiteTree']);
20
-        }
15
+	public function setUpOnce()
16
+	{
17
+		// Fix issue with tests failing without CMS module
18
+		if (!class_exists('SiteTree')) {
19
+			unset($this->illegalExtensions['SiteTree']);
20
+		}
21 21
 
22
-        parent::setUpOnce(); // TODO: Change the autogenerated stub
23
-    }
22
+		parent::setUpOnce(); // TODO: Change the autogenerated stub
23
+	}
24 24
 
25
-    public function testAvailableThemes()
26
-    {
27
-        $config = $this->objFromFixture('SiteConfig', 'default');
28
-        $ds = DIRECTORY_SEPARATOR;
29
-        $testThemeBaseDir = TEMP_FOLDER . $ds . 'test-themes';
25
+	public function testAvailableThemes()
26
+	{
27
+		$config = $this->objFromFixture('SiteConfig', 'default');
28
+		$ds = DIRECTORY_SEPARATOR;
29
+		$testThemeBaseDir = TEMP_FOLDER . $ds . 'test-themes';
30 30
         
31
-        if (file_exists($testThemeBaseDir)) {
32
-            Filesystem::removeFolder($testThemeBaseDir);
33
-        }
34
-        mkdir($testThemeBaseDir);
35
-        mkdir($testThemeBaseDir . $ds . 'blackcandy');
36
-        mkdir($testThemeBaseDir . $ds . 'blackcandy_blog');
37
-        mkdir($testThemeBaseDir . $ds . 'darkshades');
38
-        mkdir($testThemeBaseDir . $ds . 'darkshades_blog');
31
+		if (file_exists($testThemeBaseDir)) {
32
+			Filesystem::removeFolder($testThemeBaseDir);
33
+		}
34
+		mkdir($testThemeBaseDir);
35
+		mkdir($testThemeBaseDir . $ds . 'blackcandy');
36
+		mkdir($testThemeBaseDir . $ds . 'blackcandy_blog');
37
+		mkdir($testThemeBaseDir . $ds . 'darkshades');
38
+		mkdir($testThemeBaseDir . $ds . 'darkshades_blog');
39 39
         
40
-        $themes = $config->getAvailableThemes($testThemeBaseDir);
41
-        $this->assertContains('blackcandy', $themes, 'Test themes contain blackcandy theme');
42
-        $this->assertContains('darkshades', $themes, 'Test themes contain darkshades theme');
40
+		$themes = $config->getAvailableThemes($testThemeBaseDir);
41
+		$this->assertContains('blackcandy', $themes, 'Test themes contain blackcandy theme');
42
+		$this->assertContains('darkshades', $themes, 'Test themes contain darkshades theme');
43 43
         
44
-        SiteConfig::config()->disabled_themes = array('darkshades');
45
-        $themes = $config->getAvailableThemes($testThemeBaseDir);
46
-        $this->assertFalse(in_array('darkshades', $themes), 'Darkshades was disabled - it is no longer available');
44
+		SiteConfig::config()->disabled_themes = array('darkshades');
45
+		$themes = $config->getAvailableThemes($testThemeBaseDir);
46
+		$this->assertFalse(in_array('darkshades', $themes), 'Darkshades was disabled - it is no longer available');
47 47
         
48
-        Filesystem::removeFolder($testThemeBaseDir);
49
-    }
48
+		Filesystem::removeFolder($testThemeBaseDir);
49
+	}
50 50
 
51
-    public function testCanCreateRootPages()
52
-    {
53
-        $config = $this->objFromFixture('SiteConfig', 'default');
51
+	public function testCanCreateRootPages()
52
+	{
53
+		$config = $this->objFromFixture('SiteConfig', 'default');
54 54
 
55
-        // Log in without pages admin access
56
-        $this->logInWithPermission('CMS_ACCESS_AssetAdmin');
57
-        $this->assertFalse($config->canCreateTopLevel());
55
+		// Log in without pages admin access
56
+		$this->logInWithPermission('CMS_ACCESS_AssetAdmin');
57
+		$this->assertFalse($config->canCreateTopLevel());
58 58
 
59
-        // Login with necessary edit permission
60
-        $perms = SiteConfig::config()->required_permission;
61
-        $this->logInWithPermission(reset($perms));
62
-        $this->assertTrue($config->canCreateTopLevel());
63
-    }
59
+		// Login with necessary edit permission
60
+		$perms = SiteConfig::config()->required_permission;
61
+		$this->logInWithPermission(reset($perms));
62
+		$this->assertTrue($config->canCreateTopLevel());
63
+	}
64 64
 
65
-    public function testCanViewPages()
66
-    {
67
-        $config = $this->objFromFixture('SiteConfig', 'default');
68
-        $this->assertTrue($config->canViewPages());
69
-    }
65
+	public function testCanViewPages()
66
+	{
67
+		$config = $this->objFromFixture('SiteConfig', 'default');
68
+		$this->assertTrue($config->canViewPages());
69
+	}
70 70
 
71
-    public function testCanEdit()
72
-    {
73
-        $config = $this->objFromFixture('SiteConfig', 'default');
71
+	public function testCanEdit()
72
+	{
73
+		$config = $this->objFromFixture('SiteConfig', 'default');
74 74
         
75
-        // Unrelated permissions don't allow siteconfig
76
-        $this->logInWithPermission('CMS_ACCESS_AssetAdmin');
77
-        $this->assertFalse($config->canEdit());
75
+		// Unrelated permissions don't allow siteconfig
76
+		$this->logInWithPermission('CMS_ACCESS_AssetAdmin');
77
+		$this->assertFalse($config->canEdit());
78 78
 
79
-        // Only those with edit permission can do this
80
-        $this->logInWithPermission('EDIT_SITECONFIG');
81
-        $this->assertTrue($config->canEdit());
82
-    }
79
+		// Only those with edit permission can do this
80
+		$this->logInWithPermission('EDIT_SITECONFIG');
81
+		$this->assertTrue($config->canEdit());
82
+	}
83 83
 
84
-    public function testCanEditPages()
85
-    {
86
-        $config = $this->objFromFixture('SiteConfig', 'default');
84
+	public function testCanEditPages()
85
+	{
86
+		$config = $this->objFromFixture('SiteConfig', 'default');
87 87
         
88
-        // Log in without pages admin access
89
-        $this->logInWithPermission('CMS_ACCESS_AssetAdmin');
90
-        $this->assertFalse($config->canEditPages());
88
+		// Log in without pages admin access
89
+		$this->logInWithPermission('CMS_ACCESS_AssetAdmin');
90
+		$this->assertFalse($config->canEditPages());
91 91
 
92
-        // Login with necessary edit permission
93
-        $perms = SiteConfig::config()->required_permission;
94
-        $this->logInWithPermission(reset($perms));
95
-        $this->assertTrue($config->canEditPages());
96
-    }
92
+		// Login with necessary edit permission
93
+		$perms = SiteConfig::config()->required_permission;
94
+		$this->logInWithPermission(reset($perms));
95
+		$this->assertTrue($config->canEditPages());
96
+	}
97 97
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -26,16 +26,16 @@
 block discarded – undo
26 26
     {
27 27
         $config = $this->objFromFixture('SiteConfig', 'default');
28 28
         $ds = DIRECTORY_SEPARATOR;
29
-        $testThemeBaseDir = TEMP_FOLDER . $ds . 'test-themes';
29
+        $testThemeBaseDir = TEMP_FOLDER.$ds.'test-themes';
30 30
         
31 31
         if (file_exists($testThemeBaseDir)) {
32 32
             Filesystem::removeFolder($testThemeBaseDir);
33 33
         }
34 34
         mkdir($testThemeBaseDir);
35
-        mkdir($testThemeBaseDir . $ds . 'blackcandy');
36
-        mkdir($testThemeBaseDir . $ds . 'blackcandy_blog');
37
-        mkdir($testThemeBaseDir . $ds . 'darkshades');
38
-        mkdir($testThemeBaseDir . $ds . 'darkshades_blog');
35
+        mkdir($testThemeBaseDir.$ds.'blackcandy');
36
+        mkdir($testThemeBaseDir.$ds.'blackcandy_blog');
37
+        mkdir($testThemeBaseDir.$ds.'darkshades');
38
+        mkdir($testThemeBaseDir.$ds.'darkshades_blog');
39 39
         
40 40
         $themes = $config->getAvailableThemes($testThemeBaseDir);
41 41
         $this->assertContains('blackcandy', $themes, 'Test themes contain blackcandy theme');
Please login to merge, or discard this patch.
code/model/SiteConfig.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -141,9 +141,9 @@  discard block
 block discarded – undo
141 141
             $fields->makeFieldReadonly($titleField);
142 142
         }
143 143
 
144
-        if (file_exists(BASE_PATH . '/install.php')) {
144
+        if (file_exists(BASE_PATH.'/install.php')) {
145 145
             $fields->addFieldToTab("Root.Main", new LiteralField("InstallWarningHeader",
146
-                "<p class=\"message warning\">" . _t("SiteTree.REMOVE_INSTALL_WARNING",
146
+                "<p class=\"message warning\">"._t("SiteTree.REMOVE_INSTALL_WARNING",
147 147
                 "Warning: You should remove install.php from this SilverStripe install for security reasons.")
148 148
                 . "</p>"), "Title");
149 149
         }
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
     public function getAvailableThemes($baseDir = null)
166 166
     {
167 167
         $themes = SSViewer::get_themes($baseDir);
168
-        $disabled = (array)$this->config()->disabled_themes;
168
+        $disabled = (array) $this->config()->disabled_themes;
169 169
     
170 170
         foreach ($disabled as $theme) {
171 171
             if (isset($themes[$theme])) {
Please login to merge, or discard this patch.
Indentation   +424 added lines, -424 removed lines patch added patch discarded remove patch
@@ -27,428 +27,428 @@
 block discarded – undo
27 27
  */
28 28
 class SiteConfig extends DataObject implements PermissionProvider, TemplateGlobalProvider
29 29
 {
30
-    private static $db = array(
31
-        "Title" => "Varchar(255)",
32
-        "Tagline" => "Varchar(255)",
33
-        "Theme" => "Varchar(255)",
34
-        "CanViewType" => "Enum('Anyone, LoggedInUsers, OnlyTheseUsers', 'Anyone')",
35
-        "CanEditType" => "Enum('LoggedInUsers, OnlyTheseUsers', 'LoggedInUsers')",
36
-        "CanCreateTopLevelType" => "Enum('LoggedInUsers, OnlyTheseUsers', 'LoggedInUsers')",
37
-    );
38
-
39
-    private static $many_many = array(
40
-        "ViewerGroups" => "SilverStripe\\Security\\Group",
41
-        "EditorGroups" => "SilverStripe\\Security\\Group",
42
-        "CreateTopLevelGroups" => "SilverStripe\\Security\\Group"
43
-    );
44
-
45
-    private static $defaults = array(
46
-        "CanViewType" => "Anyone",
47
-        "CanEditType" => "LoggedInUsers",
48
-        "CanCreateTopLevelType" => "LoggedInUsers",
49
-    );
50
-
51
-    /**
52
-     * @config
53
-     *
54
-     * @var array
55
-     */
56
-    private static $disabled_themes = array();
57
-
58
-    /**
59
-     * Default permission to check for 'LoggedInUsers' to create or edit pages
60
-     *
61
-     * @var array
62
-     * @config
63
-     */
64
-    private static $required_permission = array('CMS_ACCESS_CMSMain', 'CMS_ACCESS_LeftAndMain');
65
-
66
-
67
-    public function populateDefaults()
68
-    {
69
-        $this->Title = _t('SiteConfig.SITENAMEDEFAULT', "Your Site Name");
70
-        $this->Tagline = _t('SiteConfig.TAGLINEDEFAULT', "your tagline here");
71
-
72
-        // Allow these defaults to be overridden
73
-        parent::populateDefaults();
74
-    }
75
-
76
-    /**
77
-     * Get the fields that are sent to the CMS.
78
-     *
79
-     * In your extensions: updateCMSFields($fields).
80
-     *
81
-     * @return FieldList
82
-     */
83
-    public function getCMSFields()
84
-    {
85
-        $groupsMap = array();
86
-
87
-        foreach (Group::get() as $group) {
88
-            // Listboxfield values are escaped, use ASCII char instead of &raquo;
89
-            $groupsMap[$group->ID] = $group->getBreadcrumbs(' > ');
90
-        }
91
-        asort($groupsMap);
92
-
93
-        $fields = new FieldList(
94
-            new TabSet("Root",
95
-                $tabMain = new Tab('Main',
96
-                    $titleField = new TextField("Title", _t('SiteConfig.SITETITLE', "Site title")),
97
-                    $taglineField = new TextField("Tagline", _t('SiteConfig.SITETAGLINE', "Site Tagline/Slogan")),
98
-                    $themeDropdownField = new DropdownField("Theme", _t('SiteConfig.THEME', 'Theme'), $this->getAvailableThemes())
99
-                ),
100
-                $tabAccess = new Tab('Access',
101
-                    $viewersOptionsField = new OptionsetField("CanViewType", _t('SiteConfig.VIEWHEADER', "Who can view pages on this site?")),
102
-                    $viewerGroupsField = ListboxField::create("ViewerGroups", _t('SiteTree.VIEWERGROUPS', "Viewer Groups"))
103
-                        ->setSource($groupsMap)
104
-                        ->setAttribute(
105
-                            'data-placeholder',
106
-                            _t('SiteTree.GroupPlaceholder', 'Click to select group')
107
-                        ),
108
-                    $editorsOptionsField = new OptionsetField("CanEditType", _t('SiteConfig.EDITHEADER', "Who can edit pages on this site?")),
109
-                    $editorGroupsField = ListboxField::create("EditorGroups", _t('SiteTree.EDITORGROUPS', "Editor Groups"))
110
-                        ->setSource($groupsMap)
111
-                        ->setAttribute(
112
-                            'data-placeholder',
113
-                            _t('SiteTree.GroupPlaceholder', 'Click to select group')
114
-                        ),
115
-                    $topLevelCreatorsOptionsField = new OptionsetField("CanCreateTopLevelType", _t('SiteConfig.TOPLEVELCREATE', "Who can create pages in the root of the site?")),
116
-                    $topLevelCreatorsGroupsField = ListboxField::create("CreateTopLevelGroups", _t('SiteTree.TOPLEVELCREATORGROUPS', "Top level creators"))
117
-                        ->setSource($groupsMap)
118
-                        ->setAttribute(
119
-                            'data-placeholder',
120
-                            _t('SiteTree.GroupPlaceholder', 'Click to select group')
121
-                        )
122
-                )
123
-            ),
124
-            new HiddenField('ID')
125
-        );
126
-
127
-        $themeDropdownField->setEmptyString(_t('SiteConfig.DEFAULTTHEME', '(Use default theme)'));
128
-
129
-        $viewersOptionsSource = array();
130
-        $viewersOptionsSource["Anyone"] = _t('SiteTree.ACCESSANYONE', "Anyone");
131
-        $viewersOptionsSource["LoggedInUsers"] = _t('SiteTree.ACCESSLOGGEDIN', "Logged-in users");
132
-        $viewersOptionsSource["OnlyTheseUsers"] = _t('SiteTree.ACCESSONLYTHESE', "Only these people (choose from list)");
133
-        $viewersOptionsField->setSource($viewersOptionsSource);
134
-
135
-        $editorsOptionsSource = array();
136
-        $editorsOptionsSource["LoggedInUsers"] = _t('SiteTree.EDITANYONE', "Anyone who can log-in to the CMS");
137
-        $editorsOptionsSource["OnlyTheseUsers"] = _t('SiteTree.EDITONLYTHESE', "Only these people (choose from list)");
138
-        $editorsOptionsField->setSource($editorsOptionsSource);
139
-
140
-        $topLevelCreatorsOptionsField->setSource($editorsOptionsSource);
141
-
142
-        if (!Permission::check('EDIT_SITECONFIG')) {
143
-            $fields->makeFieldReadonly($viewersOptionsField);
144
-            $fields->makeFieldReadonly($viewerGroupsField);
145
-            $fields->makeFieldReadonly($editorsOptionsField);
146
-            $fields->makeFieldReadonly($editorGroupsField);
147
-            $fields->makeFieldReadonly($topLevelCreatorsOptionsField);
148
-            $fields->makeFieldReadonly($topLevelCreatorsGroupsField);
149
-            $fields->makeFieldReadonly($taglineField);
150
-            $fields->makeFieldReadonly($titleField);
151
-        }
152
-
153
-        if (file_exists(BASE_PATH . '/install.php')) {
154
-            $fields->addFieldToTab("Root.Main", new LiteralField("InstallWarningHeader",
155
-                "<p class=\"message warning\">" . _t("SiteTree.REMOVE_INSTALL_WARNING",
156
-                "Warning: You should remove install.php from this SilverStripe install for security reasons.")
157
-                . "</p>"), "Title");
158
-        }
159
-
160
-        $tabMain->setTitle(_t('SiteConfig.TABMAIN', "Main"));
161
-        $tabAccess->setTitle(_t('SiteConfig.TABACCESS', "Access"));
162
-        $this->extend('updateCMSFields', $fields);
163
-
164
-        return $fields;
165
-    }
166
-
167
-    /**
168
-     * Get all available themes that haven't been marked as disabled.
169
-     *
170
-     * @param string $baseDir Optional alternative theme base directory for testing
171
-     *
172
-     * @return array of theme directory names
173
-     */
174
-    public function getAvailableThemes($baseDir = null)
175
-    {
176
-        $themes = SSViewer::get_themes($baseDir);
177
-        $disabled = (array)$this->config()->disabled_themes;
178
-
179
-        foreach ($disabled as $theme) {
180
-            if (isset($themes[$theme])) {
181
-                unset($themes[$theme]);
182
-            }
183
-        }
184
-
185
-        return $themes;
186
-    }
187
-
188
-    /**
189
-     * Get the actions that are sent to the CMS.
190
-     *
191
-     * In your extensions: updateEditFormActions($actions)
192
-     *
193
-     * @return FieldList
194
-     */
195
-    public function getCMSActions()
196
-    {
197
-        if (Permission::check('ADMIN') || Permission::check('EDIT_SITECONFIG')) {
198
-            $actions = new FieldList(
199
-                FormAction::create('save_siteconfig', _t('CMSMain.SAVE', 'Save'))
200
-                    ->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')
201
-            );
202
-        } else {
203
-            $actions = new FieldList();
204
-        }
205
-
206
-        $this->extend('updateCMSActions', $actions);
207
-
208
-        return $actions;
209
-    }
210
-
211
-    /**
212
-     * @return string
213
-     */
214
-    public function CMSEditLink()
215
-    {
216
-        return singleton('CMSSettingsController')->Link();
217
-    }
218
-
219
-    /**
220
-     * Get the current sites SiteConfig, and creates a new one through
221
-     * {@link make_site_config()} if none is found.
222
-     *
223
-     * @return SiteConfig
224
-     */
225
-    public static function current_site_config()
226
-    {
227
-        if ($siteConfig = DataObject::get_one('SiteConfig')) {
228
-            return $siteConfig;
229
-        }
230
-
231
-        return self::make_site_config();
232
-    }
233
-
234
-    /**
235
-     * Setup a default SiteConfig record if none exists.
236
-     */
237
-    public function requireDefaultRecords()
238
-    {
239
-        parent::requireDefaultRecords();
240
-
241
-        $config = DataObject::get_one('SiteConfig');
242
-
243
-        if (!$config) {
244
-            self::make_site_config();
245
-
246
-            DB::alteration_message("Added default site config", "created");
247
-        }
248
-    }
249
-
250
-    /**
251
-     * Create SiteConfig with defaults from language file.
252
-     *
253
-     * @return SiteConfig
254
-     */
255
-    public static function make_site_config()
256
-    {
257
-        $config = SiteConfig::create();
258
-        $config->write();
259
-
260
-        return $config;
261
-    }
262
-
263
-    /**
264
-     * Can a user view this SiteConfig instance?
265
-     *
266
-     * @param Member $member
267
-     * @return boolean
268
-     */
269
-    public function canView($member = null)
270
-    {
271
-        if (!$member) {
272
-            $member = Member::currentUserID();
273
-        }
274
-        if ($member && is_numeric($member)) {
275
-            $member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member);
276
-        }
277
-
278
-        $extended = $this->extendedCan('canView', $member);
279
-        if ($extended !== null) {
280
-            return $extended;
281
-        }
282
-
283
-        // Assuming all that can edit this object can also view it
284
-        return $this->canEdit($member);
285
-    }
286
-
287
-    /**
288
-     * Can a user view pages on this site? This method is only
289
-     * called if a page is set to Inherit, but there is nothing
290
-     * to inherit from.
291
-     *
292
-     * @param Member $member
293
-     * @return boolean
294
-     */
295
-    public function canViewPages($member = null)
296
-    {
297
-        if (!$member) {
298
-            $member = Member::currentUserID();
299
-        }
300
-        if ($member && is_numeric($member)) {
301
-            $member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member);
302
-        }
303
-
304
-        if ($member && Permission::checkMember($member, "ADMIN")) {
305
-            return true;
306
-        }
307
-
308
-        $extended = $this->extendedCan('canViewPages', $member);
309
-        if ($extended !== null) {
310
-            return $extended;
311
-        }
312
-
313
-        if (!$this->CanViewType || $this->CanViewType == 'Anyone') {
314
-            return true;
315
-        }
316
-
317
-        // check for any logged-in users
318
-        if ($this->CanViewType === 'LoggedInUsers' && $member) {
319
-            return true;
320
-        }
321
-
322
-        // check for specific groups
323
-        if ($this->CanViewType === 'OnlyTheseUsers' && $member && $member->inGroups($this->ViewerGroups())) {
324
-            return true;
325
-        }
326
-
327
-        return false;
328
-    }
329
-
330
-    /**
331
-     * Can a user edit pages on this site? This method is only
332
-     * called if a page is set to Inherit, but there is nothing
333
-     * to inherit from, or on new records without a parent.
334
-     *
335
-     * @param Member $member
336
-     * @return boolean
337
-     */
338
-    public function canEditPages($member = null)
339
-    {
340
-        if (!$member) {
341
-            $member = Member::currentUserID();
342
-        }
343
-        if ($member && is_numeric($member)) {
344
-            $member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member);
345
-        }
346
-
347
-        if ($member && Permission::checkMember($member, "ADMIN")) {
348
-            return true;
349
-        }
350
-
351
-        $extended = $this->extendedCan('canEditPages', $member);
352
-        if ($extended !== null) {
353
-            return $extended;
354
-        }
355
-
356
-        // check for any logged-in users with CMS access
357
-        if ($this->CanEditType === 'LoggedInUsers'
358
-            && Permission::checkMember($member, $this->config()->required_permission)
359
-        ) {
360
-            return true;
361
-        }
362
-
363
-            // check for specific groups
364
-        if ($this->CanEditType === 'OnlyTheseUsers' && $member && $member->inGroups($this->EditorGroups())) {
365
-            return true;
366
-        }
367
-
368
-        return false;
369
-    }
370
-
371
-    public function canEdit($member = null)
372
-    {
373
-        if (!$member) {
374
-            $member = Member::currentUserID();
375
-        }
376
-        if ($member && is_numeric($member)) {
377
-            $member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member);
378
-        }
379
-
380
-        $extended = $this->extendedCan('canEdit', $member);
381
-        if ($extended !== null) {
382
-            return $extended;
383
-        }
384
-
385
-        return Permission::checkMember($member, "EDIT_SITECONFIG");
386
-    }
387
-
388
-    /**
389
-     * @return array
390
-     */
391
-    public function providePermissions()
392
-    {
393
-        return array(
394
-            'EDIT_SITECONFIG' => array(
395
-                'name' => _t('SiteConfig.EDIT_PERMISSION', 'Manage site configuration'),
396
-                'category' => _t('Permissions.PERMISSIONS_CATEGORY', 'Roles and access permissions'),
397
-                'help' => _t('SiteConfig.EDIT_PERMISSION_HELP', 'Ability to edit global access settings/top-level page permissions.'),
398
-                'sort' => 400
399
-            )
400
-        );
401
-    }
402
-
403
-    /**
404
-     * Can a user create pages in the root of this site?
405
-     *
406
-     * @param Member $member
407
-     * @return boolean
408
-     */
409
-    public function canCreateTopLevel($member = null)
410
-    {
411
-        if (!$member) {
412
-            $member = Member::currentUserID();
413
-        }
414
-        if ($member && is_numeric($member)) {
415
-            $member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member);
416
-        }
417
-
418
-        if ($member && Permission::checkMember($member, "ADMIN")) {
419
-            return true;
420
-        }
421
-
422
-        $extended = $this->extendedCan('canCreateTopLevel', $member);
423
-        if ($extended !== null) {
424
-            return $extended;
425
-        }
426
-
427
-        // check for any logged-in users with CMS permission
428
-        if ($this->CanCreateTopLevelType === 'LoggedInUsers'
429
-            && Permission::checkMember($member, $this->config()->required_permission)
430
-        ) {
431
-            return true;
432
-        }
433
-
434
-        // check for specific groups
435
-        if ($this->CanCreateTopLevelType === 'OnlyTheseUsers'
436
-            && $member
437
-            && $member->inGroups($this->CreateTopLevelGroups())
438
-        ) {
439
-            return true;
440
-        }
441
-
442
-        return false;
443
-    }
444
-
445
-    /**
446
-     * Add $SiteConfig to all SSViewers
447
-     */
448
-    public static function get_template_global_variables()
449
-    {
450
-        return array(
451
-            'SiteConfig' => 'current_site_config',
452
-        );
453
-    }
30
+	private static $db = array(
31
+		"Title" => "Varchar(255)",
32
+		"Tagline" => "Varchar(255)",
33
+		"Theme" => "Varchar(255)",
34
+		"CanViewType" => "Enum('Anyone, LoggedInUsers, OnlyTheseUsers', 'Anyone')",
35
+		"CanEditType" => "Enum('LoggedInUsers, OnlyTheseUsers', 'LoggedInUsers')",
36
+		"CanCreateTopLevelType" => "Enum('LoggedInUsers, OnlyTheseUsers', 'LoggedInUsers')",
37
+	);
38
+
39
+	private static $many_many = array(
40
+		"ViewerGroups" => "SilverStripe\\Security\\Group",
41
+		"EditorGroups" => "SilverStripe\\Security\\Group",
42
+		"CreateTopLevelGroups" => "SilverStripe\\Security\\Group"
43
+	);
44
+
45
+	private static $defaults = array(
46
+		"CanViewType" => "Anyone",
47
+		"CanEditType" => "LoggedInUsers",
48
+		"CanCreateTopLevelType" => "LoggedInUsers",
49
+	);
50
+
51
+	/**
52
+	 * @config
53
+	 *
54
+	 * @var array
55
+	 */
56
+	private static $disabled_themes = array();
57
+
58
+	/**
59
+	 * Default permission to check for 'LoggedInUsers' to create or edit pages
60
+	 *
61
+	 * @var array
62
+	 * @config
63
+	 */
64
+	private static $required_permission = array('CMS_ACCESS_CMSMain', 'CMS_ACCESS_LeftAndMain');
65
+
66
+
67
+	public function populateDefaults()
68
+	{
69
+		$this->Title = _t('SiteConfig.SITENAMEDEFAULT', "Your Site Name");
70
+		$this->Tagline = _t('SiteConfig.TAGLINEDEFAULT', "your tagline here");
71
+
72
+		// Allow these defaults to be overridden
73
+		parent::populateDefaults();
74
+	}
75
+
76
+	/**
77
+	 * Get the fields that are sent to the CMS.
78
+	 *
79
+	 * In your extensions: updateCMSFields($fields).
80
+	 *
81
+	 * @return FieldList
82
+	 */
83
+	public function getCMSFields()
84
+	{
85
+		$groupsMap = array();
86
+
87
+		foreach (Group::get() as $group) {
88
+			// Listboxfield values are escaped, use ASCII char instead of &raquo;
89
+			$groupsMap[$group->ID] = $group->getBreadcrumbs(' > ');
90
+		}
91
+		asort($groupsMap);
92
+
93
+		$fields = new FieldList(
94
+			new TabSet("Root",
95
+				$tabMain = new Tab('Main',
96
+					$titleField = new TextField("Title", _t('SiteConfig.SITETITLE', "Site title")),
97
+					$taglineField = new TextField("Tagline", _t('SiteConfig.SITETAGLINE', "Site Tagline/Slogan")),
98
+					$themeDropdownField = new DropdownField("Theme", _t('SiteConfig.THEME', 'Theme'), $this->getAvailableThemes())
99
+				),
100
+				$tabAccess = new Tab('Access',
101
+					$viewersOptionsField = new OptionsetField("CanViewType", _t('SiteConfig.VIEWHEADER', "Who can view pages on this site?")),
102
+					$viewerGroupsField = ListboxField::create("ViewerGroups", _t('SiteTree.VIEWERGROUPS', "Viewer Groups"))
103
+						->setSource($groupsMap)
104
+						->setAttribute(
105
+							'data-placeholder',
106
+							_t('SiteTree.GroupPlaceholder', 'Click to select group')
107
+						),
108
+					$editorsOptionsField = new OptionsetField("CanEditType", _t('SiteConfig.EDITHEADER', "Who can edit pages on this site?")),
109
+					$editorGroupsField = ListboxField::create("EditorGroups", _t('SiteTree.EDITORGROUPS', "Editor Groups"))
110
+						->setSource($groupsMap)
111
+						->setAttribute(
112
+							'data-placeholder',
113
+							_t('SiteTree.GroupPlaceholder', 'Click to select group')
114
+						),
115
+					$topLevelCreatorsOptionsField = new OptionsetField("CanCreateTopLevelType", _t('SiteConfig.TOPLEVELCREATE', "Who can create pages in the root of the site?")),
116
+					$topLevelCreatorsGroupsField = ListboxField::create("CreateTopLevelGroups", _t('SiteTree.TOPLEVELCREATORGROUPS', "Top level creators"))
117
+						->setSource($groupsMap)
118
+						->setAttribute(
119
+							'data-placeholder',
120
+							_t('SiteTree.GroupPlaceholder', 'Click to select group')
121
+						)
122
+				)
123
+			),
124
+			new HiddenField('ID')
125
+		);
126
+
127
+		$themeDropdownField->setEmptyString(_t('SiteConfig.DEFAULTTHEME', '(Use default theme)'));
128
+
129
+		$viewersOptionsSource = array();
130
+		$viewersOptionsSource["Anyone"] = _t('SiteTree.ACCESSANYONE', "Anyone");
131
+		$viewersOptionsSource["LoggedInUsers"] = _t('SiteTree.ACCESSLOGGEDIN', "Logged-in users");
132
+		$viewersOptionsSource["OnlyTheseUsers"] = _t('SiteTree.ACCESSONLYTHESE', "Only these people (choose from list)");
133
+		$viewersOptionsField->setSource($viewersOptionsSource);
134
+
135
+		$editorsOptionsSource = array();
136
+		$editorsOptionsSource["LoggedInUsers"] = _t('SiteTree.EDITANYONE', "Anyone who can log-in to the CMS");
137
+		$editorsOptionsSource["OnlyTheseUsers"] = _t('SiteTree.EDITONLYTHESE', "Only these people (choose from list)");
138
+		$editorsOptionsField->setSource($editorsOptionsSource);
139
+
140
+		$topLevelCreatorsOptionsField->setSource($editorsOptionsSource);
141
+
142
+		if (!Permission::check('EDIT_SITECONFIG')) {
143
+			$fields->makeFieldReadonly($viewersOptionsField);
144
+			$fields->makeFieldReadonly($viewerGroupsField);
145
+			$fields->makeFieldReadonly($editorsOptionsField);
146
+			$fields->makeFieldReadonly($editorGroupsField);
147
+			$fields->makeFieldReadonly($topLevelCreatorsOptionsField);
148
+			$fields->makeFieldReadonly($topLevelCreatorsGroupsField);
149
+			$fields->makeFieldReadonly($taglineField);
150
+			$fields->makeFieldReadonly($titleField);
151
+		}
152
+
153
+		if (file_exists(BASE_PATH . '/install.php')) {
154
+			$fields->addFieldToTab("Root.Main", new LiteralField("InstallWarningHeader",
155
+				"<p class=\"message warning\">" . _t("SiteTree.REMOVE_INSTALL_WARNING",
156
+				"Warning: You should remove install.php from this SilverStripe install for security reasons.")
157
+				. "</p>"), "Title");
158
+		}
159
+
160
+		$tabMain->setTitle(_t('SiteConfig.TABMAIN', "Main"));
161
+		$tabAccess->setTitle(_t('SiteConfig.TABACCESS', "Access"));
162
+		$this->extend('updateCMSFields', $fields);
163
+
164
+		return $fields;
165
+	}
166
+
167
+	/**
168
+	 * Get all available themes that haven't been marked as disabled.
169
+	 *
170
+	 * @param string $baseDir Optional alternative theme base directory for testing
171
+	 *
172
+	 * @return array of theme directory names
173
+	 */
174
+	public function getAvailableThemes($baseDir = null)
175
+	{
176
+		$themes = SSViewer::get_themes($baseDir);
177
+		$disabled = (array)$this->config()->disabled_themes;
178
+
179
+		foreach ($disabled as $theme) {
180
+			if (isset($themes[$theme])) {
181
+				unset($themes[$theme]);
182
+			}
183
+		}
184
+
185
+		return $themes;
186
+	}
187
+
188
+	/**
189
+	 * Get the actions that are sent to the CMS.
190
+	 *
191
+	 * In your extensions: updateEditFormActions($actions)
192
+	 *
193
+	 * @return FieldList
194
+	 */
195
+	public function getCMSActions()
196
+	{
197
+		if (Permission::check('ADMIN') || Permission::check('EDIT_SITECONFIG')) {
198
+			$actions = new FieldList(
199
+				FormAction::create('save_siteconfig', _t('CMSMain.SAVE', 'Save'))
200
+					->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')
201
+			);
202
+		} else {
203
+			$actions = new FieldList();
204
+		}
205
+
206
+		$this->extend('updateCMSActions', $actions);
207
+
208
+		return $actions;
209
+	}
210
+
211
+	/**
212
+	 * @return string
213
+	 */
214
+	public function CMSEditLink()
215
+	{
216
+		return singleton('CMSSettingsController')->Link();
217
+	}
218
+
219
+	/**
220
+	 * Get the current sites SiteConfig, and creates a new one through
221
+	 * {@link make_site_config()} if none is found.
222
+	 *
223
+	 * @return SiteConfig
224
+	 */
225
+	public static function current_site_config()
226
+	{
227
+		if ($siteConfig = DataObject::get_one('SiteConfig')) {
228
+			return $siteConfig;
229
+		}
230
+
231
+		return self::make_site_config();
232
+	}
233
+
234
+	/**
235
+	 * Setup a default SiteConfig record if none exists.
236
+	 */
237
+	public function requireDefaultRecords()
238
+	{
239
+		parent::requireDefaultRecords();
240
+
241
+		$config = DataObject::get_one('SiteConfig');
242
+
243
+		if (!$config) {
244
+			self::make_site_config();
245
+
246
+			DB::alteration_message("Added default site config", "created");
247
+		}
248
+	}
249
+
250
+	/**
251
+	 * Create SiteConfig with defaults from language file.
252
+	 *
253
+	 * @return SiteConfig
254
+	 */
255
+	public static function make_site_config()
256
+	{
257
+		$config = SiteConfig::create();
258
+		$config->write();
259
+
260
+		return $config;
261
+	}
262
+
263
+	/**
264
+	 * Can a user view this SiteConfig instance?
265
+	 *
266
+	 * @param Member $member
267
+	 * @return boolean
268
+	 */
269
+	public function canView($member = null)
270
+	{
271
+		if (!$member) {
272
+			$member = Member::currentUserID();
273
+		}
274
+		if ($member && is_numeric($member)) {
275
+			$member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member);
276
+		}
277
+
278
+		$extended = $this->extendedCan('canView', $member);
279
+		if ($extended !== null) {
280
+			return $extended;
281
+		}
282
+
283
+		// Assuming all that can edit this object can also view it
284
+		return $this->canEdit($member);
285
+	}
286
+
287
+	/**
288
+	 * Can a user view pages on this site? This method is only
289
+	 * called if a page is set to Inherit, but there is nothing
290
+	 * to inherit from.
291
+	 *
292
+	 * @param Member $member
293
+	 * @return boolean
294
+	 */
295
+	public function canViewPages($member = null)
296
+	{
297
+		if (!$member) {
298
+			$member = Member::currentUserID();
299
+		}
300
+		if ($member && is_numeric($member)) {
301
+			$member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member);
302
+		}
303
+
304
+		if ($member && Permission::checkMember($member, "ADMIN")) {
305
+			return true;
306
+		}
307
+
308
+		$extended = $this->extendedCan('canViewPages', $member);
309
+		if ($extended !== null) {
310
+			return $extended;
311
+		}
312
+
313
+		if (!$this->CanViewType || $this->CanViewType == 'Anyone') {
314
+			return true;
315
+		}
316
+
317
+		// check for any logged-in users
318
+		if ($this->CanViewType === 'LoggedInUsers' && $member) {
319
+			return true;
320
+		}
321
+
322
+		// check for specific groups
323
+		if ($this->CanViewType === 'OnlyTheseUsers' && $member && $member->inGroups($this->ViewerGroups())) {
324
+			return true;
325
+		}
326
+
327
+		return false;
328
+	}
329
+
330
+	/**
331
+	 * Can a user edit pages on this site? This method is only
332
+	 * called if a page is set to Inherit, but there is nothing
333
+	 * to inherit from, or on new records without a parent.
334
+	 *
335
+	 * @param Member $member
336
+	 * @return boolean
337
+	 */
338
+	public function canEditPages($member = null)
339
+	{
340
+		if (!$member) {
341
+			$member = Member::currentUserID();
342
+		}
343
+		if ($member && is_numeric($member)) {
344
+			$member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member);
345
+		}
346
+
347
+		if ($member && Permission::checkMember($member, "ADMIN")) {
348
+			return true;
349
+		}
350
+
351
+		$extended = $this->extendedCan('canEditPages', $member);
352
+		if ($extended !== null) {
353
+			return $extended;
354
+		}
355
+
356
+		// check for any logged-in users with CMS access
357
+		if ($this->CanEditType === 'LoggedInUsers'
358
+			&& Permission::checkMember($member, $this->config()->required_permission)
359
+		) {
360
+			return true;
361
+		}
362
+
363
+			// check for specific groups
364
+		if ($this->CanEditType === 'OnlyTheseUsers' && $member && $member->inGroups($this->EditorGroups())) {
365
+			return true;
366
+		}
367
+
368
+		return false;
369
+	}
370
+
371
+	public function canEdit($member = null)
372
+	{
373
+		if (!$member) {
374
+			$member = Member::currentUserID();
375
+		}
376
+		if ($member && is_numeric($member)) {
377
+			$member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member);
378
+		}
379
+
380
+		$extended = $this->extendedCan('canEdit', $member);
381
+		if ($extended !== null) {
382
+			return $extended;
383
+		}
384
+
385
+		return Permission::checkMember($member, "EDIT_SITECONFIG");
386
+	}
387
+
388
+	/**
389
+	 * @return array
390
+	 */
391
+	public function providePermissions()
392
+	{
393
+		return array(
394
+			'EDIT_SITECONFIG' => array(
395
+				'name' => _t('SiteConfig.EDIT_PERMISSION', 'Manage site configuration'),
396
+				'category' => _t('Permissions.PERMISSIONS_CATEGORY', 'Roles and access permissions'),
397
+				'help' => _t('SiteConfig.EDIT_PERMISSION_HELP', 'Ability to edit global access settings/top-level page permissions.'),
398
+				'sort' => 400
399
+			)
400
+		);
401
+	}
402
+
403
+	/**
404
+	 * Can a user create pages in the root of this site?
405
+	 *
406
+	 * @param Member $member
407
+	 * @return boolean
408
+	 */
409
+	public function canCreateTopLevel($member = null)
410
+	{
411
+		if (!$member) {
412
+			$member = Member::currentUserID();
413
+		}
414
+		if ($member && is_numeric($member)) {
415
+			$member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member);
416
+		}
417
+
418
+		if ($member && Permission::checkMember($member, "ADMIN")) {
419
+			return true;
420
+		}
421
+
422
+		$extended = $this->extendedCan('canCreateTopLevel', $member);
423
+		if ($extended !== null) {
424
+			return $extended;
425
+		}
426
+
427
+		// check for any logged-in users with CMS permission
428
+		if ($this->CanCreateTopLevelType === 'LoggedInUsers'
429
+			&& Permission::checkMember($member, $this->config()->required_permission)
430
+		) {
431
+			return true;
432
+		}
433
+
434
+		// check for specific groups
435
+		if ($this->CanCreateTopLevelType === 'OnlyTheseUsers'
436
+			&& $member
437
+			&& $member->inGroups($this->CreateTopLevelGroups())
438
+		) {
439
+			return true;
440
+		}
441
+
442
+		return false;
443
+	}
444
+
445
+	/**
446
+	 * Add $SiteConfig to all SSViewers
447
+	 */
448
+	public static function get_template_global_variables()
449
+	{
450
+		return array(
451
+			'SiteConfig' => 'current_site_config',
452
+		);
453
+	}
454 454
 }
Please login to merge, or discard this patch.