@@ -9,27 +9,27 @@ |
||
| 9 | 9 | |
| 10 | 10 | class SitemapPageTest extends FunctionalTest |
| 11 | 11 | { |
| 12 | - protected static $fixture_file = 'SitemapPageTest.yml'; |
|
| 12 | + protected static $fixture_file = 'SitemapPageTest.yml'; |
|
| 13 | 13 | |
| 14 | - protected static $use_draft_site = true; |
|
| 14 | + protected static $use_draft_site = true; |
|
| 15 | 15 | |
| 16 | - protected function setUp() |
|
| 17 | - { |
|
| 18 | - parent::setUp(); |
|
| 16 | + protected function setUp() |
|
| 17 | + { |
|
| 18 | + parent::setUp(); |
|
| 19 | 19 | |
| 20 | - Config::modify()->set(SSViewer::class, 'themes', ['starter', '$default']); |
|
| 21 | - Config::modify()->set(SSViewer::class, 'theme', 'starter'); |
|
| 22 | - } |
|
| 20 | + Config::modify()->set(SSViewer::class, 'themes', ['starter', '$default']); |
|
| 21 | + Config::modify()->set(SSViewer::class, 'theme', 'starter'); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Note: this test depends on the "starter" theme being installed and configured as default |
|
| 26 | - */ |
|
| 27 | - public function testSitemapShowsNavigationTitleNotNormalTitle() |
|
| 28 | - { |
|
| 29 | - $response = $this->get('sitemap'); |
|
| 30 | - $parser = new CSSContentParser($response->getBody()); |
|
| 31 | - $elements = $parser->getBySelector('.sitemap li.first .sitemap-link'); |
|
| 32 | - $this->assertNotEmpty($elements); |
|
| 33 | - $this->assertEquals('Top page nav 1', (string) $elements[0]); |
|
| 34 | - } |
|
| 24 | + /** |
|
| 25 | + * Note: this test depends on the "starter" theme being installed and configured as default |
|
| 26 | + */ |
|
| 27 | + public function testSitemapShowsNavigationTitleNotNormalTitle() |
|
| 28 | + { |
|
| 29 | + $response = $this->get('sitemap'); |
|
| 30 | + $parser = new CSSContentParser($response->getBody()); |
|
| 31 | + $elements = $parser->getBySelector('.sitemap li.first .sitemap-link'); |
|
| 32 | + $this->assertNotEmpty($elements); |
|
| 33 | + $this->assertEquals('Top page nav 1', (string) $elements[0]); |
|
| 34 | + } |
|
| 35 | 35 | } |
@@ -7,15 +7,15 @@ |
||
| 7 | 7 | |
| 8 | 8 | class BasePageController extends ContentController |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * Provide current year. |
|
| 12 | - */ |
|
| 13 | - public function CurrentDatetime() |
|
| 14 | - { |
|
| 15 | - return DBDatetime::now(); |
|
| 16 | - } |
|
| 10 | + /** |
|
| 11 | + * Provide current year. |
|
| 12 | + */ |
|
| 13 | + public function CurrentDatetime() |
|
| 14 | + { |
|
| 15 | + return DBDatetime::now(); |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - public function getRSSLink() |
|
| 19 | - { |
|
| 20 | - } |
|
| 18 | + public function getRSSLink() |
|
| 19 | + { |
|
| 20 | + } |
|
| 21 | 21 | } |
@@ -20,108 +20,108 @@ |
||
| 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 | } |
@@ -15,38 +15,38 @@ |
||
| 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 | } |
@@ -10,50 +10,50 @@ |
||
| 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 | } |
@@ -17,136 +17,136 @@ |
||
| 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 | } |
@@ -7,45 +7,45 @@ |
||
| 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 | } |
@@ -10,17 +10,17 @@ |
||
| 10 | 10 | class TaxonomyTermExtension extends DataExtension |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - private static $api_access = true; |
|
| 13 | + private static $api_access = true; |
|
| 14 | 14 | |
| 15 | - private static $belongs_many_many = array( |
|
| 16 | - 'Pages' => BasePage::class |
|
| 17 | - ); |
|
| 15 | + private static $belongs_many_many = array( |
|
| 16 | + 'Pages' => BasePage::class |
|
| 17 | + ); |
|
| 18 | 18 | |
| 19 | - public function updateCMSFields(FieldList $fields) |
|
| 20 | - { |
|
| 21 | - $pagesGridField = $fields->dataFieldByName('Pages'); |
|
| 22 | - if ($pagesGridField) { |
|
| 23 | - $pagesGridField->getConfig()->removeComponentsByType(GridFieldAddNewButton::class); |
|
| 24 | - } |
|
| 25 | - } |
|
| 19 | + public function updateCMSFields(FieldList $fields) |
|
| 20 | + { |
|
| 21 | + $pagesGridField = $fields->dataFieldByName('Pages'); |
|
| 22 | + if ($pagesGridField) { |
|
| 23 | + $pagesGridField->getConfig()->removeComponentsByType(GridFieldAddNewButton::class); |
|
| 24 | + } |
|
| 25 | + } |
|
| 26 | 26 | } |
@@ -5,41 +5,41 @@ |
||
| 5 | 5 | */ |
| 6 | 6 | class CwpSiteSummaryExtension extends Extension |
| 7 | 7 | { |
| 8 | - /** |
|
| 9 | - * Updates the modules used for the version label by: |
|
| 10 | - * - Removing SS Framework |
|
| 11 | - * - Adding CWP |
|
| 12 | - * - Relabelling SS CMS |
|
| 13 | - * |
|
| 14 | - * @param array $modules |
|
| 15 | - */ |
|
| 16 | - public function updateVersionModules(&$modules) |
|
| 17 | - { |
|
| 18 | - unset($modules['silverstripe/framework']); |
|
| 19 | - $modules = ['cwp/cwp' => 'CWP'] + $modules; |
|
| 20 | - $modules['silverstripe/cms'] = 'SilverStripe CMS'; |
|
| 21 | - } |
|
| 8 | + /** |
|
| 9 | + * Updates the modules used for the version label by: |
|
| 10 | + * - Removing SS Framework |
|
| 11 | + * - Adding CWP |
|
| 12 | + * - Relabelling SS CMS |
|
| 13 | + * |
|
| 14 | + * @param array $modules |
|
| 15 | + */ |
|
| 16 | + public function updateVersionModules(&$modules) |
|
| 17 | + { |
|
| 18 | + unset($modules['silverstripe/framework']); |
|
| 19 | + $modules = ['cwp/cwp' => 'CWP'] + $modules; |
|
| 20 | + $modules['silverstripe/cms'] = 'SilverStripe CMS'; |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Updates the dropdown filter used to filter supported packages by renaming the labels (replaces the existing |
|
| 25 | - * filter options) |
|
| 26 | - * |
|
| 27 | - * @param GridFieldDropdownFilter $dropdownFilter |
|
| 28 | - */ |
|
| 29 | - public function updateDropdownFilterOptions($dropdownFilter) |
|
| 30 | - { |
|
| 31 | - $dropdownFilter->removeFilterOption('supported'); |
|
| 32 | - $dropdownFilter->removeFilterOption('unsupported'); |
|
| 23 | + /** |
|
| 24 | + * Updates the dropdown filter used to filter supported packages by renaming the labels (replaces the existing |
|
| 25 | + * filter options) |
|
| 26 | + * |
|
| 27 | + * @param GridFieldDropdownFilter $dropdownFilter |
|
| 28 | + */ |
|
| 29 | + public function updateDropdownFilterOptions($dropdownFilter) |
|
| 30 | + { |
|
| 31 | + $dropdownFilter->removeFilterOption('supported'); |
|
| 32 | + $dropdownFilter->removeFilterOption('unsupported'); |
|
| 33 | 33 | |
| 34 | - $dropdownFilter->addFilterOption( |
|
| 35 | - 'supported', |
|
| 36 | - _t(__CLASS__ . '.FilterSupported', 'CWP recipe modules'), |
|
| 37 | - ['Supported' => true] |
|
| 38 | - ); |
|
| 39 | - $dropdownFilter->addFilterOption( |
|
| 40 | - 'unsupported', |
|
| 41 | - _t(__CLASS__ . '.FilterUnsupported', 'Non CWP modules'), |
|
| 42 | - ['Supported' => false] |
|
| 43 | - ); |
|
| 44 | - } |
|
| 34 | + $dropdownFilter->addFilterOption( |
|
| 35 | + 'supported', |
|
| 36 | + _t(__CLASS__ . '.FilterSupported', 'CWP recipe modules'), |
|
| 37 | + ['Supported' => true] |
|
| 38 | + ); |
|
| 39 | + $dropdownFilter->addFilterOption( |
|
| 40 | + 'unsupported', |
|
| 41 | + _t(__CLASS__ . '.FilterUnsupported', 'Non CWP modules'), |
|
| 42 | + ['Supported' => false] |
|
| 43 | + ); |
|
| 44 | + } |
|
| 45 | 45 | } |