Completed
Push — master ( 25a516...fbacac )
by Ingo
10s
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
@@ -22,428 +22,428 @@
 block discarded – undo
22 22
  */
23 23
 class SiteConfig extends DataObject implements PermissionProvider, TemplateGlobalProvider
24 24
 {
25
-    private static $db = array(
26
-        "Title" => "Varchar(255)",
27
-        "Tagline" => "Varchar(255)",
28
-        "Theme" => "Varchar(255)",
29
-        "CanViewType" => "Enum('Anyone, LoggedInUsers, OnlyTheseUsers', 'Anyone')",
30
-        "CanEditType" => "Enum('LoggedInUsers, OnlyTheseUsers', 'LoggedInUsers')",
31
-        "CanCreateTopLevelType" => "Enum('LoggedInUsers, OnlyTheseUsers', 'LoggedInUsers')",
32
-    );
33
-
34
-    private static $many_many = array(
35
-        "ViewerGroups" => "Group",
36
-        "EditorGroups" => "Group",
37
-        "CreateTopLevelGroups" => "Group"
38
-    );
39
-
40
-    private static $defaults = array(
41
-        "CanViewType" => "Anyone",
42
-        "CanEditType" => "LoggedInUsers",
43
-        "CanCreateTopLevelType" => "LoggedInUsers",
44
-    );
45
-
46
-    /**
47
-     * @config
48
-     *
49
-     * @var array
50
-     */
51
-    private static $disabled_themes = array();
52
-
53
-    /**
54
-     * Default permission to check for 'LoggedInUsers' to create or edit pages
55
-     *
56
-     * @var array
57
-     * @config
58
-     */
59
-    private static $required_permission = array('CMS_ACCESS_CMSMain', 'CMS_ACCESS_LeftAndMain');
60
-
61
-
62
-    public function populateDefaults()
63
-    {
64
-        $this->Title = _t('SiteConfig.SITENAMEDEFAULT', "Your Site Name");
65
-        $this->Tagline = _t('SiteConfig.TAGLINEDEFAULT', "your tagline here");
66
-
67
-        // Allow these defaults to be overridden
68
-        parent::populateDefaults();
69
-    }
70
-
71
-    /**
72
-     * Get the fields that are sent to the CMS.
73
-     *
74
-     * In your extensions: updateCMSFields($fields).
75
-     *
76
-     * @return FieldList
77
-     */
78
-    public function getCMSFields()
79
-    {
80
-        $groupsMap = array();
81
-
82
-        foreach (Group::get() as $group) {
83
-            // Listboxfield values are escaped, use ASCII char instead of &raquo;
84
-            $groupsMap[$group->ID] = $group->getBreadcrumbs(' > ');
85
-        }
86
-        asort($groupsMap);
87
-
88
-        $fields = new FieldList(
89
-            new TabSet("Root",
90
-                $tabMain = new Tab('Main',
91
-                    $titleField = new TextField("Title", _t('SiteConfig.SITETITLE', "Site title")),
92
-                    $taglineField = new TextField("Tagline", _t('SiteConfig.SITETAGLINE', "Site Tagline/Slogan")),
93
-                    $themeDropdownField = new DropdownField("Theme", _t('SiteConfig.THEME', 'Theme'), $this->getAvailableThemes())
94
-                ),
95
-                $tabAccess = new Tab('Access',
96
-                    $viewersOptionsField = new OptionsetField("CanViewType", _t('SiteConfig.VIEWHEADER', "Who can view pages on this site?")),
97
-                    $viewerGroupsField = ListboxField::create("ViewerGroups", _t('SiteTree.VIEWERGROUPS', "Viewer Groups"))
98
-                        ->setSource($groupsMap)
99
-                        ->setAttribute(
100
-                            'data-placeholder',
101
-                            _t('SiteTree.GroupPlaceholder', 'Click to select group')
102
-                        ),
103
-                    $editorsOptionsField = new OptionsetField("CanEditType", _t('SiteConfig.EDITHEADER', "Who can edit pages on this site?")),
104
-                    $editorGroupsField = ListboxField::create("EditorGroups", _t('SiteTree.EDITORGROUPS', "Editor Groups"))
105
-                        ->setSource($groupsMap)
106
-                        ->setAttribute(
107
-                            'data-placeholder',
108
-                            _t('SiteTree.GroupPlaceholder', 'Click to select group')
109
-                        ),
110
-                    $topLevelCreatorsOptionsField = new OptionsetField("CanCreateTopLevelType", _t('SiteConfig.TOPLEVELCREATE', "Who can create pages in the root of the site?")),
111
-                    $topLevelCreatorsGroupsField = ListboxField::create("CreateTopLevelGroups", _t('SiteTree.TOPLEVELCREATORGROUPS', "Top level creators"))
112
-                        ->setSource($groupsMap)
113
-                        ->setAttribute(
114
-                            'data-placeholder',
115
-                            _t('SiteTree.GroupPlaceholder', 'Click to select group')
116
-                        )
117
-                )
118
-            ),
119
-            new HiddenField('ID')
120
-        );
121
-
122
-        $themeDropdownField->setEmptyString(_t('SiteConfig.DEFAULTTHEME', '(Use default theme)'));
123
-
124
-        $viewersOptionsSource = array();
125
-        $viewersOptionsSource["Anyone"] = _t('SiteTree.ACCESSANYONE', "Anyone");
126
-        $viewersOptionsSource["LoggedInUsers"] = _t('SiteTree.ACCESSLOGGEDIN', "Logged-in users");
127
-        $viewersOptionsSource["OnlyTheseUsers"] = _t('SiteTree.ACCESSONLYTHESE', "Only these people (choose from list)");
128
-        $viewersOptionsField->setSource($viewersOptionsSource);
129
-
130
-        $editorsOptionsSource = array();
131
-        $editorsOptionsSource["LoggedInUsers"] = _t('SiteTree.EDITANYONE', "Anyone who can log-in to the CMS");
132
-        $editorsOptionsSource["OnlyTheseUsers"] = _t('SiteTree.EDITONLYTHESE', "Only these people (choose from list)");
133
-        $editorsOptionsField->setSource($editorsOptionsSource);
134
-
135
-        $topLevelCreatorsOptionsField->setSource($editorsOptionsSource);
136
-
137
-        if (!Permission::check('EDIT_SITECONFIG')) {
138
-            $fields->makeFieldReadonly($viewersOptionsField);
139
-            $fields->makeFieldReadonly($viewerGroupsField);
140
-            $fields->makeFieldReadonly($editorsOptionsField);
141
-            $fields->makeFieldReadonly($editorGroupsField);
142
-            $fields->makeFieldReadonly($topLevelCreatorsOptionsField);
143
-            $fields->makeFieldReadonly($topLevelCreatorsGroupsField);
144
-            $fields->makeFieldReadonly($taglineField);
145
-            $fields->makeFieldReadonly($titleField);
146
-        }
147
-
148
-        if (file_exists(BASE_PATH . '/install.php')) {
149
-            $fields->addFieldToTab("Root.Main", new LiteralField("InstallWarningHeader",
150
-                "<p class=\"message warning\">" . _t("SiteTree.REMOVE_INSTALL_WARNING",
151
-                "Warning: You should remove install.php from this SilverStripe install for security reasons.")
152
-                . "</p>"), "Title");
153
-        }
154
-
155
-        $tabMain->setTitle(_t('SiteConfig.TABMAIN', "Main"));
156
-        $tabAccess->setTitle(_t('SiteConfig.TABACCESS', "Access"));
157
-        $this->extend('updateCMSFields', $fields);
158
-
159
-        return $fields;
160
-    }
161
-
162
-    /**
163
-     * Get all available themes that haven't been marked as disabled.
164
-     *
165
-     * @param string $baseDir Optional alternative theme base directory for testing
166
-     *
167
-     * @return array of theme directory names
168
-     */
169
-    public function getAvailableThemes($baseDir = null)
170
-    {
171
-        $themes = SSViewer::get_themes($baseDir);
172
-        $disabled = (array)$this->config()->disabled_themes;
173
-
174
-        foreach ($disabled as $theme) {
175
-            if (isset($themes[$theme])) {
176
-                unset($themes[$theme]);
177
-            }
178
-        }
179
-
180
-        return $themes;
181
-    }
182
-
183
-    /**
184
-     * Get the actions that are sent to the CMS.
185
-     *
186
-     * In your extensions: updateEditFormActions($actions)
187
-     *
188
-     * @return FieldList
189
-     */
190
-    public function getCMSActions()
191
-    {
192
-        if (Permission::check('ADMIN') || Permission::check('EDIT_SITECONFIG')) {
193
-            $actions = new FieldList(
194
-                FormAction::create('save_siteconfig', _t('CMSMain.SAVE', 'Save'))
195
-                    ->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')
196
-            );
197
-        } else {
198
-            $actions = new FieldList();
199
-        }
200
-
201
-        $this->extend('updateCMSActions', $actions);
202
-
203
-        return $actions;
204
-    }
205
-
206
-    /**
207
-     * @return string
208
-     */
209
-    public function CMSEditLink()
210
-    {
211
-        return singleton('CMSSettingsController')->Link();
212
-    }
213
-
214
-    /**
215
-     * Get the current sites SiteConfig, and creates a new one through
216
-     * {@link make_site_config()} if none is found.
217
-     *
218
-     * @return SiteConfig
219
-     */
220
-    public static function current_site_config()
221
-    {
222
-        if ($siteConfig = DataObject::get_one('SiteConfig')) {
223
-            return $siteConfig;
224
-        }
225
-
226
-        return self::make_site_config();
227
-    }
228
-
229
-    /**
230
-     * Setup a default SiteConfig record if none exists.
231
-     */
232
-    public function requireDefaultRecords()
233
-    {
234
-        parent::requireDefaultRecords();
235
-
236
-        $config = DataObject::get_one('SiteConfig');
237
-
238
-        if (!$config) {
239
-            self::make_site_config();
240
-
241
-            DB::alteration_message("Added default site config", "created");
242
-        }
243
-    }
244
-
245
-    /**
246
-     * Create SiteConfig with defaults from language file.
247
-     *
248
-     * @return SiteConfig
249
-     */
250
-    public static function make_site_config()
251
-    {
252
-        $config = SiteConfig::create();
253
-        $config->write();
254
-
255
-        return $config;
256
-    }
257
-
258
-    /**
259
-     * Can a user view this SiteConfig instance?
260
-     *
261
-     * @param Member $member
262
-     * @return boolean
263
-     */
264
-    public function canView($member = null)
265
-    {
266
-        if (!$member) {
267
-            $member = Member::currentUserID();
268
-        }
269
-        if ($member && is_numeric($member)) {
270
-            $member = DataObject::get_by_id('Member', $member);
271
-        }
272
-
273
-        $extended = $this->extendedCan('canView', $member);
274
-        if ($extended !== null) {
275
-            return $extended;
276
-        }
277
-
278
-        // Assuming all that can edit this object can also view it
279
-        return $this->canEdit($member);
280
-    }
281
-
282
-    /**
283
-     * Can a user view pages on this site? This method is only
284
-     * called if a page is set to Inherit, but there is nothing
285
-     * to inherit from.
286
-     *
287
-     * @param Member $member
288
-     * @return boolean
289
-     */
290
-    public function canViewPages($member = null)
291
-    {
292
-        if (!$member) {
293
-            $member = Member::currentUserID();
294
-        }
295
-        if ($member && is_numeric($member)) {
296
-            $member = DataObject::get_by_id('Member', $member);
297
-        }
298
-
299
-        if ($member && Permission::checkMember($member, "ADMIN")) {
300
-            return true;
301
-        }
302
-
303
-        $extended = $this->extendedCan('canViewPages', $member);
304
-        if ($extended !== null) {
305
-            return $extended;
306
-        }
307
-
308
-        if (!$this->CanViewType || $this->CanViewType == 'Anyone') {
309
-            return true;
310
-        }
311
-
312
-        // check for any logged-in users
313
-        if ($this->CanViewType === 'LoggedInUsers' && $member) {
314
-            return true;
315
-        }
316
-
317
-        // check for specific groups
318
-        if ($this->CanViewType === 'OnlyTheseUsers' && $member && $member->inGroups($this->ViewerGroups())) {
319
-            return true;
320
-        }
321
-
322
-        return false;
323
-    }
324
-
325
-    /**
326
-     * Can a user edit pages on this site? This method is only
327
-     * called if a page is set to Inherit, but there is nothing
328
-     * to inherit from, or on new records without a parent.
329
-     *
330
-     * @param Member $member
331
-     * @return boolean
332
-     */
333
-    public function canEditPages($member = null)
334
-    {
335
-        if (!$member) {
336
-            $member = Member::currentUserID();
337
-        }
338
-        if ($member && is_numeric($member)) {
339
-            $member = DataObject::get_by_id('Member', $member);
340
-        }
341
-
342
-        if ($member && Permission::checkMember($member, "ADMIN")) {
343
-            return true;
344
-        }
345
-
346
-        $extended = $this->extendedCan('canEditPages', $member);
347
-        if ($extended !== null) {
348
-            return $extended;
349
-        }
350
-
351
-        // check for any logged-in users with CMS access
352
-        if ($this->CanEditType === 'LoggedInUsers'
353
-            && Permission::checkMember($member, $this->config()->required_permission)
354
-        ) {
355
-            return true;
356
-        }
357
-
358
-            // check for specific groups
359
-        if ($this->CanEditType === 'OnlyTheseUsers' && $member && $member->inGroups($this->EditorGroups())) {
360
-            return true;
361
-        }
362
-
363
-        return false;
364
-    }
365
-
366
-    public function canEdit($member = null)
367
-    {
368
-        if (!$member) {
369
-            $member = Member::currentUserID();
370
-        }
371
-        if ($member && is_numeric($member)) {
372
-            $member = DataObject::get_by_id('Member', $member);
373
-        }
374
-
375
-        $extended = $this->extendedCan('canEdit', $member);
376
-        if ($extended !== null) {
377
-            return $extended;
378
-        }
379
-
380
-        return Permission::checkMember($member, "EDIT_SITECONFIG");
381
-    }
382
-
383
-    /**
384
-     * @return array
385
-     */
386
-    public function providePermissions()
387
-    {
388
-        return array(
389
-            'EDIT_SITECONFIG' => array(
390
-                'name' => _t('SiteConfig.EDIT_PERMISSION', 'Manage site configuration'),
391
-                'category' => _t('Permissions.PERMISSIONS_CATEGORY', 'Roles and access permissions'),
392
-                'help' => _t('SiteConfig.EDIT_PERMISSION_HELP', 'Ability to edit global access settings/top-level page permissions.'),
393
-                'sort' => 400
394
-            )
395
-        );
396
-    }
397
-
398
-    /**
399
-     * Can a user create pages in the root of this site?
400
-     *
401
-     * @param Member $member
402
-     * @return boolean
403
-     */
404
-    public function canCreateTopLevel($member = null)
405
-    {
406
-        if (!$member) {
407
-            $member = Member::currentUserID();
408
-        }
409
-        if ($member && is_numeric($member)) {
410
-            $member = DataObject::get_by_id('Member', $member);
411
-        }
412
-
413
-        if ($member && Permission::checkMember($member, "ADMIN")) {
414
-            return true;
415
-        }
416
-
417
-        $extended = $this->extendedCan('canCreateTopLevel', $member);
418
-        if ($extended !== null) {
419
-            return $extended;
420
-        }
421
-
422
-        // check for any logged-in users with CMS permission
423
-        if ($this->CanCreateTopLevelType === 'LoggedInUsers'
424
-            && Permission::checkMember($member, $this->config()->required_permission)
425
-        ) {
426
-            return true;
427
-        }
428
-
429
-        // check for specific groups
430
-        if ($this->CanCreateTopLevelType === 'OnlyTheseUsers'
431
-            && $member
432
-            && $member->inGroups($this->CreateTopLevelGroups())
433
-        ) {
434
-            return true;
435
-        }
436
-
437
-        return false;
438
-    }
439
-
440
-    /**
441
-     * Add $SiteConfig to all SSViewers
442
-     */
443
-    public static function get_template_global_variables()
444
-    {
445
-        return array(
446
-            'SiteConfig' => 'current_site_config',
447
-        );
448
-    }
25
+	private static $db = array(
26
+		"Title" => "Varchar(255)",
27
+		"Tagline" => "Varchar(255)",
28
+		"Theme" => "Varchar(255)",
29
+		"CanViewType" => "Enum('Anyone, LoggedInUsers, OnlyTheseUsers', 'Anyone')",
30
+		"CanEditType" => "Enum('LoggedInUsers, OnlyTheseUsers', 'LoggedInUsers')",
31
+		"CanCreateTopLevelType" => "Enum('LoggedInUsers, OnlyTheseUsers', 'LoggedInUsers')",
32
+	);
33
+
34
+	private static $many_many = array(
35
+		"ViewerGroups" => "Group",
36
+		"EditorGroups" => "Group",
37
+		"CreateTopLevelGroups" => "Group"
38
+	);
39
+
40
+	private static $defaults = array(
41
+		"CanViewType" => "Anyone",
42
+		"CanEditType" => "LoggedInUsers",
43
+		"CanCreateTopLevelType" => "LoggedInUsers",
44
+	);
45
+
46
+	/**
47
+	 * @config
48
+	 *
49
+	 * @var array
50
+	 */
51
+	private static $disabled_themes = array();
52
+
53
+	/**
54
+	 * Default permission to check for 'LoggedInUsers' to create or edit pages
55
+	 *
56
+	 * @var array
57
+	 * @config
58
+	 */
59
+	private static $required_permission = array('CMS_ACCESS_CMSMain', 'CMS_ACCESS_LeftAndMain');
60
+
61
+
62
+	public function populateDefaults()
63
+	{
64
+		$this->Title = _t('SiteConfig.SITENAMEDEFAULT', "Your Site Name");
65
+		$this->Tagline = _t('SiteConfig.TAGLINEDEFAULT', "your tagline here");
66
+
67
+		// Allow these defaults to be overridden
68
+		parent::populateDefaults();
69
+	}
70
+
71
+	/**
72
+	 * Get the fields that are sent to the CMS.
73
+	 *
74
+	 * In your extensions: updateCMSFields($fields).
75
+	 *
76
+	 * @return FieldList
77
+	 */
78
+	public function getCMSFields()
79
+	{
80
+		$groupsMap = array();
81
+
82
+		foreach (Group::get() as $group) {
83
+			// Listboxfield values are escaped, use ASCII char instead of &raquo;
84
+			$groupsMap[$group->ID] = $group->getBreadcrumbs(' > ');
85
+		}
86
+		asort($groupsMap);
87
+
88
+		$fields = new FieldList(
89
+			new TabSet("Root",
90
+				$tabMain = new Tab('Main',
91
+					$titleField = new TextField("Title", _t('SiteConfig.SITETITLE', "Site title")),
92
+					$taglineField = new TextField("Tagline", _t('SiteConfig.SITETAGLINE', "Site Tagline/Slogan")),
93
+					$themeDropdownField = new DropdownField("Theme", _t('SiteConfig.THEME', 'Theme'), $this->getAvailableThemes())
94
+				),
95
+				$tabAccess = new Tab('Access',
96
+					$viewersOptionsField = new OptionsetField("CanViewType", _t('SiteConfig.VIEWHEADER', "Who can view pages on this site?")),
97
+					$viewerGroupsField = ListboxField::create("ViewerGroups", _t('SiteTree.VIEWERGROUPS', "Viewer Groups"))
98
+						->setSource($groupsMap)
99
+						->setAttribute(
100
+							'data-placeholder',
101
+							_t('SiteTree.GroupPlaceholder', 'Click to select group')
102
+						),
103
+					$editorsOptionsField = new OptionsetField("CanEditType", _t('SiteConfig.EDITHEADER', "Who can edit pages on this site?")),
104
+					$editorGroupsField = ListboxField::create("EditorGroups", _t('SiteTree.EDITORGROUPS', "Editor Groups"))
105
+						->setSource($groupsMap)
106
+						->setAttribute(
107
+							'data-placeholder',
108
+							_t('SiteTree.GroupPlaceholder', 'Click to select group')
109
+						),
110
+					$topLevelCreatorsOptionsField = new OptionsetField("CanCreateTopLevelType", _t('SiteConfig.TOPLEVELCREATE', "Who can create pages in the root of the site?")),
111
+					$topLevelCreatorsGroupsField = ListboxField::create("CreateTopLevelGroups", _t('SiteTree.TOPLEVELCREATORGROUPS', "Top level creators"))
112
+						->setSource($groupsMap)
113
+						->setAttribute(
114
+							'data-placeholder',
115
+							_t('SiteTree.GroupPlaceholder', 'Click to select group')
116
+						)
117
+				)
118
+			),
119
+			new HiddenField('ID')
120
+		);
121
+
122
+		$themeDropdownField->setEmptyString(_t('SiteConfig.DEFAULTTHEME', '(Use default theme)'));
123
+
124
+		$viewersOptionsSource = array();
125
+		$viewersOptionsSource["Anyone"] = _t('SiteTree.ACCESSANYONE', "Anyone");
126
+		$viewersOptionsSource["LoggedInUsers"] = _t('SiteTree.ACCESSLOGGEDIN', "Logged-in users");
127
+		$viewersOptionsSource["OnlyTheseUsers"] = _t('SiteTree.ACCESSONLYTHESE', "Only these people (choose from list)");
128
+		$viewersOptionsField->setSource($viewersOptionsSource);
129
+
130
+		$editorsOptionsSource = array();
131
+		$editorsOptionsSource["LoggedInUsers"] = _t('SiteTree.EDITANYONE', "Anyone who can log-in to the CMS");
132
+		$editorsOptionsSource["OnlyTheseUsers"] = _t('SiteTree.EDITONLYTHESE', "Only these people (choose from list)");
133
+		$editorsOptionsField->setSource($editorsOptionsSource);
134
+
135
+		$topLevelCreatorsOptionsField->setSource($editorsOptionsSource);
136
+
137
+		if (!Permission::check('EDIT_SITECONFIG')) {
138
+			$fields->makeFieldReadonly($viewersOptionsField);
139
+			$fields->makeFieldReadonly($viewerGroupsField);
140
+			$fields->makeFieldReadonly($editorsOptionsField);
141
+			$fields->makeFieldReadonly($editorGroupsField);
142
+			$fields->makeFieldReadonly($topLevelCreatorsOptionsField);
143
+			$fields->makeFieldReadonly($topLevelCreatorsGroupsField);
144
+			$fields->makeFieldReadonly($taglineField);
145
+			$fields->makeFieldReadonly($titleField);
146
+		}
147
+
148
+		if (file_exists(BASE_PATH . '/install.php')) {
149
+			$fields->addFieldToTab("Root.Main", new LiteralField("InstallWarningHeader",
150
+				"<p class=\"message warning\">" . _t("SiteTree.REMOVE_INSTALL_WARNING",
151
+				"Warning: You should remove install.php from this SilverStripe install for security reasons.")
152
+				. "</p>"), "Title");
153
+		}
154
+
155
+		$tabMain->setTitle(_t('SiteConfig.TABMAIN', "Main"));
156
+		$tabAccess->setTitle(_t('SiteConfig.TABACCESS', "Access"));
157
+		$this->extend('updateCMSFields', $fields);
158
+
159
+		return $fields;
160
+	}
161
+
162
+	/**
163
+	 * Get all available themes that haven't been marked as disabled.
164
+	 *
165
+	 * @param string $baseDir Optional alternative theme base directory for testing
166
+	 *
167
+	 * @return array of theme directory names
168
+	 */
169
+	public function getAvailableThemes($baseDir = null)
170
+	{
171
+		$themes = SSViewer::get_themes($baseDir);
172
+		$disabled = (array)$this->config()->disabled_themes;
173
+
174
+		foreach ($disabled as $theme) {
175
+			if (isset($themes[$theme])) {
176
+				unset($themes[$theme]);
177
+			}
178
+		}
179
+
180
+		return $themes;
181
+	}
182
+
183
+	/**
184
+	 * Get the actions that are sent to the CMS.
185
+	 *
186
+	 * In your extensions: updateEditFormActions($actions)
187
+	 *
188
+	 * @return FieldList
189
+	 */
190
+	public function getCMSActions()
191
+	{
192
+		if (Permission::check('ADMIN') || Permission::check('EDIT_SITECONFIG')) {
193
+			$actions = new FieldList(
194
+				FormAction::create('save_siteconfig', _t('CMSMain.SAVE', 'Save'))
195
+					->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')
196
+			);
197
+		} else {
198
+			$actions = new FieldList();
199
+		}
200
+
201
+		$this->extend('updateCMSActions', $actions);
202
+
203
+		return $actions;
204
+	}
205
+
206
+	/**
207
+	 * @return string
208
+	 */
209
+	public function CMSEditLink()
210
+	{
211
+		return singleton('CMSSettingsController')->Link();
212
+	}
213
+
214
+	/**
215
+	 * Get the current sites SiteConfig, and creates a new one through
216
+	 * {@link make_site_config()} if none is found.
217
+	 *
218
+	 * @return SiteConfig
219
+	 */
220
+	public static function current_site_config()
221
+	{
222
+		if ($siteConfig = DataObject::get_one('SiteConfig')) {
223
+			return $siteConfig;
224
+		}
225
+
226
+		return self::make_site_config();
227
+	}
228
+
229
+	/**
230
+	 * Setup a default SiteConfig record if none exists.
231
+	 */
232
+	public function requireDefaultRecords()
233
+	{
234
+		parent::requireDefaultRecords();
235
+
236
+		$config = DataObject::get_one('SiteConfig');
237
+
238
+		if (!$config) {
239
+			self::make_site_config();
240
+
241
+			DB::alteration_message("Added default site config", "created");
242
+		}
243
+	}
244
+
245
+	/**
246
+	 * Create SiteConfig with defaults from language file.
247
+	 *
248
+	 * @return SiteConfig
249
+	 */
250
+	public static function make_site_config()
251
+	{
252
+		$config = SiteConfig::create();
253
+		$config->write();
254
+
255
+		return $config;
256
+	}
257
+
258
+	/**
259
+	 * Can a user view this SiteConfig instance?
260
+	 *
261
+	 * @param Member $member
262
+	 * @return boolean
263
+	 */
264
+	public function canView($member = null)
265
+	{
266
+		if (!$member) {
267
+			$member = Member::currentUserID();
268
+		}
269
+		if ($member && is_numeric($member)) {
270
+			$member = DataObject::get_by_id('Member', $member);
271
+		}
272
+
273
+		$extended = $this->extendedCan('canView', $member);
274
+		if ($extended !== null) {
275
+			return $extended;
276
+		}
277
+
278
+		// Assuming all that can edit this object can also view it
279
+		return $this->canEdit($member);
280
+	}
281
+
282
+	/**
283
+	 * Can a user view pages on this site? This method is only
284
+	 * called if a page is set to Inherit, but there is nothing
285
+	 * to inherit from.
286
+	 *
287
+	 * @param Member $member
288
+	 * @return boolean
289
+	 */
290
+	public function canViewPages($member = null)
291
+	{
292
+		if (!$member) {
293
+			$member = Member::currentUserID();
294
+		}
295
+		if ($member && is_numeric($member)) {
296
+			$member = DataObject::get_by_id('Member', $member);
297
+		}
298
+
299
+		if ($member && Permission::checkMember($member, "ADMIN")) {
300
+			return true;
301
+		}
302
+
303
+		$extended = $this->extendedCan('canViewPages', $member);
304
+		if ($extended !== null) {
305
+			return $extended;
306
+		}
307
+
308
+		if (!$this->CanViewType || $this->CanViewType == 'Anyone') {
309
+			return true;
310
+		}
311
+
312
+		// check for any logged-in users
313
+		if ($this->CanViewType === 'LoggedInUsers' && $member) {
314
+			return true;
315
+		}
316
+
317
+		// check for specific groups
318
+		if ($this->CanViewType === 'OnlyTheseUsers' && $member && $member->inGroups($this->ViewerGroups())) {
319
+			return true;
320
+		}
321
+
322
+		return false;
323
+	}
324
+
325
+	/**
326
+	 * Can a user edit pages on this site? This method is only
327
+	 * called if a page is set to Inherit, but there is nothing
328
+	 * to inherit from, or on new records without a parent.
329
+	 *
330
+	 * @param Member $member
331
+	 * @return boolean
332
+	 */
333
+	public function canEditPages($member = null)
334
+	{
335
+		if (!$member) {
336
+			$member = Member::currentUserID();
337
+		}
338
+		if ($member && is_numeric($member)) {
339
+			$member = DataObject::get_by_id('Member', $member);
340
+		}
341
+
342
+		if ($member && Permission::checkMember($member, "ADMIN")) {
343
+			return true;
344
+		}
345
+
346
+		$extended = $this->extendedCan('canEditPages', $member);
347
+		if ($extended !== null) {
348
+			return $extended;
349
+		}
350
+
351
+		// check for any logged-in users with CMS access
352
+		if ($this->CanEditType === 'LoggedInUsers'
353
+			&& Permission::checkMember($member, $this->config()->required_permission)
354
+		) {
355
+			return true;
356
+		}
357
+
358
+			// check for specific groups
359
+		if ($this->CanEditType === 'OnlyTheseUsers' && $member && $member->inGroups($this->EditorGroups())) {
360
+			return true;
361
+		}
362
+
363
+		return false;
364
+	}
365
+
366
+	public function canEdit($member = null)
367
+	{
368
+		if (!$member) {
369
+			$member = Member::currentUserID();
370
+		}
371
+		if ($member && is_numeric($member)) {
372
+			$member = DataObject::get_by_id('Member', $member);
373
+		}
374
+
375
+		$extended = $this->extendedCan('canEdit', $member);
376
+		if ($extended !== null) {
377
+			return $extended;
378
+		}
379
+
380
+		return Permission::checkMember($member, "EDIT_SITECONFIG");
381
+	}
382
+
383
+	/**
384
+	 * @return array
385
+	 */
386
+	public function providePermissions()
387
+	{
388
+		return array(
389
+			'EDIT_SITECONFIG' => array(
390
+				'name' => _t('SiteConfig.EDIT_PERMISSION', 'Manage site configuration'),
391
+				'category' => _t('Permissions.PERMISSIONS_CATEGORY', 'Roles and access permissions'),
392
+				'help' => _t('SiteConfig.EDIT_PERMISSION_HELP', 'Ability to edit global access settings/top-level page permissions.'),
393
+				'sort' => 400
394
+			)
395
+		);
396
+	}
397
+
398
+	/**
399
+	 * Can a user create pages in the root of this site?
400
+	 *
401
+	 * @param Member $member
402
+	 * @return boolean
403
+	 */
404
+	public function canCreateTopLevel($member = null)
405
+	{
406
+		if (!$member) {
407
+			$member = Member::currentUserID();
408
+		}
409
+		if ($member && is_numeric($member)) {
410
+			$member = DataObject::get_by_id('Member', $member);
411
+		}
412
+
413
+		if ($member && Permission::checkMember($member, "ADMIN")) {
414
+			return true;
415
+		}
416
+
417
+		$extended = $this->extendedCan('canCreateTopLevel', $member);
418
+		if ($extended !== null) {
419
+			return $extended;
420
+		}
421
+
422
+		// check for any logged-in users with CMS permission
423
+		if ($this->CanCreateTopLevelType === 'LoggedInUsers'
424
+			&& Permission::checkMember($member, $this->config()->required_permission)
425
+		) {
426
+			return true;
427
+		}
428
+
429
+		// check for specific groups
430
+		if ($this->CanCreateTopLevelType === 'OnlyTheseUsers'
431
+			&& $member
432
+			&& $member->inGroups($this->CreateTopLevelGroups())
433
+		) {
434
+			return true;
435
+		}
436
+
437
+		return false;
438
+	}
439
+
440
+	/**
441
+	 * Add $SiteConfig to all SSViewers
442
+	 */
443
+	public static function get_template_global_variables()
444
+	{
445
+		return array(
446
+			'SiteConfig' => 'current_site_config',
447
+		);
448
+	}
449 449
 }
Please login to merge, or discard this patch.