public function updateCMSFields(\FieldList $fields) { parent::updateCMSFields($fields); // Add Categories & Tags fields //if($this->owner->Parent()->getFilterableArchiveConfigValue('categories_active')){ if (Config::inst()->get($this->owner->Parent()->className, 'categories_active')) { // $categoriesField = ListboxField::create( // "Categories", // _t("FilterableArchive.Categories", "Categories"), // $this->owner->Parent()->Categories()->map()->toArray() // )->setMultiple(true); // Use tagfield instead (allows inline creation) //$availableCats = FilterCategory::get()->filter('HolderPageID',$this->owner->ParentID); $availableCats = $this->owner->Parent()->Categories(); $categoriesField = new TagField('Categories', _t("FilterableArchive.Categories", "Categories"), $availableCats, $this->owner->Categories()); //$categoriesField->setShouldLazyLoad(true); // tags should be lazy loaded (nope, gets all instead of just the parent's cats/tags) $categoriesField->setCanCreate(true); // new tag DataObjects can be created (@TODO check privileges) $fields->insertbefore($categoriesField, "Content"); } //if($this->owner->Parent()->getFilterableArchiveConfigValue('tags_active')){ if (Config::inst()->get($this->owner->Parent()->className, 'tags_active')) { // $tagsField = ListboxField::create( // "Tags", // _t("BlogPost.Tags", "Tags"), // $this->owner->Parent()->Tags()->map()->toArray() // )->setMultiple(true); // Use tagfield instead (allows inline creation) //$availableTags = FilterTag::get()->filter('HolderPageID',$this->owner->ParentID); $availableTags = $this->owner->Parent()->Tags(); $tagsField = new TagField('Tags', _t("FilterableArchive.Tags", "Tags"), $availableTags, $this->owner->Tags()); //$tagsField->setShouldLazyLoad(true); // tags should be lazy loaded (nope, gets all instead of just the parent's cats/tags) $tagsField->setCanCreate(true); // new tag DataObjects can be created (@TODO check privileges) $fields->insertAfter($tagsField, "Categories"); } }
function testItIgnoresNewTagsIfCannotCreate() { $record = new TagFieldTestBlogPost(); $record->write(); $tag = TagFieldTestBlogTag::get()->filter('Title', 'Tag1')->first(); $field = new TagField('Tags', '', new DataList('TagFieldTestBlogTag'), array($tag->ID, 'Tag3')); $field->setCanCreate(false); $field->saveInto($record); /** * @var TagFieldTestBlogPost $record */ $record = DataObject::get_by_id('TagFieldTestBlogPost', $record->ID); $this->compareExpectedAndActualTags(array('Tag1'), $record); }