This is strange. I may be doing something wrong. I created an Article DataObject that I am managing under a Category page with a DOM. I wanted to allow the users to manage the articles via ModelAdmin too. When I try do a search in ModelAdmin, no search results appear (even if I don't enter anything in the search form).
Please help :)
Article.php
<?php
class Article extends DataObject {
static $db = array(
'Title' =>'Varchar(255)',
'Subtitle' => 'Varchar(255)',
'Summary' => 'Text',
'Credits'=>'Text',
'URLSegment'=>'Varchar(255)',
"MetaTitle" => "Varchar(255)",
"MetaDescription" => "Text",
"MetaKeywords" => "Varchar(255)",
"Published" => 'Boolean',
"ToDo" => "Text"
);
function fieldLabels() {
...
}
static $has_one = array(
'Category' => 'Category',
'Author'=>'Member'
);
static $has_many = array(
'Pages' => 'ArticlePage',
'Images' => 'ArticleImage'
);
static $casting = array(
"LastEdited" => "SS_Datetime",
"Created" => "SS_Datetime"
);
static $defaults = array(
'Title'=>'New article',
'URLSegment'=>'new-article'
);
static $can_create = true;
static $summary_fields = array(
'CategoryID',
'Title',
'AuthorID',
'Subtitle',
'URLSegment',
'Created',
'LastEdited'
);
static $searchable_fields = array(
'CategoryID',
'Title',
'Subtitle',
'Summary',
'AuthorID',
'Credits',
'Created',
'LastEdited',
'Summary'
);
static $indexes = array (
'URLSegment' => true
);
//*********CMS FIELDS
public function getCMSFields()
{
$pageManager = new DataObjectManager(
$this, // Controller
'Pages', // Source name
'ArticlePage', // Source class
array(
'PageSubtitle' => 'Subtitle',
'CharCount' => 'Length of text (chars)',
'ShortContent' => 'Text'
), // Headings
'getCMSFields', // Detail fields (function name or FieldSet object)
'', // Filter clause
'' // Sort clause
// Join clause
);
$pageManager->setAddTitle(_t("Article.ADDPAGE","page"));
$pageManager->setColumnWidths(array(
'PageSubtitle' => 40,
'CharCount' => 20,
'ShortContent' => 40
));
$photoManager = new ImageDataObjectManager(
$this, // Controller
'Images', // Source name
'ArticleImage', // Source class
'File', // File name on DataObject
array(
'Caption' => 'Caption'
), // Headings
'getCMSFields'
);
$photoManager->setUploadFolder("gallery");
$photoManager->setAddTitle(_t("Article.ADDPHOTO","photo"));
$authorField = new DropdownField(
'AuthorID',
_t("Article.PICKAUTHOR","Pick author"),
array(''=>_t("Article.SELECT","Select one")) + Dataobject::get("Member", "ID")->toDropdownMap()
);
$categoryField = new DropdownField(
'CategoryID',
_t("Article.PICKCATEGORY","Pick category"),
array(''=>_t("Article.SELECT","Select one")) + Dataobject::get("Category", "ID", "Title")->toDropdownMap()
);
if($this->ID) {
$extraFields = new TabSet ("Root",
$contentTab = new Tab(_t("Article.TABCONTENT", "Content"),
$categoryField,
$authorField,
new TextField("Credits", $this->fieldLabel('Credits')),
new TextField("Title", $this->fieldLabel('Title')),
new TextField("Subtitle", $this->fieldLabel('Subtitle')),
new TextareaField("Summary", $this->fieldLabel('Summary'))
),
$pageTab = new Tab(_t("Article.TABPAGES","Strani"),
$pageManager
),
$metaTab = new Tab("Meta",
new TextField("URLSegment", $this->fieldLabel('URLSegment')),
new TextField("MetaTitle", $this->fieldLabel('MetaTitle')),
new TextareaField("MetaKeywords", $this->fieldLabel('MetaKeywords'), 1),
new TextareaField("MetaDescription", $this->fieldLabel('MetaDescription'))
),
$photoTab = new Tab(_t('Article.TABPHOTO', 'Slike'),
$photoManager
),
$tabPublish = new Tab(_t('Article.TABPUBLISH', 'Objava'),
new DatetimeField_Readonly("Created",$this->fieldLabel('Created')),
new DatetimeField_Readonly("LastEdited",$this->fieldLabel('LastEdited')),
new CheckboxField("Published",$this->fieldLabel('Published'))
),
$tabToDo = new Tab(_t('Article.TABTODO', 'Opomniki'),
//new LiteralField("ToDoHelp","Tekst To-Do"),
new TextareaField("ToDo", "", 10)
)
);
} else {
$extraFields = new TabSet ("Root",
$contentTab = new Tab(_t("Article.TABCONTENT", "Vsebina"),
new TextField("Title", _t('Article.TITLE',"Naslov članka")),
new TextField("Subtitle", _t('Article.SUBTITLE',"Podnaslov članka")),
$authorField,
new TextField("Credits", _t('Article.CREDITS',"Ostali soavtorji")),
new TextareaField("Summary", _t('Article.SUMMARY',"Povzetek članka"))
)
);
}
$f = new FieldSet(
$extraFields
);
return $f;
}
function onBeforeWrite() {
if((!$this->URLSegment || $this->URLSegment=='nov-clanek') && $this->Title !='Nov članek') {
$this->URLSegment = SiteTree::generateURLSegment($this->Title);
}
else if ($this->isChanged('URLSegment')) {
$segment = preg_replace('/[^A-Za-z0-9]+/','-',$this->URLSegment);
$segment = preg_replace('/-+/','-',$segment);
if(!$segment) {
$segment="clanek-$this->ID";
}
$this->URLSegment = $segment;
}
$count=2;
while($this->LookForExistingURLSegment($this->URLSegment)) {
$this->URLSegment = preg_replace('/-[0-9]+$/', null, $this->URLSegment).'-'.$count;
$count++;
}
parent::onBeforeWrite();
}
function LookForExistingURLSegment($URLSegment) {
return(DataObject::get_one('Article', "URLSegment = '".$URLSegment."' AND ID != ".$this->ID));
}
public function AuthorName() {
return $this->Author()->FirstName." ".$this->Author()->Surname;
}
public function isPublished() {
return $this->Published ? _t("Article.YES","Da") : _t("Article.NO","Ne");
}
}
ArticleAdmin.php
class ArticleAdmin extends ModelAdmin {
public static $managed_models = array(
'Article'
);
static $url_segment = 'articles';
static $menu_title = 'Article Admin';
public $showImportForm = false;
}