Hi Guys,
I'm constructing a news article module for my client making use of DataGrid's to house data. Now obviously when you select to add a new record to the DataGrid, in this case a new article, I want to be able to ensure that the fields needed are completed so no blank news articles are posted, or so no articles are posted that don't belong to a category.
Here's my code for the extension of the dataobject..
<?php
/****************************************************************
* *
* ESTABLISH PARAMETERS FOR EACH NEWS ARTICLE *
* *
*****************************************************************/
class NewsArticle extends DataObject {
public static $db = array(
'SortOrder' => 'Int',
'Title' => 'Varchar',
'Category' => 'Int',
'Content' => 'HTMLText'
);
//One-to-one relationship with news page
public static $has_one = array('News' => 'News');
//Tidy up CMS by removing the fields we don't want users to modify.
public function getCMSFields() {
$fields = parent::getCMSFields();
//Remove Title field and readd it with a new title
$fields->removeFieldFromTab("Root.Main","Title");
$fields->addFieldToTab("Root.Main", new TextField("Title", "Article Name"), "Content");
//Add dropdown with category options
$dropdown = new DropdownField('Category','Article Category',Dataobject::get("NewsCategory")->map("ID", "Title"));
$dropdown->setEmptyString("(Select One)");
$fields->addFieldToTab("Root.Main", $dropdown, "Content");
//Remove fields that will confuse people
$fields->removeFieldFromTab("Root.Main","NewsID");
$fields->removeFieldFromTab("Root.Main","SortOrder");
return $fields;
}
//Set Required Fields
public function getCMSValidator() {
return new RequiredFields('Title');
}
// Tell the datagrid what fields to show in the table
public static $summary_fields = array('ID', 'Title');
}
Now obviously, i've set getCMSValidator() to check the fields, as would work on an extension of Page and the SiteTree, but it does not work.
Is there something obvious i'm missing here, i've trawled the web for hours to find the answer and its doing my head in.. Sorry if this is in the wrong section I'm new on here and couldn't quite guess which one to put it under.
George.