mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT: SSF-106 adding the ability to turn off and on the "add new" button on the GridFieldTitle
This commit is contained in:
parent
8284fcc75b
commit
a715785a42
@ -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
|
||||
|
33
tests/forms/gridfield/GridFieldTitleTest.php
Normal file
33
tests/forms/gridfield/GridFieldTitleTest.php
Normal file
@ -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");
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue
Block a user