From 8b82dae06c45a70683da8c5dfafa7e6fbbdebf8b Mon Sep 17 00:00:00 2001 From: Stig Lindqvist Date: Fri, 9 Mar 2012 12:54:02 +1300 Subject: [PATCH 1/4] API CHANGE: Renaming of gridfield components #6921 --- admin/code/ModelAdmin.php | 2 +- admin/code/SecurityAdmin.php | 4 +-- admin/tests/SecurityAdminTest.php | 4 +-- docs/en/topics/grid-field.md | 30 ++++++++-------- forms/HtmlEditorField.php | 2 +- forms/UploadField.php | 2 +- ... => GridFieldAddExistingAutocompleter.php} | 8 ++--- forms/gridfield/GridFieldConfig.php | 26 +++++++------- forms/gridfield/GridFieldDeleteAction.php | 4 +-- ...PopupForms.php => GridFieldDetailForm.php} | 6 ++-- ...EditAction.php => GridFieldEditButton.php} | 6 ++-- ...Exporter.php => GridFieldExportButton.php} | 2 +- ...ldFilter.php => GridFieldFilterHeader.php} | 12 +++---- ...onDelete.php => GridFieldRemoveButton.php} | 4 +-- ...ldTitle.php => GridFieldToolbarHeader.php} | 4 +-- security/Group.php | 8 ++--- ...ldPopupForms.ss => GridFieldDetailForm.ss} | 0 ...s => GridFieldAddExistingAutocompleter.ss} | 0 ...ldEditAction.ss => GridFieldEditButton.ss} | 0 ...er_Row.ss => GridFieldFilterHeader_Row.ss} | 0 ...ieldTitle.ss => GridFieldToolbarHeader.ss} | 0 tests/forms/GridFieldTest.php | 4 +-- ...GridFieldAddExistingAutocompleterTest.php} | 16 ++++----- ...msTest.php => GridFieldDetailFormTest.php} | 36 +++++++++---------- .../gridfield/GridFieldDetailFormTest.yml | 12 +++++++ ...onTest.php => GridFieldEditButtonTest.php} | 4 +-- .../gridfield/GridFieldPopupFormsTest.yml | 12 ------- ...est.php => GridFieldToolbarHeaderTest.php} | 8 ++--- 28 files changed, 108 insertions(+), 108 deletions(-) rename forms/gridfield/{GridFieldRelationAdd.php => GridFieldAddExistingAutocompleter.php} (95%) rename forms/gridfield/{GridFieldPopupForms.php => GridFieldDetailForm.php} (98%) rename forms/gridfield/{GridFieldEditAction.php => GridFieldEditButton.php} (92%) rename forms/gridfield/{GridFieldExporter.php => GridFieldExportButton.php} (96%) rename forms/gridfield/{GridFieldFilter.php => GridFieldFilterHeader.php} (82%) rename forms/gridfield/{GridFieldRelationDelete.php => GridFieldRemoveButton.php} (93%) rename forms/gridfield/{GridFieldTitle.php => GridFieldToolbarHeader.php} (93%) rename templates/{GridFieldPopupForms.ss => GridFieldDetailForm.ss} (100%) rename templates/Includes/{GridFieldRelationAdd.ss => GridFieldAddExistingAutocompleter.ss} (100%) rename templates/Includes/{GridFieldEditAction.ss => GridFieldEditButton.ss} (100%) rename templates/Includes/{GridFieldFilter_Row.ss => GridFieldFilterHeader_Row.ss} (100%) rename templates/Includes/{GridFieldTitle.ss => GridFieldToolbarHeader.ss} (100%) rename tests/forms/gridfield/{GridFieldRelationAddTest.php => GridFieldAddExistingAutocompleterTest.php} (79%) rename tests/forms/gridfield/{GridFieldPopupFormsTest.php => GridFieldDetailFormTest.php} (72%) create mode 100644 tests/forms/gridfield/GridFieldDetailFormTest.yml rename tests/forms/gridfield/{GridFieldEditActionTest.php => GridFieldEditButtonTest.php} (96%) delete mode 100644 tests/forms/gridfield/GridFieldPopupFormsTest.yml rename tests/forms/gridfield/{GridFieldTitleTest.php => GridFieldToolbarHeaderTest.php} (87%) diff --git a/admin/code/ModelAdmin.php b/admin/code/ModelAdmin.php index c2f833e12..a76b9dd38 100644 --- a/admin/code/ModelAdmin.php +++ b/admin/code/ModelAdmin.php @@ -710,7 +710,7 @@ class ModelAdmin_CollectionController extends Controller { false, $datalist, $fieldConfig = GridFieldConfig_RecordEditor::create($numItemsPerPage) - ->addComponent(new GridFieldExporter())->removeComponentsByType('GridFieldFilter') + ->addComponent(new GridFieldExportButton())->removeComponentsByType('GridFieldFilterHeader') )->setDisplayFields($this->getResultColumns($searchCriteria)); return $tf; diff --git a/admin/code/SecurityAdmin.php b/admin/code/SecurityAdmin.php index a3c8886da..6f44b6a89 100755 --- a/admin/code/SecurityAdmin.php +++ b/admin/code/SecurityAdmin.php @@ -48,9 +48,9 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider { false, DataList::create('Member'), $memberListConfig = GridFieldConfig_RecordEditor::create() - ->addComponent(new GridFieldExporter()) + ->addComponent(new GridFieldExportButton()) )->addExtraClass("members_grid"); - $memberListConfig->getComponentByType('GridFieldPopupForms')->setValidator(new Member_Validator()); + $memberListConfig->getComponentByType('GridFieldDetailForm')->setValidator(new Member_Validator()); $groupList = Object::create('GridField', 'Groups', diff --git a/admin/tests/SecurityAdminTest.php b/admin/tests/SecurityAdminTest.php index d9470c032..961597954 100644 --- a/admin/tests/SecurityAdminTest.php +++ b/admin/tests/SecurityAdminTest.php @@ -9,7 +9,7 @@ class SecurityAdminTest extends FunctionalTest { protected $extraDataObjects = array('LeftAndMainTest_Object'); - // TODO Fix export feature (moved from MemberTableField to GridFieldExporter) + // TODO Fix export feature (moved from MemberTableField to GridFieldExportButton) // function testGroupExport() { // $this->session()->inst_set('loggedInAs', $this->idFromFixture('Member', 'admin')); @@ -27,7 +27,7 @@ class SecurityAdminTest extends FunctionalTest { // $this->assertRegExp('/"","","admin@example.com"/', $lines[1], "Member values are correctly exported"); // } - // TODO Fix export feature (moved from MemberTableField to GridFieldExporter) + // TODO Fix export feature (moved from MemberTableField to GridFieldExportButton) // function testEmptyGroupExport() { // $this->session()->inst_set('loggedInAs', $this->idFromFixture('Member', 'admin')); diff --git a/docs/en/topics/grid-field.md b/docs/en/topics/grid-field.md index a53938e73..eab4eb7dc 100644 --- a/docs/en/topics/grid-field.md +++ b/docs/en/topics/grid-field.md @@ -30,7 +30,7 @@ This example creates exactly the same kind of grid as the previous example, but :::php $config = GridFieldConfig::create(); // Provide a header row with filter controls - $config->addComponent(new GridFieldFilter()); + $config->addComponent(new GridFieldFilterHeader()); // Provide a default set of columns based on $summary_fields $config->addComponent(new GridFieldDefaultColumns()); // Provide a header row with sort controls @@ -99,7 +99,7 @@ You can also specify formatting replacements, to replace column contents with HT This component will add a header to the grid with sort buttons. It will detect which columns are sortable and only provide sort controls on those columns. -### GridFieldFilter +### GridFieldFilterHeader This component will add a header row with a text field filter for each column, letting you filter the results with text searches. It will detect which columns are filterable and only provide sort controls on those columns. @@ -109,34 +109,34 @@ This component will limit output to a fixed number of items per page add a foote ### GridFieldAction -TODO Describe component, including GridFieldEditAction/GridFieldDeleteAction +TODO Describe component, including GridFieldEditButton/GridFieldDeleteAction -### GridFieldRelationAdd +### GridFieldAddExistingAutocompleter This class is is responsible for adding objects to another object's has_many and many_many relation, as defined by the `[api:RelationList]` passed to the GridField constructor. Objects can be searched through an input field (partially matching one or more fields). Selecting from the results will add the object to the relation. -Often used alongside `[api:GridFieldRelationDelete]` for detaching existing records from a relatinship. +Often used alongside `[api:GridFieldRemoveButton]` for detaching existing records from a relatinship. For easier setup, have a look at a sample configuration in `[api:GridFieldConfig_RelationEditor]`. -### GridFieldRelationDelete +### GridFieldRemoveButton Allows to detach an item from an existing has_many or many_many relationship. Similar to {@link GridFieldDeleteAction}, but allows to distinguish between a "delete" and "detach" action in the UI - and to use both in parallel, if required. Requires the GridField to be populated with a `[api:RelationList]` rather than a plain DataList. -Often used alongside `[api:GridFieldRelationAdd]` to add existing records to the relationship. +Often used alongside `[api:GridFieldAddExistingAutocompleter]` to add existing records to the relationship. -### GridFieldPopupForms +### GridFieldDetailForm -TODO Describe component, including how it relates to GridFieldEditAction. Point to GridFieldConfig_RelationEditor for easier defaults. +TODO Describe component, including how it relates to GridFieldEditButton. Point to GridFieldConfig_RelationEditor for easier defaults. -### GridFieldTitle +### GridFieldToolbarHeader TODO -### GridFieldExporter +### GridFieldExportButton TODO @@ -152,16 +152,16 @@ It's common for a component to implement several of these interfaces in order to * `GridField_ActionProvider`, to define the sortasc and sortdesc actions that add sort column and direction to the state. * `GridField_DataManipulator`, to alter the sorting of the data list based on the sort column and direction values in the state. - ### GridFieldRelationAdd + ### GridFieldAddExistingAutocompleter -A GridFieldRelationAdd is responsible for adding objects to another object's `has_many` and `many_many` relation, +A GridFieldAddExistingAutocompleter is responsible for adding objects to another object's `has_many` and `many_many` relation, as defined by the `[api:RelationList]` passed to the GridField constructor. Objects can be searched through an input field (partially matching one or more fields). Selecting from the results will add the object to the relation. :::php $group = DataObject::get_one('Group'); - $config = GridFieldConfig::create()->addComponent(new GridFieldRelationAdd(array('FirstName', 'Surname', 'Email')); + $config = GridFieldConfig::create()->addComponent(new GridFieldAddExistingAutocompleter(array('FirstName', 'Surname', 'Email')); $gridField = new GridField('Members', 'Members', $group->Members(), $config); ## Component interfaces @@ -293,7 +293,7 @@ Here is an example in full. The actual implementation of the view and edit form * - /field//item/ * - /field//item//edit */ - class GridFieldPopupForms implements GridField_URLHandler { + class GridFieldDetailForm implements GridField_URLHandler { public function getURLHandlers($gridField) { return array( 'item/$ID' => 'handleItem', diff --git a/forms/HtmlEditorField.php b/forms/HtmlEditorField.php index a372676b8..54c0a57dc 100644 --- a/forms/HtmlEditorField.php +++ b/forms/HtmlEditorField.php @@ -355,7 +355,7 @@ class HtmlEditorField_Toolbar extends RequestHandler { $fileFieldConfig = GridFieldConfig::create(); $fileFieldConfig->addComponent(new GridFieldSortableHeader()); - $fileFieldConfig->addComponent(new GridFieldFilter()); + $fileFieldConfig->addComponent(new GridFieldFilterHeader()); $fileFieldConfig->addComponent(new GridFieldDefaultColumns()); $fileFieldConfig->addComponent(new GridFieldPaginator(5)); $fileField = new GridField('Files', false, null, $fileFieldConfig); diff --git a/forms/UploadField.php b/forms/UploadField.php index 8043b18d8..6a74dabb5 100644 --- a/forms/UploadField.php +++ b/forms/UploadField.php @@ -846,7 +846,7 @@ class UploadField_SelectHandler extends RequestHandler { $folder = $this->getFolder(); $config = GridFieldConfig::create(); $config->addComponent(new GridFieldSortableHeader()); - $config->addComponent(new GridFieldFilter()); + $config->addComponent(new GridFieldFilterHeader()); $config->addComponent(new GridFieldDefaultColumns()); $config->addComponent(new GridFieldPaginator(10)); diff --git a/forms/gridfield/GridFieldRelationAdd.php b/forms/gridfield/GridFieldAddExistingAutocompleter.php similarity index 95% rename from forms/gridfield/GridFieldRelationAdd.php rename to forms/gridfield/GridFieldAddExistingAutocompleter.php index 5c4e99ccc..13828f2e6 100755 --- a/forms/gridfield/GridFieldRelationAdd.php +++ b/forms/gridfield/GridFieldAddExistingAutocompleter.php @@ -4,17 +4,17 @@ * as defined by the {@link RelationList} passed to the GridField constructor. * Objects can be searched through an input field (partially matching one or more fields). * Selecting from the results will add the object to the relation. - * Often used alongside {@link GridFieldRelationDelete} for detaching existing records from a relatinship. + * Often used alongside {@link GridFieldRemoveButton} for detaching existing records from a relatinship. * For easier setup, have a look at a sample configuration in {@link GridFieldConfig_RelationEditor}. */ -class GridFieldRelationAdd implements GridField_HTMLProvider, GridField_ActionProvider, GridField_DataManipulator, GridField_URLHandler { +class GridFieldAddExistingAutocompleter implements GridField_HTMLProvider, GridField_ActionProvider, GridField_DataManipulator, GridField_URLHandler { /** * Which template to use for rendering * * @var string $itemClass */ - protected $itemClass = 'GridFieldRelationAdd'; + protected $itemClass = 'GridFieldAddExistingAutocompleter'; /** * Which columns that should be used for doing a "StartsWith" search. @@ -161,7 +161,7 @@ class GridFieldRelationAdd implements GridField_HTMLProvider, GridField_ActionPr $searchFields = ($this->getSearchFields()) ? $this->getSearchFields() : $this->scaffoldSearchFields($dataClass); if(!$searchFields) { throw new LogicException( - sprintf('GridFieldRelationAdd: No searchable fields could be found for class "%s"', $dataClass) + sprintf('GridFieldAddExistingAutocompleter: No searchable fields could be found for class "%s"', $dataClass) ); } diff --git a/forms/gridfield/GridFieldConfig.php b/forms/gridfield/GridFieldConfig.php index ce9a3304e..5cb804989 100755 --- a/forms/gridfield/GridFieldConfig.php +++ b/forms/gridfield/GridFieldConfig.php @@ -131,9 +131,9 @@ class GridFieldConfig_Base extends GridFieldConfig { * @param int $itemsPerPage - How many items per page should show up */ public function __construct($itemsPerPage=null) { - $this->addComponent(new GridFieldTitle()); + $this->addComponent(new GridFieldToolbarHeader()); $this->addComponent(new GridFieldSortableHeader()); - $this->addComponent(new GridFieldFilter()); + $this->addComponent(new GridFieldFilterHeader()); $this->addComponent(new GridFieldDefaultColumns()); $this->addComponent(new GridFieldPaginator($itemsPerPage)); } @@ -158,14 +158,14 @@ class GridFieldConfig_RecordEditor extends GridFieldConfig { * @param int $itemsPerPage - How many items per page should show up */ public function __construct($itemsPerPage=null) { - $this->addComponent(new GridFieldTitle()); + $this->addComponent(new GridFieldToolbarHeader()); $this->addComponent(new GridFieldSortableHeader()); - $this->addComponent(new GridFieldFilter()); + $this->addComponent(new GridFieldFilterHeader()); $this->addComponent(new GridFieldDefaultColumns()); - $this->addComponent(new GridFieldEditAction()); + $this->addComponent(new GridFieldEditButton()); $this->addComponent(new GridFieldDeleteAction()); $this->addComponent(new GridFieldPaginator($itemsPerPage)); - $this->addComponent(new GridFieldPopupForms()); + $this->addComponent(new GridFieldDetailForm()); } } @@ -181,7 +181,7 @@ class GridFieldConfig_RecordEditor extends GridFieldConfig { * for example to change the field to search. * * GridFieldConfig_RelationEditor::create() - * ->getComponentByType('GridFieldRelationAdd')->setSearchFields('MyField'); + * ->getComponentByType('GridFieldAddExistingAutocompleter')->setSearchFields('MyField'); * */ class GridFieldConfig_RelationEditor extends GridFieldConfig { @@ -200,14 +200,14 @@ class GridFieldConfig_RelationEditor extends GridFieldConfig { * @param int $itemsPerPage - How many items per page should show up */ public function __construct($itemsPerPage=null) { - $this->addComponent(new GridFieldTitle()); - $this->addComponent(new GridFieldRelationAdd()); + $this->addComponent(new GridFieldToolbarHeader()); + $this->addComponent(new GridFieldAddExistingAutocompleter()); $this->addComponent(new GridFieldSortableHeader()); - $this->addComponent(new GridFieldFilter()); + $this->addComponent(new GridFieldFilterHeader()); $this->addComponent(new GridFieldDefaultColumns()); - $this->addComponent(new GridFieldEditAction()); - $this->addComponent(new GridFieldRelationDelete()); + $this->addComponent(new GridFieldEditButton()); + $this->addComponent(new GridFieldRemoveButton()); $this->addComponent(new GridFieldPaginator($itemsPerPage)); - $this->addComponent(new GridFieldPopupForms()); + $this->addComponent(new GridFieldDetailForm()); } } diff --git a/forms/gridfield/GridFieldDeleteAction.php b/forms/gridfield/GridFieldDeleteAction.php index f2837fed4..7aa505d49 100644 --- a/forms/gridfield/GridFieldDeleteAction.php +++ b/forms/gridfield/GridFieldDeleteAction.php @@ -1,7 +1,7 @@ getList()->byID($id); if(!$item->canDelete()) { throw new ValidationException(_t('GridFieldAction_Delete.DeletePermissionsFailure',"No delete permissions"),0); diff --git a/forms/gridfield/GridFieldPopupForms.php b/forms/gridfield/GridFieldDetailForm.php similarity index 98% rename from forms/gridfield/GridFieldPopupForms.php rename to forms/gridfield/GridFieldDetailForm.php index cdd500f46..6b9a1a3df 100755 --- a/forms/gridfield/GridFieldPopupForms.php +++ b/forms/gridfield/GridFieldDetailForm.php @@ -3,21 +3,21 @@ /** * Provides view and edit forms at GridField-specific URLs. * These can be placed into pop-ups by an appropriate front-end. - * Usually added to a grid field alongside of {@link GridFieldEditAction} + * Usually added to a grid field alongside of {@link GridFieldEditButton} * which takes care of linking the individual rows to their edit view. * * The URLs provided will be off the following form: * - /field//item/ * - /field//item//edit */ -class GridFieldPopupForms implements GridField_URLHandler { +class GridFieldDetailForm implements GridField_URLHandler { /** * @var String */ - protected $template = 'GridFieldPopupForms'; + protected $template = 'GridFieldDetailForm'; /** * diff --git a/forms/gridfield/GridFieldEditAction.php b/forms/gridfield/GridFieldEditButton.php similarity index 92% rename from forms/gridfield/GridFieldEditAction.php rename to forms/gridfield/GridFieldEditButton.php index 0425f4f51..32bf2943d 100644 --- a/forms/gridfield/GridFieldEditAction.php +++ b/forms/gridfield/GridFieldEditButton.php @@ -3,10 +3,10 @@ * Provides the entry point to editing a single record presented by the grid. * Doesn't show an edit view on its own or modifies the record, but rather relies on routing conventions * established in {@link getColumnContent()}. The default routing applies to - * the {@link GridFieldPopupForms} component, which has to be added separately + * the {@link GridFieldDetailForm} component, which has to be added separately * to the grid field configuration. */ -class GridFieldEditAction implements GridField_ColumnProvider { +class GridFieldEditButton implements GridField_ColumnProvider { /** * Add a column 'Delete' @@ -79,7 +79,7 @@ class GridFieldEditAction implements GridField_ColumnProvider { 'Link' => Controller::join_links($gridField->Link('item'), $record->ID, 'edit') )); - return $data->renderWith('GridFieldEditAction'); + return $data->renderWith('GridFieldEditButton'); } /** diff --git a/forms/gridfield/GridFieldExporter.php b/forms/gridfield/GridFieldExportButton.php similarity index 96% rename from forms/gridfield/GridFieldExporter.php rename to forms/gridfield/GridFieldExportButton.php index 1229ceb24..f853041ce 100644 --- a/forms/gridfield/GridFieldExporter.php +++ b/forms/gridfield/GridFieldExportButton.php @@ -10,7 +10,7 @@ * WARNING: This is experimental and its API is subject to change. Feel free to use it as long as you are happy of * refactoring your code in the future. */ -class GridFieldExporter implements GridField_HTMLProvider, GridField_ActionProvider, GridField_URLHandler { +class GridFieldExportButton implements GridField_HTMLProvider, GridField_ActionProvider, GridField_URLHandler { /** * @var array Map of a property name on the exported objects, with values being the column title in the CSV file. diff --git a/forms/gridfield/GridFieldFilter.php b/forms/gridfield/GridFieldFilterHeader.php similarity index 82% rename from forms/gridfield/GridFieldFilter.php rename to forms/gridfield/GridFieldFilterHeader.php index 86bc381f8..4990efe60 100644 --- a/forms/gridfield/GridFieldFilter.php +++ b/forms/gridfield/GridFieldFilterHeader.php @@ -1,13 +1,13 @@ State->GridFieldFilter; + $state = $gridField->State->GridFieldFilterHeader; if($actionName === 'filter') { if(isset($data['filter'])){ foreach($data['filter'] as $key => $filter ){ @@ -39,7 +39,7 @@ class GridFieldFilter implements GridField_HTMLProvider, GridField_DataManipulat * @return SS_List */ public function getManipulatedData(GridField $gridField, SS_List $dataList) { - $state = $gridField->State->GridFieldFilter; + $state = $gridField->State->GridFieldFilterHeader; if(!isset($state->Columns)) { return $dataList; } @@ -58,7 +58,7 @@ class GridFieldFilter implements GridField_HTMLProvider, GridField_DataManipulat $forTemplate->Fields = new ArrayList; $columns = $gridField->getColumns(); - $filterArguments = $gridField->State->GridFieldFilter->Columns->toArray(); + $filterArguments = $gridField->State->GridFieldFilterHeader->Columns->toArray(); $currentColumn = 0; foreach($columns as $columnField) { @@ -92,7 +92,7 @@ class GridFieldFilter implements GridField_HTMLProvider, GridField_DataManipulat } return array( - 'header' => $forTemplate->renderWith('GridFieldFilter_Row'), + 'header' => $forTemplate->renderWith('GridFieldFilterHeader_Row'), ); } } diff --git a/forms/gridfield/GridFieldRelationDelete.php b/forms/gridfield/GridFieldRemoveButton.php similarity index 93% rename from forms/gridfield/GridFieldRelationDelete.php rename to forms/gridfield/GridFieldRemoveButton.php index ed81542bb..732836689 100644 --- a/forms/gridfield/GridFieldRelationDelete.php +++ b/forms/gridfield/GridFieldRemoveButton.php @@ -4,10 +4,10 @@ * Similar to {@link GridFieldDeleteAction}, but allows to distinguish between * a "delete" and "detach" action in the UI - and to use both in parallel, if required. * Requires the GridField to be populated with a {@link RelationList} rather than a plain {@link DataList}. - * Often used alongside {@link GridFieldRelationAdd} to add existing records to the relationship. + * Often used alongside {@link GridFieldAddExistingAutocompleter} to add existing records to the relationship. * For easier setup, have a look at a sample configuration in {@link GridFieldConfig_RelationEditor}. */ -class GridFieldRelationDelete implements GridField_ColumnProvider, GridField_ActionProvider { +class GridFieldRemoveButton implements GridField_ColumnProvider, GridField_ActionProvider { /** * Add a column 'UnlinkRelation' diff --git a/forms/gridfield/GridFieldTitle.php b/forms/gridfield/GridFieldToolbarHeader.php similarity index 93% rename from forms/gridfield/GridFieldTitle.php rename to forms/gridfield/GridFieldToolbarHeader.php index 31bceb52d..e8b140e28 100644 --- a/forms/gridfield/GridFieldTitle.php +++ b/forms/gridfield/GridFieldToolbarHeader.php @@ -14,7 +14,7 @@ * @package sapphire * @subpackage gridfield */ -class GridFieldTitle implements GridField_HTMLProvider { +class GridFieldToolbarHeader implements GridField_HTMLProvider { /** * @@ -34,7 +34,7 @@ class GridFieldTitle implements GridField_HTMLProvider { 'header' => $gridField->customise(array( 'NewLink' => Controller::join_links($gridField->Link('item'), 'new'), 'NewEnabled' => $this->getNewEnabled() - ))->renderWith('GridFieldTitle') + ))->renderWith('GridFieldToolbarHeader') ); } diff --git a/security/Group.php b/security/Group.php index 411c50aea..bd692d0ad 100755 --- a/security/Group.php +++ b/security/Group.php @@ -88,15 +88,15 @@ class Group extends DataObject { $parentidfield->setRightTitle('' . _t('Group.GroupReminder', 'If you choose a parent group, this group will take all it\'s roles') . ''); // Filter permissions - // TODO SecurityAdmin coupling, not easy to get to the form fields through GridFieldPopupForms + // TODO SecurityAdmin coupling, not easy to get to the form fields through GridFieldDetailForm $permissionsField->setHiddenPermissions(SecurityAdmin::$hidden_permissions); if($this->ID) { $config = new GridFieldConfig_RelationEditor(); - $config->addComponents(new GridFieldExporter()); - $config->getComponentByType('GridFieldRelationAdd') + $config->addComponents(new GridFieldExportButton()); + $config->getComponentByType('GridFieldAddExistingAutocompleter') ->setResultsFormat('$Title ($Email)')->setSearchFields(array('FirstName', 'Surname', 'Email')); - $config->getComponentByType('GridFieldPopupForms')->setValidator(new Member_Validator()); + $config->getComponentByType('GridFieldDetailForm')->setValidator(new Member_Validator()); $memberList = Object::create('GridField', 'Members',false, $this->Members(), $config)->addExtraClass('members_grid'); // @todo Implement permission checking on GridField //$memberList->setPermissions(array('edit', 'delete', 'export', 'add', 'inlineadd')); diff --git a/templates/GridFieldPopupForms.ss b/templates/GridFieldDetailForm.ss similarity index 100% rename from templates/GridFieldPopupForms.ss rename to templates/GridFieldDetailForm.ss diff --git a/templates/Includes/GridFieldRelationAdd.ss b/templates/Includes/GridFieldAddExistingAutocompleter.ss similarity index 100% rename from templates/Includes/GridFieldRelationAdd.ss rename to templates/Includes/GridFieldAddExistingAutocompleter.ss diff --git a/templates/Includes/GridFieldEditAction.ss b/templates/Includes/GridFieldEditButton.ss similarity index 100% rename from templates/Includes/GridFieldEditAction.ss rename to templates/Includes/GridFieldEditButton.ss diff --git a/templates/Includes/GridFieldFilter_Row.ss b/templates/Includes/GridFieldFilterHeader_Row.ss similarity index 100% rename from templates/Includes/GridFieldFilter_Row.ss rename to templates/Includes/GridFieldFilterHeader_Row.ss diff --git a/templates/Includes/GridFieldTitle.ss b/templates/Includes/GridFieldToolbarHeader.ss similarity index 100% rename from templates/Includes/GridFieldTitle.ss rename to templates/Includes/GridFieldToolbarHeader.ss diff --git a/tests/forms/GridFieldTest.php b/tests/forms/GridFieldTest.php index 5617bda17..ba3361f06 100644 --- a/tests/forms/GridFieldTest.php +++ b/tests/forms/GridFieldTest.php @@ -29,9 +29,9 @@ class GridFieldTest extends SapphireTest { $obj = new GridField('testfield', 'testfield'); $expectedComponents = new ArrayList(array( - new GridFieldTitle(), + new GridFieldToolbarHeader(), new GridFieldSortableHeader, - new GridFieldFilter, + new GridFieldFilterHeader, new GridFieldDefaultColumns, new GridFieldPaginator, new GridState_Component, diff --git a/tests/forms/gridfield/GridFieldRelationAddTest.php b/tests/forms/gridfield/GridFieldAddExistingAutocompleterTest.php similarity index 79% rename from tests/forms/gridfield/GridFieldRelationAddTest.php rename to tests/forms/gridfield/GridFieldAddExistingAutocompleterTest.php index 82d6fbc7e..102660271 100644 --- a/tests/forms/gridfield/GridFieldRelationAddTest.php +++ b/tests/forms/gridfield/GridFieldAddExistingAutocompleterTest.php @@ -1,5 +1,5 @@ objFromFixture('GridFieldTest_Team', 'team1'); $team2 = $this->objFromFixture('GridFieldTest_Team', 'team2'); - $response = $this->get('GridFieldRelationAddTest_Controller'); + $response = $this->get('GridFieldAddExistingAutocompleterTest_Controller'); $this->assertFalse($response->isError()); $parser = new CSSContentParser($response->getBody()); $btns = $parser->getBySelector('.ss-gridfield #action_gridfield_relationfind'); $response = $this->post( - 'GridFieldRelationAddTest_Controller/Form/field/testfield/search/Team 2', + 'GridFieldAddExistingAutocompleterTest_Controller/Form/field/testfield/search/Team 2', array( (string)$btns[0]['name'] => 1 ) @@ -26,7 +26,7 @@ class GridFieldRelationAddTest extends FunctionalTest { $this->assertEquals(array($team2->ID => 'Team 2'), $result); $response = $this->post( - 'GridFieldRelationAddTest_Controller/Form/field/testfield/search/Unknown', + 'GridFieldAddExistingAutocompleterTest_Controller/Form/field/testfield/search/Unknown', array( (string)$btns[0]['name'] => 1 ) @@ -41,7 +41,7 @@ class GridFieldRelationAddTest extends FunctionalTest { $team1 = $this->objFromFixture('GridFieldTest_Team', 'team1'); $team2 = $this->objFromFixture('GridFieldTest_Team', 'team2'); - $response = $this->get('GridFieldRelationAddTest_Controller'); + $response = $this->get('GridFieldAddExistingAutocompleterTest_Controller'); $this->assertFalse($response->isError()); $parser = new CSSContentParser($response->getBody()); $items = $parser->getBySelector('.ss-gridfield .ss-gridfield-items .ss-gridfield-item'); @@ -50,7 +50,7 @@ class GridFieldRelationAddTest extends FunctionalTest { $btns = $parser->getBySelector('.ss-gridfield #action_gridfield_relationadd'); $response = $this->post( - 'GridFieldRelationAddTest_Controller/Form/field/testfield', + 'GridFieldAddExistingAutocompleterTest_Controller/Form/field/testfield', array( 'relationID' => $team2->ID, (string)$btns[0]['name'] => 1 @@ -67,14 +67,14 @@ class GridFieldRelationAddTest extends FunctionalTest { } -class GridFieldRelationAddTest_Controller extends Controller implements TestOnly { +class GridFieldAddExistingAutocompleterTest_Controller extends Controller implements TestOnly { protected $template = 'BlankPage'; function Form() { $player = DataObject::get('GridFieldTest_Player')->find('Email', 'player1@test.com'); $config = GridFieldConfig::create()->addComponents( - $relationComponent = new GridFieldRelationAdd('Name'), + $relationComponent = new GridFieldAddExistingAutocompleter('Name'), new GridFieldDefaultColumns() ); $field = new GridField('testfield', 'testfield', $player->Teams(), $config); diff --git a/tests/forms/gridfield/GridFieldPopupFormsTest.php b/tests/forms/gridfield/GridFieldDetailFormTest.php similarity index 72% rename from tests/forms/gridfield/GridFieldPopupFormsTest.php rename to tests/forms/gridfield/GridFieldDetailFormTest.php index c603f24a4..0fdfbcbe5 100644 --- a/tests/forms/gridfield/GridFieldPopupFormsTest.php +++ b/tests/forms/gridfield/GridFieldDetailFormTest.php @@ -1,22 +1,22 @@ logInWithPermission('ADMIN'); - $group = DataList::create('GridFieldPopupFormsTest_PeopleGroup') + $group = DataList::create('GridFieldDetailFormTest_PeopleGroup') ->filter('Name', 'My Group') ->First(); $count = $group->People()->Count(); - $response = $this->get('GridFieldPopupFormsTest_Controller'); + $response = $this->get('GridFieldDetailFormTest_Controller'); $this->assertFalse($response->isError()); $parser = new CSSContentParser($response->getBody()); $addlinkitem = $parser->getBySelector('.ss-gridfield .new-link'); @@ -39,7 +39,7 @@ class GridFieldPopupFormsTest extends FunctionalTest { ); $this->assertFalse($response->isError()); - $group = DataList::create('GridFieldPopupFormsTest_PeopleGroup') + $group = DataList::create('GridFieldDetailFormTest_PeopleGroup') ->filter('Name', 'My Group') ->First(); $this->assertEquals($count + 1, $group->People()->Count()); @@ -47,13 +47,13 @@ class GridFieldPopupFormsTest extends FunctionalTest { function testEditForm() { $this->logInWithPermission('ADMIN'); - $group = DataList::create('GridFieldPopupFormsTest_PeopleGroup') + $group = DataList::create('GridFieldDetailFormTest_PeopleGroup') ->filter('Name', 'My Group') ->First(); $firstperson = $group->People()->First(); $this->assertTrue($firstperson->Surname != 'Baggins'); - $response = $this->get('GridFieldPopupFormsTest_Controller'); + $response = $this->get('GridFieldDetailFormTest_Controller'); $this->assertFalse($response->isError()); $parser = new CSSContentParser($response->getBody()); $editlinkitem = $parser->getBySelector('.ss-gridfield-items .first .edit-link'); @@ -76,7 +76,7 @@ class GridFieldPopupFormsTest extends FunctionalTest { ); $this->assertFalse($response->isError()); - $group = DataList::create('GridFieldPopupFormsTest_PeopleGroup') + $group = DataList::create('GridFieldDetailFormTest_PeopleGroup') ->filter('Name', 'My Group') ->First(); $firstperson = $group->People()->First(); @@ -84,38 +84,38 @@ class GridFieldPopupFormsTest extends FunctionalTest { } } -class GridFieldPopupFormsTest_Person extends DataObject implements TestOnly { +class GridFieldDetailFormTest_Person extends DataObject implements TestOnly { static $db = array( 'FirstName' => 'Varchar', 'Surname' => 'Varchar' ); static $has_one = array( - 'Group' => 'GridFieldPopupFormsTest_PeopleGroup' + 'Group' => 'GridFieldDetailFormTest_PeopleGroup' ); } -class GridFieldPopupFormsTest_PeopleGroup extends DataObject implements TestOnly { +class GridFieldDetailFormTest_PeopleGroup extends DataObject implements TestOnly { static $db = array( 'Name' => 'Varchar' ); static $has_many = array( - 'People' => 'GridFieldPopupFormsTest_Person' + 'People' => 'GridFieldDetailFormTest_Person' ); } -class GridFieldPopupFormsTest_Controller extends Controller implements TestOnly { +class GridFieldDetailFormTest_Controller extends Controller implements TestOnly { protected $template = 'BlankPage'; function Form() { - $group = DataList::create('GridFieldPopupFormsTest_PeopleGroup') + $group = DataList::create('GridFieldDetailFormTest_PeopleGroup') ->filter('Name', 'My Group') ->First(); $field = new GridField('testfield', 'testfield', $group->People()); - $field->getConfig()->addComponent($gridFieldForm = new GridFieldPopupForms($this, 'Form')); - $field->getConfig()->addComponent(new GridFieldEditAction()); + $field->getConfig()->addComponent($gridFieldForm = new GridFieldDetailForm($this, 'Form')); + $field->getConfig()->addComponent(new GridFieldEditButton()); return new Form($this, 'Form', new FieldList($field), new FieldList()); } } diff --git a/tests/forms/gridfield/GridFieldDetailFormTest.yml b/tests/forms/gridfield/GridFieldDetailFormTest.yml new file mode 100644 index 000000000..163418bd1 --- /dev/null +++ b/tests/forms/gridfield/GridFieldDetailFormTest.yml @@ -0,0 +1,12 @@ +GridFieldDetailFormTest_Person: + joe: + FirstName: Joe + Surname: Bloggs + jane: + FirstName: Jane + Surname: Doe + +GridFieldDetailFormTest_PeopleGroup: + group: + Name: My Group + People: =>GridFieldDetailFormTest_Person.joe,=>GridFieldDetailFormTest_Person.jane diff --git a/tests/forms/gridfield/GridFieldEditActionTest.php b/tests/forms/gridfield/GridFieldEditButtonTest.php similarity index 96% rename from tests/forms/gridfield/GridFieldEditActionTest.php rename to tests/forms/gridfield/GridFieldEditButtonTest.php index 07ef784b4..13b3b045b 100644 --- a/tests/forms/gridfield/GridFieldEditActionTest.php +++ b/tests/forms/gridfield/GridFieldEditButtonTest.php @@ -1,6 +1,6 @@ list = new DataList('GridFieldAction_Edit_Team'); - $config = GridFieldConfig::create()->addComponent(new GridFieldEditAction()); + $config = GridFieldConfig::create()->addComponent(new GridFieldEditButton()); $this->gridField = new GridField('testfield', 'testfield', $this->list, $config); $this->form = new Form(new Controller(), 'mockform', new FieldList(array($this->gridField)), new FieldList()); } diff --git a/tests/forms/gridfield/GridFieldPopupFormsTest.yml b/tests/forms/gridfield/GridFieldPopupFormsTest.yml deleted file mode 100644 index 9090d706b..000000000 --- a/tests/forms/gridfield/GridFieldPopupFormsTest.yml +++ /dev/null @@ -1,12 +0,0 @@ -GridFieldPopupFormsTest_Person: - joe: - FirstName: Joe - Surname: Bloggs - jane: - FirstName: Jane - Surname: Doe - -GridFieldPopupFormsTest_PeopleGroup: - group: - Name: My Group - People: =>GridFieldPopupFormsTest_Person.joe,=>GridFieldPopupFormsTest_Person.jane diff --git a/tests/forms/gridfield/GridFieldTitleTest.php b/tests/forms/gridfield/GridFieldToolbarHeaderTest.php similarity index 87% rename from tests/forms/gridfield/GridFieldTitleTest.php rename to tests/forms/gridfield/GridFieldToolbarHeaderTest.php index 11ab670d2..2f67df433 100644 --- a/tests/forms/gridfield/GridFieldTitleTest.php +++ b/tests/forms/gridfield/GridFieldToolbarHeaderTest.php @@ -1,12 +1,12 @@ logInWithPermission('ADMIN'); //construct a fake form field to render out the grid field within it $config = new GridFieldConfig(); - $config->addComponent($titleField = new GridFieldTitle()); + $config->addComponent($titleField = new GridFieldToolbarHeader()); $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))); @@ -21,7 +21,7 @@ class GridFieldTitleTest extends SapphireTest { $this->logInWithPermission('ADMIN'); //construct a fake form field to render out the grid field within it $config = new GridFieldConfig(); - $config->addComponent($titleField = new GridFieldTitle()); + $config->addComponent($titleField = new GridFieldToolbarHeader()); $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))); @@ -35,7 +35,7 @@ class GridFieldTitleTest extends SapphireTest { public function testGridTitleAddNewWithoutPermission() { if(Member::currentUser()) { Member::currentUser()->logOut(); } $config = new GridFieldConfig(); - $config->addComponent($titleField = new GridFieldTitle()); + $config->addComponent($titleField = new GridFieldToolbarHeader()); $grid = new GridField('TestField', 'Test Field', new DataList('Company'),$config); $fields = new FieldList(new TabSet("Root",$tabMain = new Tab('Main',$grid))); $form = new Form(Controller::curr(), "TestForm", $fields, new FieldList()); From 6d0b0d678838d793a179af0281f6e00ece57418c Mon Sep 17 00:00:00 2001 From: Stig Lindqvist Date: Fri, 9 Mar 2012 13:55:49 +1300 Subject: [PATCH 2/4] API CHANGE Removing GridFieldDeleteAction and moved functionality into GridFieldRemoveButton #6921 --- forms/gridfield/GridFieldConfig.php | 2 +- forms/gridfield/GridFieldDeleteAction.php | 61 ++++++---- forms/gridfield/GridFieldRemoveButton.php | 106 ------------------ .../gridfield/GridFieldDeleteActionTest.php | 17 +++ 4 files changed, 58 insertions(+), 128 deletions(-) delete mode 100644 forms/gridfield/GridFieldRemoveButton.php diff --git a/forms/gridfield/GridFieldConfig.php b/forms/gridfield/GridFieldConfig.php index 5cb804989..0cc589a0a 100755 --- a/forms/gridfield/GridFieldConfig.php +++ b/forms/gridfield/GridFieldConfig.php @@ -206,7 +206,7 @@ class GridFieldConfig_RelationEditor extends GridFieldConfig { $this->addComponent(new GridFieldFilterHeader()); $this->addComponent(new GridFieldDefaultColumns()); $this->addComponent(new GridFieldEditButton()); - $this->addComponent(new GridFieldRemoveButton()); + $this->addComponent(new GridFieldDeleteAction(true)); $this->addComponent(new GridFieldPaginator($itemsPerPage)); $this->addComponent(new GridFieldDetailForm()); } diff --git a/forms/gridfield/GridFieldDeleteAction.php b/forms/gridfield/GridFieldDeleteAction.php index 7aa505d49..2685fcfe2 100644 --- a/forms/gridfield/GridFieldDeleteAction.php +++ b/forms/gridfield/GridFieldDeleteAction.php @@ -5,6 +5,24 @@ */ class GridFieldDeleteAction implements GridField_ColumnProvider, GridField_ActionProvider { + + /** + * If this is set to true, this actionprovider will remove the object from the list, instead of + * deleting. In the case of a has one, has many or many many list it will uncouple the item from + * the list. + * + * @var boolean + */ + protected $removeRelation = false; + + /** + * + * @param boolean $unlinkRelation - true if removing the item from the list, but not deleting it + */ + public function __construct($unlinkRelation = false) { + $this->removeRelation = $unlinkRelation; + } + /** * Add a column 'Delete' * @@ -58,7 +76,7 @@ class GridFieldDeleteAction implements GridField_ColumnProvider, GridField_Actio * @return array */ public function getActions($gridField) { - return array('deleterecord'); + return array('deleterecord', 'unlinkrelation'); } /** @@ -69,19 +87,20 @@ class GridFieldDeleteAction implements GridField_ColumnProvider, GridField_Actio * @return string - the HTML for the column */ public function getColumnContent($gridField, $record, $columnName) { - if(!$record->canDelete()) { - return; + if($this->removeRelation) { + $field = Object::create('GridField_FormAction', $gridField, 'UnlinkRelation'.$record->ID, false, "unlinkrelation", array('RecordID' => $record->ID)) + ->addExtraClass('gridfield-button-unlink') + ->setAttribute('title', _t('GridAction.UnlinkRelation', "Unlink")) + ->setAttribute('data-icon', 'chain--minus'); + } else { + if(!$record->canDelete()) { + return; + } + $field = Object::create('GridField_FormAction', $gridField, 'DeleteRecord'.$record->ID, false, "deleterecord", array('RecordID' => $record->ID)) + ->addExtraClass('gridfield-button-delete') + ->setAttribute('title', _t('GridAction.Delete', "Delete")) + ->setAttribute('data-icon', 'decline'); } - $field = Object::create('GridField_FormAction', - $gridField, - 'DeleteRecord'.$record->ID, - false, - "deleterecord", - array('RecordID' => $record->ID) - ) - ->addExtraClass('gridfield-button-delete') - ->setAttribute('title', _t('GridAction.Delete', "delete")) - ->setAttribute('data-icon', 'decline'); return $field->Field(); } @@ -95,15 +114,15 @@ class GridFieldDeleteAction implements GridField_ColumnProvider, GridField_Actio * @return void */ public function handleAction(GridField $gridField, $actionName, $arguments, $data) { - if($actionName == 'deleterecord') { - $id = $arguments['RecordID']; - // Always deletes a record. Use GridFieldRemoveButton to detach it from the current relationship. - $item = $gridField->getList()->byID($id); - if(!$item->canDelete()) { + if($actionName == 'deleterecord' || $actionName == 'unlinkrelation') { + $item = $gridField->getList()->byID($arguments['RecordID']); + if(!$item) { + return; + } + if($actionName == 'deleterecord' && !$item->canDelete()) { throw new ValidationException(_t('GridFieldAction_Delete.DeletePermissionsFailure',"No delete permissions"),0); } - if(!$item) return; - $item->delete(); - } + $gridField->getList()->remove($item); + } } } \ No newline at end of file diff --git a/forms/gridfield/GridFieldRemoveButton.php b/forms/gridfield/GridFieldRemoveButton.php deleted file mode 100644 index 732836689..000000000 --- a/forms/gridfield/GridFieldRemoveButton.php +++ /dev/null @@ -1,106 +0,0 @@ - ''); - } - } - - /** - * Which columns are handled by this component - * - * @param type $gridField - * @return type - */ - public function getColumnsHandled($gridField) { - return array('Actions'); - } - - /** - * Which GridField actions are this component handling - * - * @param GridField $gridField - * @return array - */ - public function getActions($gridField) { - return array('unlinkrelation'); - } - - /** - * - * @param GridField $gridField - * @param DataObject $record - * @param string $columnName - * @return string - the HTML for the column - */ - public function getColumnContent($gridField, $record, $columnName) { - $field = Object::create('GridField_FormAction', - $gridField, - 'UnlinkRelation'.$record->ID, - false, - "unlinkrelation", - array('RecordID' => $record->ID) - ) - ->setAttribute('title', _t('GridAction.UnlinkRelation', "Unlink")) - ->setAttribute('data-icon', 'chain--minus') - ->addExtraClass('gridfield-button-unlink'); - return $field->Field(); - } - - /** - * Handle the actions and apply any changes to the GridField - * - * @param GridField $gridField - * @param string $actionName - * @param mixed $arguments - * @param array $data - form data - * @return void - */ - public function handleAction(GridField $gridField, $actionName, $arguments, $data) { - $id = $arguments['RecordID']; - $item = $gridField->getList()->byID($id); - if(!$item) return; - if($actionName == 'unlinkrelation') { - $gridField->getList()->remove($item); - } - } -} diff --git a/tests/forms/gridfield/GridFieldDeleteActionTest.php b/tests/forms/gridfield/GridFieldDeleteActionTest.php index 750123207..3c09d7b6a 100644 --- a/tests/forms/gridfield/GridFieldDeleteActionTest.php +++ b/tests/forms/gridfield/GridFieldDeleteActionTest.php @@ -60,6 +60,23 @@ class GridFieldDeleteActionTest extends SapphireTest { $this->gridField->gridFieldAlterAction(array('StateID'=>$stateID), $this->form, $request); $this->assertEquals(2, $this->list->count(), 'User should be able to delete records with ADMIN permission.'); } + + public function testDeleteActionRemoveRelation() { + $this->logInWithPermission('ADMIN'); + + $config = GridFieldConfig::create()->addComponent(new GridFieldDeleteAction(true)); + + $gridField = new GridField('testfield', 'testfield', $this->list, $config); + $form = new Form(new Controller(), 'mockform', new FieldList(array($this->gridField)), new FieldList()); + + $stateID = 'testGridStateActionField'; + Session::set($stateID, array('grid'=>'', 'actionName'=>'deleterecord','args'=>array('RecordID'=>1))); + $request = new SS_HTTPRequest('POST', 'url', array(), array('action_gridFieldAlterAction?StateID='.$stateID=>true)); + + $this->gridField->gridFieldAlterAction(array('StateID'=>$stateID), $this->form, $request); + $this->assertEquals(2, $this->list->count(), 'User should be able to delete records with ADMIN permission.'); + + } } class GridFieldAction_Delete_Team extends DataObject implements TestOnly { From 09d6fa7bb3915d6caa8426c494e73d499ca08287 Mon Sep 17 00:00:00 2001 From: Stig Lindqvist Date: Fri, 9 Mar 2012 14:07:40 +1300 Subject: [PATCH 3/4] API CHANGE Renamed GridFieldDefaultColumns to GridFieldDataColumns #6921 --- docs/en/topics/grid-field.md | 10 +++++----- forms/HtmlEditorField.php | 2 +- forms/UploadField.php | 2 +- forms/gridfield/GridField.php | 2 +- forms/gridfield/GridFieldComponent.php | 2 +- forms/gridfield/GridFieldConfig.php | 6 +++--- ...ieldDefaultColumns.php => GridFieldDataColumns.php} | 2 +- tests/forms/GridFieldTest.php | 8 ++++---- .../GridFieldAddExistingAutocompleterTest.php | 2 +- 9 files changed, 18 insertions(+), 18 deletions(-) rename forms/gridfield/{GridFieldDefaultColumns.php => GridFieldDataColumns.php} (97%) diff --git a/docs/en/topics/grid-field.md b/docs/en/topics/grid-field.md index eab4eb7dc..a74939be7 100644 --- a/docs/en/topics/grid-field.md +++ b/docs/en/topics/grid-field.md @@ -32,7 +32,7 @@ This example creates exactly the same kind of grid as the previous example, but // Provide a header row with filter controls $config->addComponent(new GridFieldFilterHeader()); // Provide a default set of columns based on $summary_fields - $config->addComponent(new GridFieldDefaultColumns()); + $config->addComponent(new GridFieldDataColumns()); // Provide a header row with sort controls $config->addComponent(new GridFieldSortableHeader()); // Paginate results to 25 items per page, and show a footer with pagination controls @@ -44,7 +44,7 @@ If we wanted to make a simpler grid without pagination or filtering, we could do :::php $config = GridFieldConfig::create(); // Provide a default set of columns based on $summary_fields - $config->addComponent(new GridFieldDefaultColumns()); + $config->addComponent(new GridFieldDataColumns()); // Provide a header row with sort controls $config->addComponent(new GridFieldPaginator(25)); $field = new GridField("Members", "Members of this group", $this->group->Members(), $config); @@ -57,11 +57,11 @@ A `GridFieldConfig` is made up of a new of `GridFieldComponent` objects, which a `GridFieldComponent` is a family of interfaces. SilverStripe Framework comes with the following components that you can use out of the box. -### GridFieldDefaultColumns +### GridFieldDataColumns This is the one component that, in most cases, you must include. It provides the default columns, sourcing them from the underlying DataObject's `$summary_fields` if no specific configuration is provided. -Without GridFieldDefaultColumns added to a GridField, it would have no columns whatsoever. Although this isn't particularly useful most of the time, we have allowed for this for two reasons: +Without GridFieldDataColumns added to a GridField, it would have no columns whatsoever. Although this isn't particularly useful most of the time, we have allowed for this for two reasons: * You may have a grid whose fields are generated purely by another non-standard component. * It keeps the core of the GridField lean, focused solely on providing APIs to the components. @@ -233,7 +233,7 @@ By default, a grid contains no columns. All the columns displayed in a grid wil For example, you may create a grid field with several components providing columns: - * `GridFieldDefaultColumns` could provide basic data columns. + * `GridFieldDataColumns` could provide basic data columns. * An editor component could provide a column containing action buttons on the right. * A multiselect component clould provide a column showing a checkbox on the left. diff --git a/forms/HtmlEditorField.php b/forms/HtmlEditorField.php index 54c0a57dc..a18f8ebb6 100644 --- a/forms/HtmlEditorField.php +++ b/forms/HtmlEditorField.php @@ -356,7 +356,7 @@ class HtmlEditorField_Toolbar extends RequestHandler { $fileFieldConfig = GridFieldConfig::create(); $fileFieldConfig->addComponent(new GridFieldSortableHeader()); $fileFieldConfig->addComponent(new GridFieldFilterHeader()); - $fileFieldConfig->addComponent(new GridFieldDefaultColumns()); + $fileFieldConfig->addComponent(new GridFieldDataColumns()); $fileFieldConfig->addComponent(new GridFieldPaginator(5)); $fileField = new GridField('Files', false, null, $fileFieldConfig); $fileField->setList($this->getFiles($parentID)); diff --git a/forms/UploadField.php b/forms/UploadField.php index 6a74dabb5..80249b083 100644 --- a/forms/UploadField.php +++ b/forms/UploadField.php @@ -847,7 +847,7 @@ class UploadField_SelectHandler extends RequestHandler { $config = GridFieldConfig::create(); $config->addComponent(new GridFieldSortableHeader()); $config->addComponent(new GridFieldFilterHeader()); - $config->addComponent(new GridFieldDefaultColumns()); + $config->addComponent(new GridFieldDataColumns()); $config->addComponent(new GridFieldPaginator(10)); $field = new GridField('Files', false, $folder->stageChildren(), $config); diff --git a/forms/gridfield/GridField.php b/forms/gridfield/GridField.php index f58e37108..ac1fbbd39 100755 --- a/forms/gridfield/GridField.php +++ b/forms/gridfield/GridField.php @@ -404,7 +404,7 @@ class GridField extends FormField { array( "class" => implode(' ', $classes), 'data-id' => $record->ID, - // TODO Allow per-row customization similar to GridFieldDefaultColumns + // TODO Allow per-row customization similar to GridFieldDataColumns 'data-class' => $record->ClassName, ), $rowContent diff --git a/forms/gridfield/GridFieldComponent.php b/forms/gridfield/GridFieldComponent.php index 988ed1083..cf6c58bdd 100644 --- a/forms/gridfield/GridFieldComponent.php +++ b/forms/gridfield/GridFieldComponent.php @@ -36,7 +36,7 @@ interface GridField_ColumnProvider extends GridFieldComponent { /** * Modify the list of columns displayed in the table. - * See {@link GridField->getDisplayFields()} and {@link GridFieldDefaultColumns}. + * See {@link GridField->getDisplayFields()} and {@link GridFieldDataColumns}. * * @param GridField * @param Array List reference of all column names. diff --git a/forms/gridfield/GridFieldConfig.php b/forms/gridfield/GridFieldConfig.php index 0cc589a0a..76ad37a6b 100755 --- a/forms/gridfield/GridFieldConfig.php +++ b/forms/gridfield/GridFieldConfig.php @@ -134,7 +134,7 @@ class GridFieldConfig_Base extends GridFieldConfig { $this->addComponent(new GridFieldToolbarHeader()); $this->addComponent(new GridFieldSortableHeader()); $this->addComponent(new GridFieldFilterHeader()); - $this->addComponent(new GridFieldDefaultColumns()); + $this->addComponent(new GridFieldDataColumns()); $this->addComponent(new GridFieldPaginator($itemsPerPage)); } } @@ -161,7 +161,7 @@ class GridFieldConfig_RecordEditor extends GridFieldConfig { $this->addComponent(new GridFieldToolbarHeader()); $this->addComponent(new GridFieldSortableHeader()); $this->addComponent(new GridFieldFilterHeader()); - $this->addComponent(new GridFieldDefaultColumns()); + $this->addComponent(new GridFieldDataColumns()); $this->addComponent(new GridFieldEditButton()); $this->addComponent(new GridFieldDeleteAction()); $this->addComponent(new GridFieldPaginator($itemsPerPage)); @@ -204,7 +204,7 @@ class GridFieldConfig_RelationEditor extends GridFieldConfig { $this->addComponent(new GridFieldAddExistingAutocompleter()); $this->addComponent(new GridFieldSortableHeader()); $this->addComponent(new GridFieldFilterHeader()); - $this->addComponent(new GridFieldDefaultColumns()); + $this->addComponent(new GridFieldDataColumns()); $this->addComponent(new GridFieldEditButton()); $this->addComponent(new GridFieldDeleteAction(true)); $this->addComponent(new GridFieldPaginator($itemsPerPage)); diff --git a/forms/gridfield/GridFieldDefaultColumns.php b/forms/gridfield/GridFieldDataColumns.php similarity index 97% rename from forms/gridfield/GridFieldDefaultColumns.php rename to forms/gridfield/GridFieldDataColumns.php index 1c058a615..1d2c88cdd 100644 --- a/forms/gridfield/GridFieldDefaultColumns.php +++ b/forms/gridfield/GridFieldDataColumns.php @@ -6,7 +6,7 @@ * @package sapphire * @subpackage fields-relational */ -class GridFieldDefaultColumns implements GridField_ColumnProvider { +class GridFieldDataColumns implements GridField_ColumnProvider { public function augmentColumns($gridField, &$columns) { $baseColumns = array_keys($gridField->getDisplayFields()); diff --git a/tests/forms/GridFieldTest.php b/tests/forms/GridFieldTest.php index ba3361f06..8012554d6 100644 --- a/tests/forms/GridFieldTest.php +++ b/tests/forms/GridFieldTest.php @@ -32,7 +32,7 @@ class GridFieldTest extends SapphireTest { new GridFieldToolbarHeader(), new GridFieldSortableHeader, new GridFieldFilterHeader, - new GridFieldDefaultColumns, + new GridFieldDataColumns, new GridFieldPaginator, new GridState_Component, )); @@ -48,13 +48,13 @@ class GridFieldTest extends SapphireTest { $config = GridFieldConfig::create(); $config->addComponent(new GridFieldSortableHeader()); - $config->addComponent(new GridFieldDefaultColumns()); + $config->addComponent(new GridFieldDataColumns()); $obj = new GridField('testfield', 'testfield', ArrayList::create(array()),$config); $expectedComponents = new ArrayList(array( 0 => new GridFieldSortableHeader, - 1 => new GridFieldDefaultColumns, + 1 => new GridFieldDataColumns, 2 => new GridState_Component, )); @@ -430,7 +430,7 @@ class GridFieldTest extends SapphireTest { )); $config = new GridFieldConfig(); - $config->addComponent(new GridFieldDefaultColumns()); + $config->addComponent(new GridFieldDataColumns()); $obj = new GridField('testfield', 'testfield', $list, $config); $form = new Form(new Controller(), 'mockform', new FieldList(array($obj)), new FieldList()); $content = new CSSContentParser($obj->FieldHolder()); diff --git a/tests/forms/gridfield/GridFieldAddExistingAutocompleterTest.php b/tests/forms/gridfield/GridFieldAddExistingAutocompleterTest.php index 102660271..76d91b63e 100644 --- a/tests/forms/gridfield/GridFieldAddExistingAutocompleterTest.php +++ b/tests/forms/gridfield/GridFieldAddExistingAutocompleterTest.php @@ -75,7 +75,7 @@ class GridFieldAddExistingAutocompleterTest_Controller extends Controller implem $player = DataObject::get('GridFieldTest_Player')->find('Email', 'player1@test.com'); $config = GridFieldConfig::create()->addComponents( $relationComponent = new GridFieldAddExistingAutocompleter('Name'), - new GridFieldDefaultColumns() + new GridFieldDataColumns() ); $field = new GridField('testfield', 'testfield', $player->Teams(), $config); return new Form($this, 'Form', new FieldList($field), new FieldList()); From 627708e3a827e2ad0741131e70b376535a977e61 Mon Sep 17 00:00:00 2001 From: Mark Stephens Date: Fri, 9 Mar 2012 14:15:34 +1300 Subject: [PATCH 4/4] BUGFIX: add Director::isDev parameter so we can test if we know we're dev mode already without touching the database. Used in showqueries on MySQL, so that errors are avoided when showing queries on initial switch to dev move (#6856) --- control/Director.php | 29 ++++++++++++++++------------- model/MySQLDatabase.php | 4 ++-- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/control/Director.php b/control/Director.php index 403b01bc1..5d00b4c45 100644 --- a/control/Director.php +++ b/control/Director.php @@ -802,19 +802,31 @@ class Director implements TemplateGlobalProvider { /** * This function will return true if the site is in a development environment. * For information about environment types, see {@link Director::set_environment_type()}. + * @param $dontTouchDB If true, the database checks are not performed, which allows certain DB checks + * to not fail before the DB is ready. If false (default), DB checks are included. */ - static function isDev() { + static function isDev($dontTouchDB = false) { // This variable is used to supress repetitions of the isDev security message below. static $firstTimeCheckingGetVar = true; + + $result = false; + + if(isset($_SESSION['isDev']) && $_SESSION['isDev']) $result = true; + if(self::$environment_type && self::$environment_type == 'dev') $result = true; + + if(!empty(Director::$dev_servers)) { + Deprecation::notice('3.0', 'Director::$dev_servers doesn\'t work anymore'); + } // Use ?isDev=1 to get development access on the live server - if(isset($_GET['isDev'])) { + if(!$dontTouchDB && !$result && isset($_GET['isDev'])) { if(Security::database_is_ready()) { if($firstTimeCheckingGetVar && !Permission::check('ADMIN')){ BasicAuth::requireLogin("SilverStripe developer access. Use your CMS login", "ADMIN"); } $_SESSION['isDev'] = $_GET['isDev']; - if($firstTimeCheckingGetVar) $firstTimeCheckingGetVar = false; + $firstTimeCheckingGetVar = false; + $result = $_GET['isDev']; } else { if($firstTimeCheckingGetVar && DB::connection_attempted()) { echo "

dbConn->query($sql); - if(isset($_REQUEST['showqueries'])) { + if(isset($_REQUEST['showqueries']) && Director::isDev(true)) { $endtime = round(microtime(true) - $starttime,4); Debug::message("\n$sql\n{$endtime}ms\n", false); }