From 414ba50e04213f4a87932e63f56622f94c412693 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Sat, 25 Sep 2010 01:09:22 +0000 Subject: [PATCH] ENHANCEMENT Added test page for TagField --- code/TestTag.php | 23 +++++++++++++++++++++++ code/TestTagFieldPage.php | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 code/TestTag.php create mode 100644 code/TestTagFieldPage.php diff --git a/code/TestTag.php b/code/TestTag.php new file mode 100644 index 0000000..0b54950 --- /dev/null +++ b/code/TestTag.php @@ -0,0 +1,23 @@ + '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(); + } + + } + } +} \ No newline at end of file diff --git a/code/TestTagFieldPage.php b/code/TestTagFieldPage.php new file mode 100644 index 0000000..4f10f18 --- /dev/null +++ b/code/TestTagFieldPage.php @@ -0,0 +1,38 @@ + '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(); + } + } + +} \ No newline at end of file