mirror of
https://github.com/silverstripe/silverstripe-frameworktest
synced 2024-10-22 11:06:02 +02:00
ENHANCEMENT Added test page for TagField
This commit is contained in:
parent
ffc2f85b9d
commit
414ba50e04
23
code/TestTag.php
Normal file
23
code/TestTag.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
class TestTag extends DataObject {
|
||||
|
||||
static $db = array(
|
||||
'Title' => 'Text'
|
||||
);
|
||||
|
||||
static $belongs_many_many = array(
|
||||
'Pages' => 'TestTagFieldPage'
|
||||
);
|
||||
|
||||
function requireDefaultRecords(){
|
||||
$class = $this->class;
|
||||
if(!DataObject::get_one($class)) {
|
||||
foreach(array('one', 'two', 'three', 'four') as $title) {
|
||||
$tag = new $class();
|
||||
$tag->Title = $title;
|
||||
$tag->write();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
38
code/TestTagFieldPage.php
Normal file
38
code/TestTagFieldPage.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
class TestTagFieldPage extends Page {
|
||||
|
||||
static $db = array(
|
||||
'TestTagString' => 'Text',
|
||||
'FixedTags' => 'Text'
|
||||
);
|
||||
|
||||
static $many_many = array(
|
||||
'TestTags' => 'TestTag',
|
||||
);
|
||||
|
||||
function getCMSFields() {
|
||||
$fields = parent::getCMSFields();
|
||||
|
||||
$tf1 = new TagField('TestTagString', "Single column tags (try 'one', 'two', 'three', 'four')", 'TestTag');
|
||||
$fields->addFieldToTab('Root.Content.Main', $tf1);
|
||||
|
||||
$tf2 = new TagField('TestTags', "Relation tags (try 'one', 'two', 'three', 'four')", null, 'TestTag');
|
||||
$fields->addFieldToTab('Root.Content.Main', $tf2);
|
||||
|
||||
$tf3 = new TagField('FixedTags', "Fixed tags (try 'PHP', 'Ruby', 'Python')", null, 'TestTag');
|
||||
$tf3->setCustomTags(array('PHP', 'Ruby', 'Python'));
|
||||
$fields->addFieldToTab('Root.Content.Main', $tf3);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
function requireDefaultRecords(){
|
||||
$class = $this->class;
|
||||
if(!DataObject::get_one($class)) {
|
||||
$page = new $class();
|
||||
$page->Title = "Test TagField";
|
||||
$page->write();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user