Permalink
Browse files

ENHANCEMENT: SSF-106 adding the ability to turn off and on the "add n…

…ew" button on the GridFieldTitle
  • Loading branch information...
Julian Seidenberg
Julian Seidenberg committed Mar 5, 2012
1 parent 8284fcc commit a715785a4280c2c9c72192918883a735792f6f70
@@ -1,13 +1,25 @@
<?php
class GridFieldTitle implements GridField_HTMLProvider {
+
+ protected $newEnabled = true;
+
function getHTMLFragments($gridField) {
return array(
'header' => $gridField->customise(array(
- 'NewLink' => Controller::join_links($gridField->Link('item'), 'new')
+ 'NewLink' => Controller::join_links($gridField->Link('item'), 'new'),
+ 'NewEnabled' => $this->getNewEnabled()
))->renderWith('GridFieldTitle')
);
}
+
+ function getNewEnabled() {
+ return $this->newEnabled;
+ }
+
+ function setNewEnabled($enabled) {
+ $this->newEnabled = $enabled;
+ }
}
?>
@@ -1,3 +1,3 @@
<tr class="title">
- <th colspan="$ColumnCount"><h2>$Title</h2> <a href="$NewLink" class="action ss-ui-action-constructive ss-ui-button ui-button ui-widget ui-state-default ui-corner-all new new-link" data-icon="add"><% _t('GridField.AddNew', 'Add New') %></a></th>
+ <th colspan="$ColumnCount"><h2>$Title</h2><% if NewEnabled %> <a href="$NewLink" class="action ss-ui-action-constructive ss-ui-button ui-button ui-widget ui-state-default ui-corner-all new new-link" data-icon="add"><% _t('GridField.AddNew', 'Add New') %></a><% end_if %></th>
</tr>
@@ -1,5 +1,5 @@
<?php
-class GridFieldtest extends SapphireTest {
+class GridFieldTest extends SapphireTest {
/**
* @covers GridField::__construct
@@ -0,0 +1,33 @@
+<?php
+class GridFieldTitleTest extends SapphireTest {
+
+
+ public function testGridTitleAddNewEnabled() {
+ //construct a fake form field to render out the grid field within it
+ $config = new GridFieldConfig();
+ $config->addComponent($titleField = new GridFieldTitle());
+ $actions = new FieldList();
+ $grid = new GridField('TestField', 'Test Field', new DataList('Company'),$config);
+ $fields = new FieldList($rootTab = new TabSet("Root",$tabMain = new Tab('Main',$grid)));
+ $form = new Form(Controller::curr(), "TestForm", $fields, $actions);
+
+ $titleField->setNewEnabled(true);
+ $html = $form->forTemplate();
+ $this->assertContains('data-icon="add"', $html,"HTML contains the 'add new' button");
+ }
+
+ public function testGridTitleAddNewDisabled() {
+ //construct a fake form field to render out the grid field within it
+ $config = new GridFieldConfig();
+ $config->addComponent($titleField = new GridFieldTitle());
+ $actions = new FieldList();
+ $grid = new GridField('TestField', 'Test Field', new DataList('Company'),$config);
+ $fields = new FieldList($rootTab = new TabSet("Root",$tabMain = new Tab('Main',$grid)));
+ $form = new Form(Controller::curr(), "TestForm", $fields, $actions);
+
+ $titleField->setNewEnabled(false);
+ $html = $form->forTemplate();
+ $this->assertNotContains('data-icon="add"', $html,"HTML does not contain the 'add new' button");
+ }
+}
+?>

0 comments on commit a715785

Please sign in to comment.