-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DOC Update doc structure for docs.silverstripe.org #114
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
docs/en/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
--- | ||
title: Basic usage | ||
summary: How to set up your taxonomy relations and fields | ||
--- | ||
|
||
# Basic usage | ||
|
||
The main model you'll be interacting with is [`TaxonomyTerm`](api:SilverStripe\Taxonomy\TaxonomyTerm). This class represents the actual taxonomy terms you will apply to your data. | ||
|
||
A taxonomy is of extremely limited use by itself. To make use of it, you need to associate it with | ||
`DataObject` models in your site. | ||
|
||
To add the the ability to associate a model with `TaxonomyTerm`, you need to add the many-many relation: | ||
|
||
```php | ||
namespace App\Model; | ||
|
||
use SilverStripe\Forms\TreeMultiselectField; | ||
use SilverStripe\ORM\DataObject; | ||
use SilverStripe\Taxonomy\TaxonomyTerm; | ||
|
||
class MyModel extends DataObject | ||
{ | ||
// ... | ||
private static $many_many = [ | ||
'Terms' => TaxonomyTerm::class, | ||
]; | ||
|
||
public function getCMSFields() | ||
{ | ||
$fields = parent::getCMSFields(); | ||
// ... | ||
$fields->addFieldToTab('Root.Main', TreeMultiselectField::create( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
'Terms', | ||
$this->fieldLabel('Terms'), | ||
TaxonomyTerm::class | ||
)); | ||
return $fields; | ||
} | ||
} | ||
``` | ||
|
||
Run a `dev/build?flush=all` and you'll be able to add taxonomy terms to your record - but now you need to create some terms! See [the userhelp documentation](https://userhelp.silverstripe.org/en/optional_features/taxonomies/) for information about functionality from a content author perspective. | ||
|
||
## Filtering by type | ||
|
||
If you have implemented taxonomy types, you can filter them to ensure that only taxonomy terms of a given type or types can be selected. | ||
This can be useful, for example, if you want to separate your terms between files/images/documents and CMS pages. | ||
|
||
> [!WARNING] | ||
> This relies on `TaxonomyType` records which have specific names being set up in the CMS. | ||
> You will need to coordinate with content authors to ensure these are always available, or else | ||
> ensure they are created by default by [populating defaults](https://docs.silverstripe.org/en/developer_guides/model/how_tos/dynamic_default_fields/) | ||
> and ensure they cannot be deleted by [implementing an Extension](https://docs.silverstripe.org/en/developer_guides/extending/extensions/) | ||
> with the `canDelete()` method. | ||
|
||
To implement this filtering, call [`TreeMultiselectField::setFilterFunction()`](api:SilverStripe\Forms\TreeMultiselectField::setFilterFunction()) with the filtering logic: | ||
|
||
```php | ||
use SilverStripe\Forms\TreeMultiselectField; | ||
use SilverStripe\Taxonomy\TaxonomyTerm; | ||
use SilverStripe\Taxonomy\TaxonomyType; | ||
|
||
/** @var TreeMultiselectField $treeField */ | ||
$typeID = TaxonomyType::get()->find('Name', 'CMS Page')?->ID; | ||
$treeField->setFilterFunction(fn (TaxonomyTerm $term) => $term->TypeID === $typeID); | ||
``` | ||
|
||
## Showing taxonomy terms | ||
|
||
So you've got a set of terms associated with a page, and you want to show them on your site. You can loop through them | ||
like any other relation: | ||
|
||
```ss | ||
<% loop $Terms %> | ||
<span class="tag">$Name</span> | ||
<% end_loop %> | ||
``` |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
title: Taxonomies | ||
summary: Provides the capability to add and edit simple taxonomies for categorising data | ||
icon: link | ||
--- | ||
|
||
# Taxonomies | ||
|
||
Make sure that your Silverstripe CMS installation has [`silverstripe/taxonomy`](https://github.com/silverstripe/silverstripe-taxonomy/) installed. | ||
|
||
This module provides a "Taxonomies" section in the CMS, and a couple of `DataObject` models. | ||
|
||
[CHILDREN includeFolders] |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All changes in this file were just to pass linting. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed unnecessary empty section