Completed
Pull Request — master (#70)
by Robbie
02:42
created
tests/Report/CwpStatsReportTest.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -9,35 +9,35 @@
 block discarded – undo
9 9
 
10 10
 class CwpStatsReportTest extends SapphireTest
11 11
 {
12
-    protected static $fixture_file = 'CwpStatsReportTest.yml';
12
+	protected static $fixture_file = 'CwpStatsReportTest.yml';
13 13
 
14
-    public function testCount()
15
-    {
16
-        // Publish all pages apart from page3.
17
-        $this->objFromFixture(Page::class, 'page1')->publishRecursive();
18
-        $this->objFromFixture(Page::class, 'page2')->publishRecursive();
19
-        $this->objFromFixture(Page::class, 'page3')->publishRecursive();
14
+	public function testCount()
15
+	{
16
+		// Publish all pages apart from page3.
17
+		$this->objFromFixture(Page::class, 'page1')->publishRecursive();
18
+		$this->objFromFixture(Page::class, 'page2')->publishRecursive();
19
+		$this->objFromFixture(Page::class, 'page3')->publishRecursive();
20 20
 
21
-        // Add page5s to a subsite, if the module is installed.
22
-        $page5s = $this->objFromFixture(Page::class, 'page5s');
23
-        if (class_exists(Subsite::class)) {
24
-            $subsite = Subsite::create();
25
-            $subsite->Title = 'subsite';
26
-            $subsite->write();
21
+		// Add page5s to a subsite, if the module is installed.
22
+		$page5s = $this->objFromFixture(Page::class, 'page5s');
23
+		if (class_exists(Subsite::class)) {
24
+			$subsite = Subsite::create();
25
+			$subsite->Title = 'subsite';
26
+			$subsite->write();
27 27
 
28
-            $page5s->SubsiteID = $subsite->ID;
29
-            $page5s->write();
30
-        }
31
-        $page5s->publishRecursive();
28
+			$page5s->SubsiteID = $subsite->ID;
29
+			$page5s->write();
30
+		}
31
+		$page5s->publishRecursive();
32 32
 
33
-        $report = CwpStatsReport::create();
34
-        $records = $report->sourceRecords([])->toArray();
35
-        $i = 0;
36
-        $this->assertEquals($records[$i++]['Count'], 4, 'Four pages in total, across locales, subsites, live only.');
37
-        if (class_exists(Subsite::class)) {
38
-            $this->assertEquals($records[$i++]['Count'], 3, 'Three pages in the main site, if subsites installed.');
39
-            $this->assertEquals($records[$i++]['Count'], 1, 'One page in the subsite, if subsites installed');
40
-        }
41
-        $this->assertEquals($records[$i++]['Count'], 1, 'One file in total.');
42
-    }
33
+		$report = CwpStatsReport::create();
34
+		$records = $report->sourceRecords([])->toArray();
35
+		$i = 0;
36
+		$this->assertEquals($records[$i++]['Count'], 4, 'Four pages in total, across locales, subsites, live only.');
37
+		if (class_exists(Subsite::class)) {
38
+			$this->assertEquals($records[$i++]['Count'], 3, 'Three pages in the main site, if subsites installed.');
39
+			$this->assertEquals($records[$i++]['Count'], 1, 'One page in the subsite, if subsites installed');
40
+		}
41
+		$this->assertEquals($records[$i++]['Count'], 1, 'One file in total.');
42
+	}
43 43
 }
Please login to merge, or discard this patch.
src/Report/CwpStatsReport.php 1 patch
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -20,108 +20,108 @@
 block discarded – undo
20 20
  */
21 21
 class CwpStatsReport extends Report
22 22
 {
23
-    public function title()
24
-    {
25
-        return _t(__CLASS__ . '.Title', 'Summary statistics');
26
-    }
27
-
28
-    public function description()
29
-    {
30
-        return _t(
31
-            __CLASS__ . '.Description',
32
-            'This report provides various statistics for this site. The "total live page count" is the number that ' .
33
-                'can be compared against the instance size specifications.'
34
-        );
35
-    }
36
-
37
-    public function columns()
38
-    {
39
-        return [
40
-            'Name' => _t(__CLASS__ . '.Name', 'Name'),
41
-            'Count' => _t(__CLASS__ . '.Count', 'Count'),
42
-        ];
43
-    }
44
-
45
-    /**
46
-     * Manually create source records for the report. Agreggates cannot be provided as a column of a DataQuery result.
47
-     *
48
-     * {@inheritDoc}
49
-     */
50
-    public function sourceRecords($params = [], $sort = null, $limit = null)
51
-    {
52
-        $records = [];
53
-
54
-        // Get the query to apply across all variants: looks at all subsites, translations, live stage only.
55
-        $crossVariant = (function ($dataQuery) {
56
-            $params = [
57
-                'Subsite.filter' => false,
58
-                'Versioned.mode' => 'stage',
59
-                'Versioned.stage' => Versioned::LIVE,
60
-            ];
61
-
62
-            return $dataQuery->setDataQueryParam($params);
63
-        });
64
-
65
-        // Total.
66
-        $records[] = [
67
-            'Name' => _t(
68
-                __CLASS__ . '.TotalPageCount',
69
-                'Total live page count, across all translations and subsites'
70
-            ),
71
-            'Count' => $crossVariant(SiteTree::get())->count(),
72
-        ];
73
-
74
-        if (class_exists(Subsite::class)) {
75
-            // Main site.
76
-            $records[] = [
77
-                'Name' => _t(__CLASS__ . '.PagesForMainSite', '- in the main site'),
78
-                'Count' => $crossVariant(SiteTree::get())
79
-                    ->filter(['SubsiteID' => 0])
80
-                    ->count(),
81
-            ];
82
-
83
-            // Per subsite.
84
-            $subsites = Subsite::get();
85
-            foreach ($subsites as $subsite) {
86
-                $records[] = [
87
-                    'Name' => _t(
88
-                        __CLASS__ . '.PagesForSubsite',
89
-                        "- in the subsite '{SubsiteTitle}'",
90
-                        ['SubsiteTitle' => $subsite->Title]
91
-                    ),
92
-                    'Count' => $crossVariant(SiteTree::get())
93
-                        ->filter(['SubsiteID' => $subsite->ID])
94
-                        ->count(),
95
-                ];
96
-            }
97
-        }
98
-
99
-        // Files.
100
-        $records[] = [
101
-            'Name' => _t(__CLASS__ . '.FileCount', 'File count'),
102
-            'Count' => File::get()
103
-                ->setDataQueryParam('Subsite.filter', false)
104
-                ->filter(['ClassName:not' => Folder::class])
105
-                ->count(),
106
-        ];
107
-
108
-        return ArrayList::create($records);
109
-    }
110
-
111
-    /**
112
-     * @return GridField
113
-     */
114
-    public function getReportField()
115
-    {
116
-        /** @var GridField $gridField */
117
-        $gridField = parent::getReportField();
118
-
119
-        /** @var GridFieldConfig $gridConfig */
120
-        $gridConfig = $gridField->getConfig();
121
-        $gridConfig->removeComponentsByType(GridFieldPrintButton::class);
122
-        $gridConfig->removeComponentsByType(GridFieldExportButton::class);
123
-        $gridConfig->removeComponentsByType(GridFieldSortableHeader::class);
124
-
125
-        return $gridField;
126
-    }
23
+	public function title()
24
+	{
25
+		return _t(__CLASS__ . '.Title', 'Summary statistics');
26
+	}
27
+
28
+	public function description()
29
+	{
30
+		return _t(
31
+			__CLASS__ . '.Description',
32
+			'This report provides various statistics for this site. The "total live page count" is the number that ' .
33
+				'can be compared against the instance size specifications.'
34
+		);
35
+	}
36
+
37
+	public function columns()
38
+	{
39
+		return [
40
+			'Name' => _t(__CLASS__ . '.Name', 'Name'),
41
+			'Count' => _t(__CLASS__ . '.Count', 'Count'),
42
+		];
43
+	}
44
+
45
+	/**
46
+	 * Manually create source records for the report. Agreggates cannot be provided as a column of a DataQuery result.
47
+	 *
48
+	 * {@inheritDoc}
49
+	 */
50
+	public function sourceRecords($params = [], $sort = null, $limit = null)
51
+	{
52
+		$records = [];
53
+
54
+		// Get the query to apply across all variants: looks at all subsites, translations, live stage only.
55
+		$crossVariant = (function ($dataQuery) {
56
+			$params = [
57
+				'Subsite.filter' => false,
58
+				'Versioned.mode' => 'stage',
59
+				'Versioned.stage' => Versioned::LIVE,
60
+			];
61
+
62
+			return $dataQuery->setDataQueryParam($params);
63
+		});
64
+
65
+		// Total.
66
+		$records[] = [
67
+			'Name' => _t(
68
+				__CLASS__ . '.TotalPageCount',
69
+				'Total live page count, across all translations and subsites'
70
+			),
71
+			'Count' => $crossVariant(SiteTree::get())->count(),
72
+		];
73
+
74
+		if (class_exists(Subsite::class)) {
75
+			// Main site.
76
+			$records[] = [
77
+				'Name' => _t(__CLASS__ . '.PagesForMainSite', '- in the main site'),
78
+				'Count' => $crossVariant(SiteTree::get())
79
+					->filter(['SubsiteID' => 0])
80
+					->count(),
81
+			];
82
+
83
+			// Per subsite.
84
+			$subsites = Subsite::get();
85
+			foreach ($subsites as $subsite) {
86
+				$records[] = [
87
+					'Name' => _t(
88
+						__CLASS__ . '.PagesForSubsite',
89
+						"- in the subsite '{SubsiteTitle}'",
90
+						['SubsiteTitle' => $subsite->Title]
91
+					),
92
+					'Count' => $crossVariant(SiteTree::get())
93
+						->filter(['SubsiteID' => $subsite->ID])
94
+						->count(),
95
+				];
96
+			}
97
+		}
98
+
99
+		// Files.
100
+		$records[] = [
101
+			'Name' => _t(__CLASS__ . '.FileCount', 'File count'),
102
+			'Count' => File::get()
103
+				->setDataQueryParam('Subsite.filter', false)
104
+				->filter(['ClassName:not' => Folder::class])
105
+				->count(),
106
+		];
107
+
108
+		return ArrayList::create($records);
109
+	}
110
+
111
+	/**
112
+	 * @return GridField
113
+	 */
114
+	public function getReportField()
115
+	{
116
+		/** @var GridField $gridField */
117
+		$gridField = parent::getReportField();
118
+
119
+		/** @var GridFieldConfig $gridConfig */
120
+		$gridConfig = $gridField->getConfig();
121
+		$gridConfig->removeComponentsByType(GridFieldPrintButton::class);
122
+		$gridConfig->removeComponentsByType(GridFieldExportButton::class);
123
+		$gridConfig->removeComponentsByType(GridFieldSortableHeader::class);
124
+
125
+		return $gridField;
126
+	}
127 127
 }
Please login to merge, or discard this patch.
src/Extensions/CustomSiteConfig.php 1 patch
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -12,58 +12,58 @@
 block discarded – undo
12 12
  */
13 13
 class CustomSiteConfig extends DataExtension
14 14
 {
15
-    private static $db = array(
16
-        'GACode' => 'Varchar(16)',
17
-        'FacebookURL' => 'Varchar(256)', // multitude of ways to link to Facebook accounts, best to leave it open.
18
-        'TwitterUsername' => 'Varchar(16)', // max length of Twitter username 15
19
-    );
15
+	private static $db = array(
16
+		'GACode' => 'Varchar(16)',
17
+		'FacebookURL' => 'Varchar(256)', // multitude of ways to link to Facebook accounts, best to leave it open.
18
+		'TwitterUsername' => 'Varchar(16)', // max length of Twitter username 15
19
+	);
20 20
 
21
-    public function updateCMSFields(FieldList $fields)
22
-    {
23
-        $fields->addFieldToTab(
24
-            'Root.Main',
25
-            $gaCode = TextField::create(
26
-                'GACode',
27
-                _t(__CLASS__ . '.GaField', 'Google Analytics account')
28
-            )
29
-        );
21
+	public function updateCMSFields(FieldList $fields)
22
+	{
23
+		$fields->addFieldToTab(
24
+			'Root.Main',
25
+			$gaCode = TextField::create(
26
+				'GACode',
27
+				_t(__CLASS__ . '.GaField', 'Google Analytics account')
28
+			)
29
+		);
30 30
 
31
-        $gaCode->setRightTitle(
32
-            DBField::create_field('HTMLFragment', _t(
33
-                __CLASS__ . '.GaFieldDesc',
34
-                'Account number to be used all across the site (in the format <strong>UA-XXXXX-X</strong>)'
35
-            ))
36
-        );
31
+		$gaCode->setRightTitle(
32
+			DBField::create_field('HTMLFragment', _t(
33
+				__CLASS__ . '.GaFieldDesc',
34
+				'Account number to be used all across the site (in the format <strong>UA-XXXXX-X</strong>)'
35
+			))
36
+		);
37 37
 
38
-        $fields->findOrMakeTab('Root.SocialMedia', _t(__CLASS__ . '.SocialMediaTab', 'Social Media'));
38
+		$fields->findOrMakeTab('Root.SocialMedia', _t(__CLASS__ . '.SocialMediaTab', 'Social Media'));
39 39
 
40
-        $fields->addFieldToTab(
41
-            'Root.SocialMedia',
42
-            $facebookURL = TextField::create(
43
-                'FacebookURL',
44
-                _t(__CLASS__ . '.FbField', 'Facebook UID or username')
45
-            )
46
-        );
47
-        $facebookURL->setRightTitle(
48
-            DBField::create_field('HTMLFragment', _t(
49
-                __CLASS__ . '.FbFieldDesc',
50
-                'Facebook link (everything after the "http://facebook.com/", eg http://facebook.com/'
51
-                . '<strong>username</strong> or http://facebook.com/<strong>pages/108510539573</strong>)'
52
-            ))
53
-        );
40
+		$fields->addFieldToTab(
41
+			'Root.SocialMedia',
42
+			$facebookURL = TextField::create(
43
+				'FacebookURL',
44
+				_t(__CLASS__ . '.FbField', 'Facebook UID or username')
45
+			)
46
+		);
47
+		$facebookURL->setRightTitle(
48
+			DBField::create_field('HTMLFragment', _t(
49
+				__CLASS__ . '.FbFieldDesc',
50
+				'Facebook link (everything after the "http://facebook.com/", eg http://facebook.com/'
51
+				. '<strong>username</strong> or http://facebook.com/<strong>pages/108510539573</strong>)'
52
+			))
53
+		);
54 54
 
55
-        $fields->addFieldToTab(
56
-            'Root.SocialMedia',
57
-            $twitterUsername = TextField::create(
58
-                'TwitterUsername',
59
-                _t(__CLASS__ . '.TwitterField', 'Twitter username')
60
-            )
61
-        );
62
-        $twitterUsername->setRightTitle(
63
-            DBField::create_field('HTMLFragment', _t(
64
-                __CLASS__ . '.TwitterFieldDesc',
65
-                'Twitter username (eg, http://twitter.com/<strong>username</strong>)'
66
-            ))
67
-        );
68
-    }
55
+		$fields->addFieldToTab(
56
+			'Root.SocialMedia',
57
+			$twitterUsername = TextField::create(
58
+				'TwitterUsername',
59
+				_t(__CLASS__ . '.TwitterField', 'Twitter username')
60
+			)
61
+		);
62
+		$twitterUsername->setRightTitle(
63
+			DBField::create_field('HTMLFragment', _t(
64
+				__CLASS__ . '.TwitterFieldDesc',
65
+				'Twitter username (eg, http://twitter.com/<strong>username</strong>)'
66
+			))
67
+		);
68
+	}
69 69
 }
Please login to merge, or discard this patch.
tests/Extensions/WorkflowDefinitionExtensionTest.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -15,38 +15,38 @@
 block discarded – undo
15 15
 class WorkflowDefinitionExtensionTest extends FunctionalTest
16 16
 {
17 17
 
18
-    /**
19
-     * @var Boolean If set to TRUE, this will force a test database to be generated
20
-     * in {@link setUp()}. Note that this flag is overruled by the presence of a
21
-     * {@link $fixture_file}, which always forces a database build.
22
-     */
23
-    protected $usesDatabase = true;
24
-
25
-    /**
26
-     * Tests the config option that controls the creation of a default workflow definition
27
-     *
28
-     * @return void
29
-     */
30
-    public function testCreateDefaultWorkflowTest()
31
-    {
32
-        if (!class_exists(WorkflowDefinition::class)) {
33
-            $this->markTestSkipped('This test requires the advancedworkflow module to be installed');
34
-        }
35
-
36
-        DB::quiet();
37
-
38
-        // test disabling the default workflow definition
39
-        Config::modify()->set(CwpWorkflowDefinitionExtension::class, 'create_default_workflow', false);
40
-        $workflowExtn = Injector::inst()->create(CwpWorkflowDefinitionExtension::class);
41
-        $workflowExtn->requireDefaultRecords();
42
-        $definition = WorkflowDefinition::get()->first();
43
-        $this->assertNull($definition);
44
-
45
-        // test enabling the default workflow definition
46
-        Config::modify()->set(CwpWorkflowDefinitionExtension::class, 'create_default_workflow', true);
47
-        $workflowExtn = Injector::inst()->create(CwpWorkflowDefinitionExtension::class);
48
-        $workflowExtn->requireDefaultRecords();
49
-        $definition = WorkflowDefinition::get()->first();
50
-        $this->assertNotNull($definition);
51
-    }
18
+	/**
19
+	 * @var Boolean If set to TRUE, this will force a test database to be generated
20
+	 * in {@link setUp()}. Note that this flag is overruled by the presence of a
21
+	 * {@link $fixture_file}, which always forces a database build.
22
+	 */
23
+	protected $usesDatabase = true;
24
+
25
+	/**
26
+	 * Tests the config option that controls the creation of a default workflow definition
27
+	 *
28
+	 * @return void
29
+	 */
30
+	public function testCreateDefaultWorkflowTest()
31
+	{
32
+		if (!class_exists(WorkflowDefinition::class)) {
33
+			$this->markTestSkipped('This test requires the advancedworkflow module to be installed');
34
+		}
35
+
36
+		DB::quiet();
37
+
38
+		// test disabling the default workflow definition
39
+		Config::modify()->set(CwpWorkflowDefinitionExtension::class, 'create_default_workflow', false);
40
+		$workflowExtn = Injector::inst()->create(CwpWorkflowDefinitionExtension::class);
41
+		$workflowExtn->requireDefaultRecords();
42
+		$definition = WorkflowDefinition::get()->first();
43
+		$this->assertNull($definition);
44
+
45
+		// test enabling the default workflow definition
46
+		Config::modify()->set(CwpWorkflowDefinitionExtension::class, 'create_default_workflow', true);
47
+		$workflowExtn = Injector::inst()->create(CwpWorkflowDefinitionExtension::class);
48
+		$workflowExtn->requireDefaultRecords();
49
+		$definition = WorkflowDefinition::get()->first();
50
+		$this->assertNotNull($definition);
51
+	}
52 52
 }
Please login to merge, or discard this patch.
tests/Tasks/PopulateThemeSampleDataTaskTest.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -10,50 +10,50 @@
 block discarded – undo
10 10
 
11 11
 class PopulateThemeSampleDataTaskTest extends SapphireTest
12 12
 {
13
-    protected $usesDatabase = true;
14
-
15
-    /**
16
-     * Ensure that the "contact" user form is only created once
17
-     */
18
-    public function testOnlyCreateContactFormOnce()
19
-    {
20
-        if (!class_exists(UserDefinedForm::class)) {
21
-            $this->markTestSkipped('This test requires the userforms module to be installed');
22
-        }
23
-
24
-        $createdMessage = 'Created "contact" UserDefinedForm';
25
-
26
-        $task = new PopulateThemeSampleDataTask;
27
-
28
-        // Run the task
29
-        $this->assertContains($createdMessage, $this->bufferedTask($task));
30
-
31
-        // Run a second time
32
-        $this->assertNotContains($createdMessage, $this->bufferedTask($task));
33
-
34
-        // Change the page name
35
-        $form = UserDefinedForm::get()->filter('URLSegment', 'contact')->first();
36
-        $form->URLSegment = 'testing';
37
-        $form->write();
38
-
39
-        // Ensure the old version is still detected in draft, so not recreated
40
-        $this->assertNotContains($createdMessage, $this->bufferedTask($task));
41
-
42
-        // Delete the page, then ensure it's recreated again (DataObject::delete will remove staged versions)
43
-        $form->delete();
44
-        $this->assertContains($createdMessage, $this->bufferedTask($task));
45
-    }
46
-
47
-    /**
48
-     * Run a BuildTask while buffering its output, and return the result
49
-     *
50
-     * @param  BuildTask $task
51
-     * @return string
52
-     */
53
-    protected function bufferedTask(BuildTask $task)
54
-    {
55
-        ob_start();
56
-        $task->run(new HTTPRequest('GET', '/'));
57
-        return ob_get_clean();
58
-    }
13
+	protected $usesDatabase = true;
14
+
15
+	/**
16
+	 * Ensure that the "contact" user form is only created once
17
+	 */
18
+	public function testOnlyCreateContactFormOnce()
19
+	{
20
+		if (!class_exists(UserDefinedForm::class)) {
21
+			$this->markTestSkipped('This test requires the userforms module to be installed');
22
+		}
23
+
24
+		$createdMessage = 'Created "contact" UserDefinedForm';
25
+
26
+		$task = new PopulateThemeSampleDataTask;
27
+
28
+		// Run the task
29
+		$this->assertContains($createdMessage, $this->bufferedTask($task));
30
+
31
+		// Run a second time
32
+		$this->assertNotContains($createdMessage, $this->bufferedTask($task));
33
+
34
+		// Change the page name
35
+		$form = UserDefinedForm::get()->filter('URLSegment', 'contact')->first();
36
+		$form->URLSegment = 'testing';
37
+		$form->write();
38
+
39
+		// Ensure the old version is still detected in draft, so not recreated
40
+		$this->assertNotContains($createdMessage, $this->bufferedTask($task));
41
+
42
+		// Delete the page, then ensure it's recreated again (DataObject::delete will remove staged versions)
43
+		$form->delete();
44
+		$this->assertContains($createdMessage, $this->bufferedTask($task));
45
+	}
46
+
47
+	/**
48
+	 * Run a BuildTask while buffering its output, and return the result
49
+	 *
50
+	 * @param  BuildTask $task
51
+	 * @return string
52
+	 */
53
+	protected function bufferedTask(BuildTask $task)
54
+	{
55
+		ob_start();
56
+		$task->run(new HTTPRequest('GET', '/'));
57
+		return ob_get_clean();
58
+	}
59 59
 }
Please login to merge, or discard this patch.
src/Tasks/PopulateThemeSampleDataTask.php 1 patch
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -17,136 +17,136 @@
 block discarded – undo
17 17
  */
18 18
 class PopulateThemeSampleDataTask extends BuildTask
19 19
 {
20
-    protected $title = 'Populate sample data for theme demo';
21
-
22
-    protected $description = 'Populates some sample data for showcasing the functionality of the '
23
-        . 'starter and Wātea themes';
24
-
25
-    /**
26
-     * A series of method calls to create sample data
27
-     *
28
-     * @param HTTPRequest $request
29
-     */
30
-    public function run($request)
31
-    {
32
-        if (!class_exists(UserDefinedForm::class)) {
33
-            return;
34
-        }
35
-        $this->handleContactForm();
36
-    }
37
-
38
-    /**
39
-     * Decide whether to create a contact user defined form, and call it to be be created if so
40
-     *
41
-     * @return $this
42
-     */
43
-    protected function handleContactForm()
44
-    {
45
-        if (!$this->getContactFormExists()) {
46
-            $this->createContactForm();
47
-        }
48
-        return $this;
49
-    }
50
-
51
-    /**
52
-     * Determine whether a "contact us" userform exists yet
53
-     *
54
-     * @return bool
55
-     */
56
-    protected function getContactFormExists()
57
-    {
58
-        $exists = false;
59
-        foreach (UserDefinedForm::get()->column('ID') as $formId) {
60
-            $count = Versioned::get_all_versions(UserDefinedForm::class, $formId)
61
-                ->filter('URLSegment', 'contact')
62
-                ->count();
63
-
64
-            if ($count >= 1) {
65
-                $exists = true;
66
-                break;
67
-            }
68
-        }
69
-        return $exists;
70
-    }
71
-
72
-    /**
73
-     * Create a "contact us" userform. Please note that this form does not have any recipients by default, so
74
-     * no emails will be sent. To add recipients - edit the page in the CMS and add a recipient via the "Recipients"
75
-     * tab.
76
-     *
77
-     * @return $this
78
-     */
79
-    protected function createContactForm()
80
-    {
81
-        $form = UserDefinedForm::create(array(
82
-            'Title' => 'Contact',
83
-            'URLSegment' => 'contact',
84
-            'Content' => '<p>$UserDefinedForm</p>',
85
-            'SubmitButtonText' => 'Submit',
86
-            'ClearButtonText' => 'Clear',
87
-            'OnCompleteMessage' => "<p>Thanks, we've received your submission and will be in touch shortly.</p>",
88
-            'EnableLiveValidation' => true
89
-        ));
90
-
91
-        $form->write();
92
-
93
-        // Add form fields
94
-        $fields = array(
95
-            EditableFormStep::create([
96
-                'Title' => _t(
97
-                    'SilverStripe\\UserForms\\Model\\EditableFormField\\EditableFormStep.TITLE_FIRST',
98
-                    'First Page'
99
-                )
100
-            ]),
101
-            EditableTextField::create([
102
-                'Title' => 'Name',
103
-                'Required' => true,
104
-                'RightTitle' => 'Please enter your first and last name'
105
-            ]),
106
-            EditableEmailField::create([
107
-                'Title' => Email::class,
108
-                'Required' => true,
109
-                'Placeholder' => '[email protected]'
110
-            ]),
111
-            EditableTextField::create([
112
-                'Title' => 'Subject'
113
-            ]),
114
-            EditableTextField::create([
115
-                'Title' => 'Message',
116
-                'Required' => true,
117
-                'Rows' => 5
118
-            ])
119
-        );
120
-
121
-        foreach ($fields as $field) {
122
-            $field->write();
123
-            $form->Fields()->add($field);
124
-            $field->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
125
-        }
126
-
127
-        $form->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
128
-        $form->flushCache();
129
-
130
-        $this->output(' + Created "contact" UserDefinedForm page');
131
-
132
-        return $this;
133
-    }
134
-
135
-    /**
136
-     * Output a message either to the console or browser
137
-     *
138
-     * @param  string $message
139
-     * @return $this
140
-     */
141
-    protected function output($message)
142
-    {
143
-        if (Director::is_cli()) {
144
-            $message .= PHP_EOL;
145
-        } else {
146
-            $message = sprintf('<p>%s</p>', $message);
147
-        }
148
-        echo $message;
149
-
150
-        return $this;
151
-    }
20
+	protected $title = 'Populate sample data for theme demo';
21
+
22
+	protected $description = 'Populates some sample data for showcasing the functionality of the '
23
+		. 'starter and Wātea themes';
24
+
25
+	/**
26
+	 * A series of method calls to create sample data
27
+	 *
28
+	 * @param HTTPRequest $request
29
+	 */
30
+	public function run($request)
31
+	{
32
+		if (!class_exists(UserDefinedForm::class)) {
33
+			return;
34
+		}
35
+		$this->handleContactForm();
36
+	}
37
+
38
+	/**
39
+	 * Decide whether to create a contact user defined form, and call it to be be created if so
40
+	 *
41
+	 * @return $this
42
+	 */
43
+	protected function handleContactForm()
44
+	{
45
+		if (!$this->getContactFormExists()) {
46
+			$this->createContactForm();
47
+		}
48
+		return $this;
49
+	}
50
+
51
+	/**
52
+	 * Determine whether a "contact us" userform exists yet
53
+	 *
54
+	 * @return bool
55
+	 */
56
+	protected function getContactFormExists()
57
+	{
58
+		$exists = false;
59
+		foreach (UserDefinedForm::get()->column('ID') as $formId) {
60
+			$count = Versioned::get_all_versions(UserDefinedForm::class, $formId)
61
+				->filter('URLSegment', 'contact')
62
+				->count();
63
+
64
+			if ($count >= 1) {
65
+				$exists = true;
66
+				break;
67
+			}
68
+		}
69
+		return $exists;
70
+	}
71
+
72
+	/**
73
+	 * Create a "contact us" userform. Please note that this form does not have any recipients by default, so
74
+	 * no emails will be sent. To add recipients - edit the page in the CMS and add a recipient via the "Recipients"
75
+	 * tab.
76
+	 *
77
+	 * @return $this
78
+	 */
79
+	protected function createContactForm()
80
+	{
81
+		$form = UserDefinedForm::create(array(
82
+			'Title' => 'Contact',
83
+			'URLSegment' => 'contact',
84
+			'Content' => '<p>$UserDefinedForm</p>',
85
+			'SubmitButtonText' => 'Submit',
86
+			'ClearButtonText' => 'Clear',
87
+			'OnCompleteMessage' => "<p>Thanks, we've received your submission and will be in touch shortly.</p>",
88
+			'EnableLiveValidation' => true
89
+		));
90
+
91
+		$form->write();
92
+
93
+		// Add form fields
94
+		$fields = array(
95
+			EditableFormStep::create([
96
+				'Title' => _t(
97
+					'SilverStripe\\UserForms\\Model\\EditableFormField\\EditableFormStep.TITLE_FIRST',
98
+					'First Page'
99
+				)
100
+			]),
101
+			EditableTextField::create([
102
+				'Title' => 'Name',
103
+				'Required' => true,
104
+				'RightTitle' => 'Please enter your first and last name'
105
+			]),
106
+			EditableEmailField::create([
107
+				'Title' => Email::class,
108
+				'Required' => true,
109
+				'Placeholder' => '[email protected]'
110
+			]),
111
+			EditableTextField::create([
112
+				'Title' => 'Subject'
113
+			]),
114
+			EditableTextField::create([
115
+				'Title' => 'Message',
116
+				'Required' => true,
117
+				'Rows' => 5
118
+			])
119
+		);
120
+
121
+		foreach ($fields as $field) {
122
+			$field->write();
123
+			$form->Fields()->add($field);
124
+			$field->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
125
+		}
126
+
127
+		$form->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
128
+		$form->flushCache();
129
+
130
+		$this->output(' + Created "contact" UserDefinedForm page');
131
+
132
+		return $this;
133
+	}
134
+
135
+	/**
136
+	 * Output a message either to the console or browser
137
+	 *
138
+	 * @param  string $message
139
+	 * @return $this
140
+	 */
141
+	protected function output($message)
142
+	{
143
+		if (Director::is_cli()) {
144
+			$message .= PHP_EOL;
145
+		} else {
146
+			$message = sprintf('<p>%s</p>', $message);
147
+		}
148
+		echo $message;
149
+
150
+		return $this;
151
+	}
152 152
 }
Please login to merge, or discard this patch.
src/PageTypes/SitemapPageController.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -7,45 +7,45 @@
 block discarded – undo
7 7
 
8 8
 class SitemapPageController extends PageController
9 9
 {
10
-    private static $allowed_actions = [
11
-        'showpage',
12
-    ];
13
-
14
-    private static $url_handlers = [
15
-        'page/$ID' => 'showpage',
16
-    ];
17
-
18
-    public function showpage($request)
19
-    {
20
-        $id = (int) $request->param('ID');
21
-        if (!$id) {
22
-            return false;
23
-        }
24
-        $page = SiteTree::get()->byId($id);
25
-
26
-        // does the page exist?
27
-        if (!($page && $page->exists())) {
28
-            return $this->httpError(404);
29
-        }
30
-
31
-        // can the page be viewed?
32
-        if (!$page->canView()) {
33
-            return $this->httpError(403);
34
-        }
35
-
36
-        $viewer = $this->customise([
37
-            'IsAjax' => $request->isAjax(),
38
-            'SelectedPage' => $page,
39
-            'Children' => $page->Children(),
40
-        ]);
41
-
42
-        if ($request->isAjax()) {
43
-            return $viewer->renderWith([
44
-                'type' => 'Includes',
45
-                'SitemapNodeChildren'
46
-            ]);
47
-        }
48
-
49
-        return $viewer;
50
-    }
10
+	private static $allowed_actions = [
11
+		'showpage',
12
+	];
13
+
14
+	private static $url_handlers = [
15
+		'page/$ID' => 'showpage',
16
+	];
17
+
18
+	public function showpage($request)
19
+	{
20
+		$id = (int) $request->param('ID');
21
+		if (!$id) {
22
+			return false;
23
+		}
24
+		$page = SiteTree::get()->byId($id);
25
+
26
+		// does the page exist?
27
+		if (!($page && $page->exists())) {
28
+			return $this->httpError(404);
29
+		}
30
+
31
+		// can the page be viewed?
32
+		if (!$page->canView()) {
33
+			return $this->httpError(403);
34
+		}
35
+
36
+		$viewer = $this->customise([
37
+			'IsAjax' => $request->isAjax(),
38
+			'SelectedPage' => $page,
39
+			'Children' => $page->Children(),
40
+		]);
41
+
42
+		if ($request->isAjax()) {
43
+			return $viewer->renderWith([
44
+				'type' => 'Includes',
45
+				'SitemapNodeChildren'
46
+			]);
47
+		}
48
+
49
+		return $viewer;
50
+	}
51 51
 }
Please login to merge, or discard this patch.
src/PageTypes/BasePage.php 1 patch
Indentation   +143 added lines, -143 removed lines patch added patch discarded remove patch
@@ -27,147 +27,147 @@
 block discarded – undo
27 27
 
28 28
 class BasePage extends SiteTree
29 29
 {
30
-    private static $icon = 'cwp/cwp:images/icons/sitetree_images/page.png';
31
-
32
-    /**
33
-     * Hide this page type from the CMS. hide_ancestor is slightly misnamed, should really be just "hide"
34
-     *
35
-     * {@inheritDoc}
36
-     */
37
-    private static $hide_ancestor = BasePage::class;
38
-
39
-    private static $api_access = [
40
-        'view' => [
41
-            'Locale', 'URLSegment', 'Title', 'MenuTitle', 'Content', 'MetaDescription',
42
-            'ExtraMenu', 'Sort', 'Version', 'ParentID', 'ID'
43
-        ],
44
-        'edit' => [
45
-            'Locale', 'URLSegment', 'Title', 'MenuTitle', 'Content', 'MetaDescription',
46
-            'ExtraMenu', 'Sort', 'Version', 'ParentID', 'ID'
47
-        ],
48
-    ];
49
-
50
-    private static $table_name = 'BasePage';
51
-
52
-    /**
53
-     * @config
54
-     * @var string
55
-     */
56
-    private static $related_pages_title = 'Related pages';
57
-
58
-    private static $many_many = [
59
-        'Terms' => TaxonomyTerm::class,
60
-        'RelatedPages' => BasePage::class,
61
-    ];
62
-
63
-    /**
64
-     * @var array
65
-     * @config
66
-     */
67
-    private static $many_many_extraFields = [
68
-        'RelatedPages' => [
69
-            'SortOrder' => DBInt::class,
70
-        ],
71
-    ];
72
-
73
-    private static $plural_name = 'Base Pages';
74
-
75
-    /**
76
-     * Get the footer holder.
77
-     */
78
-    public function getFooter()
79
-    {
80
-        return FooterHolder::get_one(FooterHolder::class);
81
-    }
82
-
83
-    public function RelatedPages()
84
-    {
85
-        return $this->getManyManyComponents('RelatedPages')->sort('SortOrder');
86
-    }
87
-
88
-    public function RelatedPagesTitle()
89
-    {
90
-        return $this->config()->get('related_pages_title');
91
-    }
92
-
93
-    public function getCMSFields()
94
-    {
95
-        $this->beforeUpdateCMSFields(function (FieldList $fields) {
96
-            // Related Pages
97
-            $components = GridFieldConfig_RelationEditor::create();
98
-            $components->removeComponentsByType(GridFieldAddNewButton::class);
99
-            $components->removeComponentsByType(GridFieldEditButton::class);
100
-            $components->removeComponentsByType(GridFieldFilterHeader::class);
101
-            $components->addComponent(new GridFieldOrderableRows('SortOrder'));
102
-
103
-            /** @var GridFieldDataColumns $dataColumns */
104
-            $dataColumns = $components->getComponentByType(GridFieldDataColumns::class);
105
-            $dataColumns->setDisplayFields([
106
-                'Title' => _t(__CLASS__ . '.ColumnTitle', 'Title'),
107
-                'ClassName' => _t(__CLASS__ . '.ColumnPageType', 'Page Type')
108
-            ]);
109
-
110
-            $fields->findOrMakeTab(
111
-                'Root.RelatedPages',
112
-                _t(__CLASS__ . '.RelatedPages', 'Related pages')
113
-            );
114
-            $fields->addFieldToTab(
115
-                'Root.RelatedPages',
116
-                GridField::create(
117
-                    'RelatedPages',
118
-                    _t(__CLASS__ . '.RelatedPages', 'Related pages'),
119
-                    $this->RelatedPages(),
120
-                    $components
121
-                )
122
-            );
123
-
124
-            // Taxonomies - Unless they have their own 'Tags' field (such as in Blog, etc)
125
-            $hasMany = $this->hasMany();
126
-            $manyMany = $this->manyMany();
127
-            if (!isset($hasMany['Tags']) && !isset($manyMany['Tags'])) {
128
-                $components = GridFieldConfig_RelationEditor::create();
129
-                $components->removeComponentsByType(GridFieldAddNewButton::class);
130
-                $components->removeComponentsByType(GridFieldEditButton::class);
131
-
132
-                /** @var GridFieldAddExistingAutocompleter $autoCompleter */
133
-                $autoCompleter = $components->getComponentByType(GridFieldAddExistingAutocompleter::class);
134
-                $autoCompleter->setResultsFormat('$Name ($TaxonomyName)');
135
-
136
-                /** @var GridFieldDataColumns $dataColumns */
137
-                $dataColumns = $components->getComponentByType(GridFieldDataColumns::class);
138
-                $dataColumns->setDisplayFields([
139
-                    'Name' => _t(__CLASS__ . '.Term', 'Term'),
140
-                    'TaxonomyName' => _t(__CLASS__ . '.Taxonomy', 'Taxonomy')
141
-                ]);
142
-
143
-                $fields->findOrMakeTab('Root.Tags', _t(__CLASS__ . '.TagsTabTitle', 'Tags'));
144
-                $fields->addFieldToTab(
145
-                    'Root.Tags',
146
-                    TreeMultiselectField::create(
147
-                        'Terms',
148
-                        _t(__CLASS__ . '.Terms', 'Terms'),
149
-                        TaxonomyTerm::class
150
-                    )->setDescription(_t(__CLASS__ . '.TermsDescription', 'Click to search for additional terms'))
151
-                );
152
-            }
153
-        });
154
-        return parent::getCMSFields();
155
-    }
156
-
157
-    /**
158
-     * Returns the native language name for the selected locale/language, empty string if Fluent is not available
159
-     *
160
-     * @return string
161
-     */
162
-    public function getSelectedLanguage()
163
-    {
164
-        if (!class_exists(Locale::class) || !$this->hasMethod('Locales')) {
165
-            return '';
166
-        }
167
-
168
-        /** @var ArrayData $information */
169
-        $information = $this->LocaleInformation(FluentState::singleton()->getLocale());
170
-
171
-        return $information->LanguageNative;
172
-    }
30
+	private static $icon = 'cwp/cwp:images/icons/sitetree_images/page.png';
31
+
32
+	/**
33
+	 * Hide this page type from the CMS. hide_ancestor is slightly misnamed, should really be just "hide"
34
+	 *
35
+	 * {@inheritDoc}
36
+	 */
37
+	private static $hide_ancestor = BasePage::class;
38
+
39
+	private static $api_access = [
40
+		'view' => [
41
+			'Locale', 'URLSegment', 'Title', 'MenuTitle', 'Content', 'MetaDescription',
42
+			'ExtraMenu', 'Sort', 'Version', 'ParentID', 'ID'
43
+		],
44
+		'edit' => [
45
+			'Locale', 'URLSegment', 'Title', 'MenuTitle', 'Content', 'MetaDescription',
46
+			'ExtraMenu', 'Sort', 'Version', 'ParentID', 'ID'
47
+		],
48
+	];
49
+
50
+	private static $table_name = 'BasePage';
51
+
52
+	/**
53
+	 * @config
54
+	 * @var string
55
+	 */
56
+	private static $related_pages_title = 'Related pages';
57
+
58
+	private static $many_many = [
59
+		'Terms' => TaxonomyTerm::class,
60
+		'RelatedPages' => BasePage::class,
61
+	];
62
+
63
+	/**
64
+	 * @var array
65
+	 * @config
66
+	 */
67
+	private static $many_many_extraFields = [
68
+		'RelatedPages' => [
69
+			'SortOrder' => DBInt::class,
70
+		],
71
+	];
72
+
73
+	private static $plural_name = 'Base Pages';
74
+
75
+	/**
76
+	 * Get the footer holder.
77
+	 */
78
+	public function getFooter()
79
+	{
80
+		return FooterHolder::get_one(FooterHolder::class);
81
+	}
82
+
83
+	public function RelatedPages()
84
+	{
85
+		return $this->getManyManyComponents('RelatedPages')->sort('SortOrder');
86
+	}
87
+
88
+	public function RelatedPagesTitle()
89
+	{
90
+		return $this->config()->get('related_pages_title');
91
+	}
92
+
93
+	public function getCMSFields()
94
+	{
95
+		$this->beforeUpdateCMSFields(function (FieldList $fields) {
96
+			// Related Pages
97
+			$components = GridFieldConfig_RelationEditor::create();
98
+			$components->removeComponentsByType(GridFieldAddNewButton::class);
99
+			$components->removeComponentsByType(GridFieldEditButton::class);
100
+			$components->removeComponentsByType(GridFieldFilterHeader::class);
101
+			$components->addComponent(new GridFieldOrderableRows('SortOrder'));
102
+
103
+			/** @var GridFieldDataColumns $dataColumns */
104
+			$dataColumns = $components->getComponentByType(GridFieldDataColumns::class);
105
+			$dataColumns->setDisplayFields([
106
+				'Title' => _t(__CLASS__ . '.ColumnTitle', 'Title'),
107
+				'ClassName' => _t(__CLASS__ . '.ColumnPageType', 'Page Type')
108
+			]);
109
+
110
+			$fields->findOrMakeTab(
111
+				'Root.RelatedPages',
112
+				_t(__CLASS__ . '.RelatedPages', 'Related pages')
113
+			);
114
+			$fields->addFieldToTab(
115
+				'Root.RelatedPages',
116
+				GridField::create(
117
+					'RelatedPages',
118
+					_t(__CLASS__ . '.RelatedPages', 'Related pages'),
119
+					$this->RelatedPages(),
120
+					$components
121
+				)
122
+			);
123
+
124
+			// Taxonomies - Unless they have their own 'Tags' field (such as in Blog, etc)
125
+			$hasMany = $this->hasMany();
126
+			$manyMany = $this->manyMany();
127
+			if (!isset($hasMany['Tags']) && !isset($manyMany['Tags'])) {
128
+				$components = GridFieldConfig_RelationEditor::create();
129
+				$components->removeComponentsByType(GridFieldAddNewButton::class);
130
+				$components->removeComponentsByType(GridFieldEditButton::class);
131
+
132
+				/** @var GridFieldAddExistingAutocompleter $autoCompleter */
133
+				$autoCompleter = $components->getComponentByType(GridFieldAddExistingAutocompleter::class);
134
+				$autoCompleter->setResultsFormat('$Name ($TaxonomyName)');
135
+
136
+				/** @var GridFieldDataColumns $dataColumns */
137
+				$dataColumns = $components->getComponentByType(GridFieldDataColumns::class);
138
+				$dataColumns->setDisplayFields([
139
+					'Name' => _t(__CLASS__ . '.Term', 'Term'),
140
+					'TaxonomyName' => _t(__CLASS__ . '.Taxonomy', 'Taxonomy')
141
+				]);
142
+
143
+				$fields->findOrMakeTab('Root.Tags', _t(__CLASS__ . '.TagsTabTitle', 'Tags'));
144
+				$fields->addFieldToTab(
145
+					'Root.Tags',
146
+					TreeMultiselectField::create(
147
+						'Terms',
148
+						_t(__CLASS__ . '.Terms', 'Terms'),
149
+						TaxonomyTerm::class
150
+					)->setDescription(_t(__CLASS__ . '.TermsDescription', 'Click to search for additional terms'))
151
+				);
152
+			}
153
+		});
154
+		return parent::getCMSFields();
155
+	}
156
+
157
+	/**
158
+	 * Returns the native language name for the selected locale/language, empty string if Fluent is not available
159
+	 *
160
+	 * @return string
161
+	 */
162
+	public function getSelectedLanguage()
163
+	{
164
+		if (!class_exists(Locale::class) || !$this->hasMethod('Locales')) {
165
+			return '';
166
+		}
167
+
168
+		/** @var ArrayData $information */
169
+		$information = $this->LocaleInformation(FluentState::singleton()->getLocale());
170
+
171
+		return $information->LanguageNative;
172
+	}
173 173
 }
Please login to merge, or discard this patch.
src/PageTypes/BaseHomePage.php 1 patch
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -26,137 +26,137 @@
 block discarded – undo
26 26
  */
27 27
 class BaseHomePage extends Page
28 28
 {
29
-    private static $icon = 'cwp/cwp:images/icons/sitetree_images/home.png';
30
-
31
-    private static $hide_ancestor = BaseHomePage::class;
32
-
33
-    private static $singular_name = 'Home Page';
34
-
35
-    private static $plural_name = 'Home Pages';
36
-
37
-    private static $table_name = 'BaseHomePage';
38
-
39
-    private static $db = [
40
-        'FeatureOneTitle' => 'Varchar(255)',
41
-        'FeatureOneCategory' => "Enum('bell,comments,film,flag,globe,group,list,phone,rss,time,user','comments')",
42
-        'FeatureOneContent' => 'HTMLText',
43
-        'FeatureOneButtonText' => 'Varchar(255)',
44
-        'FeatureTwoTitle' => 'Varchar(255)',
45
-        'FeatureTwoCategory' => "Enum('bell,comments,film,flag,globe,group,list,phone,rss,time,user','comments')",
46
-        'FeatureTwoContent' => 'HTMLText',
47
-        'FeatureTwoButtonText' => 'Varchar(255)'
48
-    ];
49
-
50
-    private static $has_one = [
51
-        'LearnMorePage' => SiteTree::class,
52
-        'FeatureOneLink' => SiteTree::class,
53
-        'FeatureTwoLink' => SiteTree::class,
54
-    ];
55
-
56
-    private static $has_many = [
57
-        'Quicklinks' => Quicklink::class . '.Parent',
58
-    ];
59
-
60
-    public function Quicklinks()
61
-    {
62
-        return $this->getComponents('Quicklinks')->sort('SortOrder');
63
-    }
64
-
65
-    public function getCMSFields()
66
-    {
67
-        $this->beforeUpdateCMSFields(function (FieldList $fields) {
68
-            // Main Content tab
69
-            $fields->addFieldToTab(
70
-                'Root.Main',
71
-                TreeDropdownField::create(
72
-                    'LearnMorePageID',
73
-                    _t(__CLASS__ . '.LearnMoreLink', 'Page to link the "Learn More" button to:'),
74
-                    SiteTree::class
75
-                ),
76
-                'Metadata'
77
-            );
78
-
79
-            $gridField = GridField::create(
80
-                'Quicklinks',
81
-                'Quicklinks',
82
-                $this->Quicklinks(),
83
-                GridFieldConfig_RelationEditor::create()
84
-            );
85
-            $gridConfig = $gridField->getConfig();
86
-            $gridConfig->getComponentByType(GridFieldAddNewButton::class)->setButtonName(
87
-                _t(__CLASS__ . '.AddNewButton', 'Add new')
88
-            );
89
-
90
-            $injector = Injector::inst();
91
-
92
-            $gridConfig->removeComponentsByType(GridFieldAddExistingAutocompleter::class);
93
-            $gridConfig->removeComponentsByType(GridFieldDeleteAction::class);
94
-            $gridConfig->addComponent($injector->create(GridFieldDeleteAction::class));
95
-            $gridConfig->addComponent($injector->create(GridFieldOrderableRows::class, 'SortOrder'));
96
-            $gridField->setModelClass(Quicklink::class);
97
-
98
-            $fields->addFieldToTab('Root.Quicklinks', $gridField);
99
-
100
-            $fields->removeByName('Import');
101
-
102
-            $fields->addFieldToTab(
103
-                'Root.Features',
104
-                ToggleCompositeField::create(
105
-                    'FeatureOne',
106
-                    _t(__CLASS__ . '.FeatureOne', 'Feature One'),
107
-                    array(
108
-                        TextField::create('FeatureOneTitle', _t(__CLASS__ . '.Title', 'Title')),
109
-                        $dropdownField = DropdownField::create(
110
-                            'FeatureOneCategory',
111
-                            _t(__CLASS__ . '.FeatureCategoryDropdown', 'Category icon'),
112
-                            singleton(BaseHomePage::class)->dbObject('FeatureOneCategory')->enumValues()
113
-                        ),
114
-                        HTMLEditorField::create(
115
-                            'FeatureOneContent',
116
-                            _t(__CLASS__ . '.FeatureContentFieldLabel', 'Content')
117
-                        ),
118
-                        TextField::create(
119
-                            'FeatureOneButtonText',
120
-                            _t(__CLASS__ . '.FeatureButtonText', 'Button text')
121
-                        ),
122
-                        TreeDropdownField::create(
123
-                            'FeatureOneLinkID',
124
-                            _t(__CLASS__ . '.FeatureLink', 'Page to link to'),
125
-                            SiteTree::class
126
-                        )->setDescription(_t(__CLASS__ . '.ButtonTextRequired', 'Button text must be filled in'))
127
-                    )
128
-                )->setHeadingLevel(3)
129
-            );
130
-            $dropdownField->setEmptyString('none');
131
-
132
-            $fields->addFieldToTab('Root.Features', ToggleCompositeField::create(
133
-                'FeatureTwo',
134
-                _t(__CLASS__ . '.FeatureTwo', 'Feature Two'),
135
-                array(
136
-                    TextField::create('FeatureTwoTitle', _t(__CLASS__ . '.Title', 'Title')),
137
-                    $dropdownField = DropdownField::create(
138
-                        'FeatureTwoCategory',
139
-                        _t(__CLASS__ . '.FeatureCategoryDropdown', 'Category icon'),
140
-                        singleton(BaseHomePage::class)->dbObject('FeatureTwoCategory')->enumValues()
141
-                    ),
142
-                    HTMLEditorField::create(
143
-                        'FeatureTwoContent',
144
-                        _t(__CLASS__ . '.FeatureContentFieldLabel', 'Content')
145
-                    ),
146
-                    TextField::create(
147
-                        'FeatureTwoButtonText',
148
-                        _t(__CLASS__ . '.FeatureButtonText', 'Button text')
149
-                    ),
150
-                    TreeDropdownField::create(
151
-                        'FeatureTwoLinkID',
152
-                        _t(__CLASS__ . '.FeatureLink', 'Page to link to'),
153
-                        SiteTree::class
154
-                    )->setDescription(_t(__CLASS__ . '.ButtonTextRequired', 'Button text must be filled in'))
155
-                )
156
-            )->setHeadingLevel(3));
157
-            $dropdownField->setEmptyString('none');
158
-        });
159
-
160
-        return parent::getCMSFields();
161
-    }
29
+	private static $icon = 'cwp/cwp:images/icons/sitetree_images/home.png';
30
+
31
+	private static $hide_ancestor = BaseHomePage::class;
32
+
33
+	private static $singular_name = 'Home Page';
34
+
35
+	private static $plural_name = 'Home Pages';
36
+
37
+	private static $table_name = 'BaseHomePage';
38
+
39
+	private static $db = [
40
+		'FeatureOneTitle' => 'Varchar(255)',
41
+		'FeatureOneCategory' => "Enum('bell,comments,film,flag,globe,group,list,phone,rss,time,user','comments')",
42
+		'FeatureOneContent' => 'HTMLText',
43
+		'FeatureOneButtonText' => 'Varchar(255)',
44
+		'FeatureTwoTitle' => 'Varchar(255)',
45
+		'FeatureTwoCategory' => "Enum('bell,comments,film,flag,globe,group,list,phone,rss,time,user','comments')",
46
+		'FeatureTwoContent' => 'HTMLText',
47
+		'FeatureTwoButtonText' => 'Varchar(255)'
48
+	];
49
+
50
+	private static $has_one = [
51
+		'LearnMorePage' => SiteTree::class,
52
+		'FeatureOneLink' => SiteTree::class,
53
+		'FeatureTwoLink' => SiteTree::class,
54
+	];
55
+
56
+	private static $has_many = [
57
+		'Quicklinks' => Quicklink::class . '.Parent',
58
+	];
59
+
60
+	public function Quicklinks()
61
+	{
62
+		return $this->getComponents('Quicklinks')->sort('SortOrder');
63
+	}
64
+
65
+	public function getCMSFields()
66
+	{
67
+		$this->beforeUpdateCMSFields(function (FieldList $fields) {
68
+			// Main Content tab
69
+			$fields->addFieldToTab(
70
+				'Root.Main',
71
+				TreeDropdownField::create(
72
+					'LearnMorePageID',
73
+					_t(__CLASS__ . '.LearnMoreLink', 'Page to link the "Learn More" button to:'),
74
+					SiteTree::class
75
+				),
76
+				'Metadata'
77
+			);
78
+
79
+			$gridField = GridField::create(
80
+				'Quicklinks',
81
+				'Quicklinks',
82
+				$this->Quicklinks(),
83
+				GridFieldConfig_RelationEditor::create()
84
+			);
85
+			$gridConfig = $gridField->getConfig();
86
+			$gridConfig->getComponentByType(GridFieldAddNewButton::class)->setButtonName(
87
+				_t(__CLASS__ . '.AddNewButton', 'Add new')
88
+			);
89
+
90
+			$injector = Injector::inst();
91
+
92
+			$gridConfig->removeComponentsByType(GridFieldAddExistingAutocompleter::class);
93
+			$gridConfig->removeComponentsByType(GridFieldDeleteAction::class);
94
+			$gridConfig->addComponent($injector->create(GridFieldDeleteAction::class));
95
+			$gridConfig->addComponent($injector->create(GridFieldOrderableRows::class, 'SortOrder'));
96
+			$gridField->setModelClass(Quicklink::class);
97
+
98
+			$fields->addFieldToTab('Root.Quicklinks', $gridField);
99
+
100
+			$fields->removeByName('Import');
101
+
102
+			$fields->addFieldToTab(
103
+				'Root.Features',
104
+				ToggleCompositeField::create(
105
+					'FeatureOne',
106
+					_t(__CLASS__ . '.FeatureOne', 'Feature One'),
107
+					array(
108
+						TextField::create('FeatureOneTitle', _t(__CLASS__ . '.Title', 'Title')),
109
+						$dropdownField = DropdownField::create(
110
+							'FeatureOneCategory',
111
+							_t(__CLASS__ . '.FeatureCategoryDropdown', 'Category icon'),
112
+							singleton(BaseHomePage::class)->dbObject('FeatureOneCategory')->enumValues()
113
+						),
114
+						HTMLEditorField::create(
115
+							'FeatureOneContent',
116
+							_t(__CLASS__ . '.FeatureContentFieldLabel', 'Content')
117
+						),
118
+						TextField::create(
119
+							'FeatureOneButtonText',
120
+							_t(__CLASS__ . '.FeatureButtonText', 'Button text')
121
+						),
122
+						TreeDropdownField::create(
123
+							'FeatureOneLinkID',
124
+							_t(__CLASS__ . '.FeatureLink', 'Page to link to'),
125
+							SiteTree::class
126
+						)->setDescription(_t(__CLASS__ . '.ButtonTextRequired', 'Button text must be filled in'))
127
+					)
128
+				)->setHeadingLevel(3)
129
+			);
130
+			$dropdownField->setEmptyString('none');
131
+
132
+			$fields->addFieldToTab('Root.Features', ToggleCompositeField::create(
133
+				'FeatureTwo',
134
+				_t(__CLASS__ . '.FeatureTwo', 'Feature Two'),
135
+				array(
136
+					TextField::create('FeatureTwoTitle', _t(__CLASS__ . '.Title', 'Title')),
137
+					$dropdownField = DropdownField::create(
138
+						'FeatureTwoCategory',
139
+						_t(__CLASS__ . '.FeatureCategoryDropdown', 'Category icon'),
140
+						singleton(BaseHomePage::class)->dbObject('FeatureTwoCategory')->enumValues()
141
+					),
142
+					HTMLEditorField::create(
143
+						'FeatureTwoContent',
144
+						_t(__CLASS__ . '.FeatureContentFieldLabel', 'Content')
145
+					),
146
+					TextField::create(
147
+						'FeatureTwoButtonText',
148
+						_t(__CLASS__ . '.FeatureButtonText', 'Button text')
149
+					),
150
+					TreeDropdownField::create(
151
+						'FeatureTwoLinkID',
152
+						_t(__CLASS__ . '.FeatureLink', 'Page to link to'),
153
+						SiteTree::class
154
+					)->setDescription(_t(__CLASS__ . '.ButtonTextRequired', 'Button text must be filled in'))
155
+				)
156
+			)->setHeadingLevel(3));
157
+			$dropdownField->setEmptyString('none');
158
+		});
159
+
160
+		return parent::getCMSFields();
161
+	}
162 162
 }
Please login to merge, or discard this patch.