From b0ba742c1fc18e4cba7d3eaeb1a7d6a9c3c1ac5d Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 23 Mar 2016 12:12:48 +1300 Subject: [PATCH] Campaign form schema and edit form Remove once we have a schema-driven GridField in place. Edit form should be a GridFieldDetailForm, but there's more work to do for schema generation from this component. --- admin/code/CampaignAdmin.php | 144 ++++++++++++++++++++++++++++++++++- 1 file changed, 143 insertions(+), 1 deletion(-) diff --git a/admin/code/CampaignAdmin.php b/admin/code/CampaignAdmin.php index 702e697ae..683e1b3f1 100644 --- a/admin/code/CampaignAdmin.php +++ b/admin/code/CampaignAdmin.php @@ -13,6 +13,8 @@ class CampaignAdmin extends LeftAndMain implements PermissionProvider { 'readCampaign', 'updateCampaign', 'deleteCampaign', + 'schema', + 'DetailEditForm' ]; private static $menu_priority = 11; @@ -20,6 +22,7 @@ class CampaignAdmin extends LeftAndMain implements PermissionProvider { private static $menu_title = 'Campaigns'; private static $url_handlers = [ + 'GET items' => 'readCampaigns', 'POST item/$ID' => 'createCampaign', 'GET item/$ID' => 'readCampaign', 'PUT item/$ID' => 'updateCampaign', @@ -36,13 +39,118 @@ class CampaignAdmin extends LeftAndMain implements PermissionProvider { } public function getClientConfig() { + // TODO Hardcoding schema until we can get GridField to generate a schema dynamically + $json = << [ - 'editForm' => $this->schema->getSchema($this->getEditForm()) + 'editForm' => [ + // TODO Use schemaUrl instead + 'schema' => json_decode($json) + ] ] ]); } + public function getEditForm($id = null, $fields = null) { + return ''; + } + /** * REST endpoint to create a campaign. * @@ -58,6 +166,21 @@ class CampaignAdmin extends LeftAndMain implements PermissionProvider { return $response; } + /** + * REST endpoint to get a list of campaigns. + * + * @param SS_HTTPRequest $request + * + * @return SS_HTTPResponse + */ + public function readCampaigns(SS_HTTPRequest $request) { + $response = new SS_HTTPResponse(); + $response->addHeader('Content-Type', 'application/json'); + $response->setBody(Convert::raw2json(['campaigns' => 'read'])); + + return $response; + } + /** * REST endpoint to get a campaign. * @@ -103,4 +226,23 @@ class CampaignAdmin extends LeftAndMain implements PermissionProvider { return $response; } + /** + * @todo Use GridFieldDetailForm once it can handle structured data and form schemas + * + * @return Form + */ + public function getDetailEditForm() { + return Form::create( + $this, + 'DetailEditForm', + FieldList::create( + TextField::create('Name'), + TextAreaField::create('Description') + ), + FieldList::create( + FormAction::create('save', 'Save') + ) + ); + } + }