Permalink
Browse files

Use ItemSetField for picking vocab terms on site nodes

Use https://github.com/ajshort/silverstripe-itemsetfield for picking vocabulary
terms to add to pages decorated with VocabularyTermClassifiable.
  • Loading branch information...
jthomerson committed Feb 7, 2012
1 parent 8508ea0 commit a363c2e9a174764d407185770d7d3648dfe5dcaf
Showing with 21 additions and 9 deletions.
  1. +13 −4 code/VocabularyTerm.php
  2. +8 −5 code/VocabularyTermClassifiable.php
View
@@ -44,10 +44,6 @@ class VocabularyTerm extends DataObject {
'MachineName',
);
- public function getFullTermTitle() {
- return sprintf('%s : %s', $this->Vocabulary()->Name, $this->Term);
- }
-
public function getChildrenTerms() {
return implode(', ', $this->Children()->map('ID', 'Term'));
}
@@ -73,8 +69,21 @@ function getCMSFields() {
return $fields;
}
+ public function getFullTermTitle() {
+ return sprintf('%s : %s', $this->Vocabulary()->Name, $this->Term);
+ }
+
public function getParentsTerms() {
return implode(', ', $this->Parents()->map('ID', 'Term'));
}
+ public function Summary() {
+ $summary = $this->getFullTermTitle();
+ $parents = $this->getParentsTerms();
+ if (!empty($parents)) {
+ $summary .= sprintf('<em>' . _t('VocabularyTerm.Summary.Parents', ' (Parent terms: %s)') . '</em>', $parents);
+ }
+ return $summary;
+ }
+
}
@@ -19,11 +19,14 @@ function extraStatics() {
}
public function updateCMSFields(FieldSet &$fields) {
- //$fields->addFieldToTab('Root.Content.Main', new ReadonlyField('FirstPublishedDate', 'First Published (online)'), 'Title');
- $termsSort = '"Vocabulary"."Name", "VocabularyTerm"."Term"';
- $termsJoin = 'JOIN "Vocabulary" ON "Vocabulary"."ID" = "VocabularyTerm"."VocabularyID"';
- $terms = DataObject::get('VocabularyTerm', '', $termsSort, $termsJoin)->map('ID', 'FullTermTitle');
- $fields->addFieldToTab('Root.Taxonomy', new CheckboxSetField('VocabularyTerms', 'Vocabulary Terms', $terms));
+ $fields->addFieldToTab('Root.Taxonomy', new ManyManyPickerField(
+ $this->owner,
+ 'VocabularyTerms',
+ _t('Vocabulary.Terms.Label', 'Vocabulary Terms'),
+ array(
+ 'ShowPickedInSearch' => false,
+ )
+ ));
}
}

0 comments on commit a363c2e

Please sign in to comment.