Permalink
Browse files

More cleanup for SS3.0.

  • Loading branch information...
1 parent 79d2476 commit f11a2d33db9738067921d935dfa4a4f80e433caa @mateusz committed Dec 4, 2012
Showing with 42 additions and 31 deletions.
  1. +38 −26 Readme.md
  2. +2 −3 code/Poll.php
  3. +2 −2 code/PollForm.php
View
@@ -6,7 +6,7 @@
## Requirements
-SilverStripe 2.4.x
+SilverStripe 3.0.x
## Installation
@@ -30,7 +30,9 @@ SilverStripe 2.4.x
### Connect Poll object with PollForm
-The PollForm knows how to render itself, and is able to render both the selection form and the chart. It needs to get a Poll object as its input though, and it's up to you to provide it: it will depend on your project how you will want to do this.
+The PollForm knows how to render itself, and is able to render both the selection form and the chart. It needs to get a
+Poll object as its input though, and it's up to you to provide it: it will depend on your project how you will want to
+do this.
Here is the most basic example of how to associate one Poll with each Page:
@@ -42,25 +44,25 @@ class Page extends SiteTree {
...
- function getCMSFields() {
- $fields = parent::getCMSFields();
-
- $polls = DataObject::get('Poll');
- if ($polls) {
- $pollsMap = $polls->toDropdownMap('ID', 'Title', '--- Select a poll ---');
- $fields->addFieldsToTab('Root.Content.Main', array(
- new DropdownField('PollID', 'Poll', $pollsMap)
- ));
- }
- else {
- $fields->addFieldsToTab('Root.Content.Main', array(
- new LiteralField('Heading', '<h1>No polls available</h1>'),
- new LiteralField('PollID', '<p>There are no polls available. Please use <a href="admin/polls">the polls section</a> to add them.</p>')
- ));
- }
-
- return $fields;
- }
+ function getCMSFields() {
+ $fields = parent::getCMSFields();
+
+ $polls = Poll::get();
+ if ($polls) {
+ $fields->addFieldsToTab('Root.Main', array(
+ new DropdownField('PollID', 'Poll', $polls->map(), $this->PollID, null, '--- Select a poll ---')
+ ));
+ }
+ else {
+ $fields->addFieldsToTab('Root.Main', array(
+ new LiteralField('Heading', '<h1>No polls available</h1>'),
+ new LiteralField('PollID', '<p>There are no polls available. Please use <a href="admin/polls">the polls
+ section</a> to add them.</p>')
+ ));
+ }
+
+ return $fields;
+ }
...
}
@@ -89,11 +91,19 @@ class Page_Controller extends ContentController {
}
```
-With this, you can use $PollForm in your template to specify where you want the poll to show up. This will give you an empty string though, if the Poll passed to PollForm is null, so make sure you are giving it a valid input.
+You will then be able to embed this form in your template like that:
+
+```php
+$PollForm
+```
+
+This allows you to specify where you want the poll to show up. The poll will not appear if the related `SiteTree` object
+has no poll associated with it (i.e. $this->Poll() is empty).
### Customise the chart
-You can obtain a good deal of control by redefining the **PollForm.ss** template in your **theme** folder. Here is the default setup:
+You can obtain a good deal of control by redefining the **PollForm.ss** template in your **theme** folder. Here is the
+default setup:
```html
<% if Poll.Visible %>
@@ -148,8 +158,8 @@ And here is advanced setup that renders the poll as simple HTML blocks, using so
<% end_if %>
```
-If you want to make a site-wide changes, you can use a decorator and define **replaceChart** function. For example the following
-will give you a text-only rendering of results:
+If you want to make a site-wide changes, you can use a decorator and define **replaceChart** function. For example the
+following will give you a text-only rendering of results:
```php
class PollFormDecorator extends DataObjectDecorator {
@@ -169,4 +179,6 @@ Object::add_extension('PollForm', 'PollFormDecorator');
```
-Finally, for a full control of the poll form and the results subclass the PollForm - you can then create form-specific templates or work on the basis of redefining the **getChart** method. This way you can also create multiple parallel presentation layers for the polls.
+Finally, for a full control of the poll form and the results subclass the PollForm - you can then create form-specific
+templates or work on the basis of redefining the **getChart** method. This way you can also create multiple parallel
+presentation layers for the polls.
View
@@ -56,7 +56,7 @@ function getCMSFields() {
new OptionsetField('IsActive', 'Poll state', array(1 => 'Active', 0 => 'Inactive')),
$embargo = new DatetimeField('Embargo', 'Embargo'),
$expiry = new DatetimeField('Expiry', 'Expiry'),
- new HTMLEditorField('Description', 'Description', 12),
+ new HTMLEditorField('Description', 'Description'),
$image = new UploadField('Image', 'Poll image')
)
)
@@ -71,7 +71,7 @@ function getCMSFields() {
$expiry->getTimeField()->setConfig('showdropdown', true);
$expiry->getDateField()->setConfig('dateformat', 'dd/MM/YYYY');
$expiry->getTimeField()->setConfig('timeformat', 'h:m a');
-
+
// Add the fields that depend on the poll being already saved and having an ID
if($this->ID != 0) {
@@ -84,7 +84,6 @@ function getCMSFields() {
$config->addComponent(new GridFieldDeleteAction());
$config->addComponent(new GridFieldDetailForm());
$config->addComponent(new GridFieldSortableHeader());
- $config->addComponent(new GridFieldSortableRows('Order'));
$pollChoicesTable = new GridField(
'Choices',
View
@@ -76,10 +76,10 @@ function submitPoll($data, $form) {
}
$url .= '#'.self::$redirect_to_anchor.'-'.$this->poll->ID;
- Director::redirect($url);
+ $this->controller->redirect($url);
}
else {
- Director::redirectBack();
+ $this->controller->redirectBack();
}
}

0 comments on commit f11a2d3

Please sign in to comment.