Skip to content

Commit

Permalink
commenting
Browse files Browse the repository at this point in the history
  • Loading branch information
Uncle Cheese committed Aug 13, 2013
1 parent 2c635f6 commit 5a470e4
Show file tree
Hide file tree
Showing 17 changed files with 318 additions and 228 deletions.
24 changes: 14 additions & 10 deletions _config.php
@@ -1,16 +1,20 @@
<?php


define('MOCK_DATAOBJECTS_DIR',basename(dirname(__FILE__)));

foreach(SS_ClassLoader::instance()->getManifest()->getDescendantsOf("DBField") as $class) {
$mockClass = "Mock{$class}Field";
if(class_exists($mockClass)) {
$e = Config::inst()->get($class, "extensions");
$e[] = $mockClass;
Config::inst()->update($class, "extensions", $e);
if(Director::get_environment_type() == "dev") {
define('MOCK_DATAOBJECTS_DIR',basename(dirname(__FILE__)));
$e = Config::inst()->get("DBField", "extensions");
$e[] = "MockDBField";
Config::inst()->update("DBField", "extensions", $e);
foreach(SS_ClassLoader::instance()->getManifest()->getDescendantsOf("DBField") as $class) {
$mockClass = "Mock{$class}Field";
if(class_exists($mockClass)) {
$e = Config::inst()->get($class, "extensions");
$e[] = $mockClass;
Config::inst()->update($class, "extensions", $e);
}
}
LeftAndMain::require_javascript(MOCK_DATAOBJECTS_DIR.'/javascript/mock_dataobjects.js');
}

LeftAndMain::require_javascript(MOCK_DATAOBJECTS_DIR.'/javascript/mock_dataobjects.js');
CMSMenu::remove_menu_item('MockChildrenController');
CMSMenu::remove_menu_item('MockChildrenController');
9 changes: 6 additions & 3 deletions _config/mock_dataobjects.yml
@@ -1,14 +1,17 @@
---
Name: mockdataobjects
Only:
environment: dev
---
DBField:
extensions:
- MockDBField

DataObject:
extensions:
- MockDataObject

DBField:
extensions:
- MockDBField

MockDataObject:
fill_options:
include_relations: true
Expand Down
64 changes: 57 additions & 7 deletions code/admins/MockChildrenController.php
@@ -1,15 +1,48 @@
<?php


/**
* Displays a page for creating mock children in the CMS
*
* @package silverstripe-mock-dataobjects
* @author Uncle Cheese <unclecheese@leftandmain.com>
*/
class MockChildrenController extends CMSMain {


/**
* @var string
*/
private static $url_segment = 'pages/addmockchildren';


/**
* @var string
*/
private static $url_rule = '/$Action/$ID/$OtherID';


/**
* @var int
*/
private static $url_priority = 50;


/**
* @var string
*/
private static $menu_title = 'Add mock children';


/**
* @var string
*/
private static $required_permission_codes = 'CMS_ACCESS_CMSMain';


/**
* @var array
*/
private static $allowed_actions = array(
'MockChildrenForm',
'doAddMockChildren',
Expand All @@ -18,13 +51,24 @@ class MockChildrenController extends CMSMain {





/**
* The default action to show the page. Accepts the ID of the page in the ID param
*
* @param SS_HTTPRequest
* @return SSViewer
*/
public function node(SS_HTTPRequest $r) {
return $this->getResponseNegotiator()->respond($r);
}

function MockChildrenForm() {


/**
* Builds the form for creating mock children.
*
* @return CMSForm
*/
public function MockChildrenForm() {
$pageTypes = array();
$parentID = $this->request->param('ID') ?: $this->request->requestVar('ID');
$parentPage = SiteTree::get()->byID((int) $parentID);
Expand Down Expand Up @@ -92,6 +136,14 @@ function MockChildrenForm() {
}



/**
* Handles the creation of mock children with {@link MockDataBuilder}
*
* @param array $data The data passed in from the form
* @param CMSForm $form The Form object that was used
* @return SSViewer
*/
public function doAddMockChildren($data, $form) {
$parentPage = SiteTree::get()->byID((int) $data['ID']);
if(!$parentPage) return false;
Expand All @@ -116,9 +168,7 @@ public function doAddMockChildren($data, $form) {
_t('MockData.CREATESUCCESS','Created {count} mock children under {title}',array('count' => $data['Count'], 'title' => $parentPage->Title))
);
$this->redirect(Controller::join_links(singleton('CMSPagesController')->Link()));
return $this->getResponseNegotiator()->respond($this->request);




return $this->getResponseNegotiator()->respond($this->request);
}
}
127 changes: 0 additions & 127 deletions code/admins/MockDataAdmin.php

This file was deleted.

16 changes: 13 additions & 3 deletions code/extensions/MockDataCMS.php
@@ -1,9 +1,21 @@
<?php


/**
* Injects functionality into the CMS to allow for populating a page with mock data
*
* @package silverstripe-mock-dataobjects
* @author Uncle Cheese <unclecheese@leftandmain.com>
*/
class MockDataCMS extends DataExtension {


/**
* A form action that takes the current page ID to populate it with mock data
*
* @param array $data The data passed in from the form
* @param CMSForm $form The Form object that was used
*/
public function addMockData($data, $form) {
if($page = SiteTree::get()->byID($data['ID'])) {
$page->fill(array(
Expand All @@ -18,9 +30,7 @@ public function addMockData($data, $form) {
);

}

return $this->owner->getResponseNegotiator()->respond($this->owner->request);
}



}
20 changes: 19 additions & 1 deletion code/extensions/MockDataGridFieldItemRequest.php
@@ -1,16 +1,34 @@
<?php



/**
* Injects functionality into {@link GridField} to show a button that adds mock data to
* the record when in detail view.
*
* @package silverstripe-mock-dataobjects
* @author Uncle Cheese <unclecheese@leftandmain.com>
*/
class MockDataGridFieldItemRequest extends DataExtension {


/**
* Updates the edit form to add a new form action
*
* @param Form $form The item edit form
*/
public function updateItemEditForm(Form $form) {
$form->Actions()->push(FormAction::create("doAddMockData",_t('MockData.FILLWITHMOCKDATA','Fill with mock data')));
}



/**
* A form action that handles populating the record with mock data
*
* @param array $data The data that as passed in from the form
* @param Form $form The Form object that was used
* @return SSViewer
*/
public function doAddMockData($data, $form) {
$this->owner->record->fill(array(
'only_empty' => true,
Expand Down

0 comments on commit 5a470e4

Please sign in to comment.