Skip to content

Commit 7cd9c81

Browse files
committed
DOC Prepare for docs site
1 parent 8fb9324 commit 7cd9c81

8 files changed

Lines changed: 120 additions & 108 deletions

File tree

.doclintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docs/en/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ composer require silverstripe/tagfield
1313

1414
## Overview
1515

16-
![Screenshot](docs/en/screenshot.png)
16+
![Screenshot](docs/en/_images/screenshot.png)
1717

1818
Allows storing tags as a relationship, or comma-delimited strings.
1919
Supports autocompletion with lazy-loading.

composer.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"phpunit/phpunit": "^9.6",
2828
"squizlabs/php_codesniffer": "^3",
2929
"silverstripe/standards": "^1",
30+
"silverstripe/documentation-lint": "^1",
3031
"phpstan/extension-installer": "^1.3"
3132
},
3233
"autoload": {
@@ -40,6 +41,11 @@
4041
"client/dist"
4142
]
4243
},
44+
"config": {
45+
"allow-plugins": {
46+
"dealerdirect/phpcodesniffer-composer-installer": true
47+
}
48+
},
4349
"minimum-stability": "dev",
4450
"prefer-stable": true
4551
}

docs/en/index.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
---
2+
title: TagField
3+
summary: Provides a custom form field for adding tags to content, supporting either related data objects or simple string-based tags
4+
icon: tags
5+
---
6+
7+
# TagField
8+
9+
The TagField module provides a custom form field for adding tags to content. It supports creating tags as related data objects or as a simple comma-separated list of strings.
10+
11+
## Installation
12+
13+
```bash
14+
composer require silverstripe/tagfield
15+
```
16+
17+
Then run `/dev/build`, from either the command line or the browser.
18+
19+
## Usage
20+
21+
The primary use, for this module, is as a custom input field interface. For instance, imagine you had the following data objects:
22+
23+
```php
24+
namespace App\Models;
25+
26+
class BlogPost extends DataObject
27+
{
28+
private static $many_many = [
29+
'BlogTags' => BlogTag::class,
30+
];
31+
}
32+
```
33+
34+
```php
35+
namespace App\Models;
36+
37+
class BlogTag extends DataObject
38+
{
39+
private static $db = [
40+
'Title' => 'Varchar(200)',
41+
];
42+
43+
private static $belongs_many_many = [
44+
'BlogPosts' => BlogPost::class,
45+
];
46+
}
47+
```
48+
49+
If you wanted to link blog tags to blog posts, you might override [`DataObject::getCMSFields()`](api:SilverStripe\ORM\DataObject::getCMSFields()) with the following field:
50+
51+
```php
52+
$field = TagField::create(
53+
'BlogTags',
54+
'Blog Tags',
55+
BlogTag::get(),
56+
$this->BlogTags()
57+
)
58+
// tags should be lazy loaded
59+
->setShouldLazyLoad(true)
60+
// new tag DataObjects can be created
61+
->setCanCreate(true);
62+
```
63+
64+
**Note:** This assumes you have imported the namespaces class, e.g. `use SilverStripe\TagField\TagField;`.
65+
66+
This will present a tag field, in which you can select existing blog tags or create new ones. They will be created/linked after the blog posts are saved.
67+
68+
### StringTagField
69+
70+
You can also store string-based tags, with the following field type:
71+
72+
```php
73+
$field = StringTagField::create(
74+
'Tags',
75+
'Tags',
76+
['one', 'two'],
77+
explode(',', $this->Tags)
78+
)
79+
->setCanCreate(true)
80+
->setShouldLazyLoad(true);
81+
```
82+
83+
This assumes you are storing tags in the following data object structure:
84+
85+
```php
86+
namespace App\Models;
87+
88+
class BlogPost extends DataObject
89+
{
90+
private static $db = [
91+
'Tags' => 'Text',
92+
];
93+
}
94+
```
95+
96+
In the above code example, the options available (whether lazy loaded or not) would be "one" and "two", and the
97+
user would be able to create new options. Whichever tags are chosen would be stored in the BlogPost's `Tags` field
98+
as a comma-delimited string.
99+
100+
## Using tagfield with silverstripe-taxonomy
101+
102+
TagField assumes that objects have a `Title` field. For classes without a `Title` field
103+
use [`TagField::setTitleField()`](api:SilverStripe\TagField\TagField::setTitleField()) to modify accordingly.
104+
105+
```php
106+
$field = TagField::create(
107+
'Tags',
108+
'Blog Tags',
109+
TaxonomyTerm::get()
110+
)
111+
->setTitleField('Name');
112+
```

docs/en/installing.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

docs/en/introduction.md

Lines changed: 0 additions & 14 deletions
This file was deleted.

docs/en/using.md

Lines changed: 0 additions & 84 deletions
This file was deleted.

0 commit comments

Comments
 (0)