Skip to content

Commit 8b480d6

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

8 files changed

Lines changed: 72 additions & 51 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
}
Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,68 @@
1-
# Using
1+
---
2+
title: TagField Module Usage
3+
summary: Managing tags on DataObjects, and integration with silverstripe-taxonomy
4+
icon: tags
5+
---
6+
7+
# Usage
28

39
The primary use, for this module, is as a custom input field interface. For instance, imagine you had the following data objects:
410

511
```php
12+
namespace App\Models;
13+
614
class BlogPost extends DataObject
715
{
8-
private static $many_many = array(
9-
'BlogTags' => 'SilverStripe\\Blog\\Model\\BlogTag'
10-
);
16+
private static $many_many = [
17+
'BlogTags' => BlogTag::class,
18+
];
1119
}
20+
```
21+
22+
```php
23+
namespace App\Models;
1224

1325
class BlogTag extends DataObject
1426
{
15-
private static $db = array(
16-
'Title' => 'Varchar(200)'
17-
);
27+
private static $db = [
28+
'Title' => 'Varchar(200)',
29+
];
1830

19-
private static $belongs_many_many = array(
20-
'BlogPosts' => 'SilverStripe\\Blog\\Model\\BlogPost'
21-
);
31+
private static $belongs_many_many = [
32+
'BlogPosts' => BlogPost::class,
33+
];
2234
}
2335
```
2436

25-
If you wanted to link blog tags to blog posts, you might override `getCMSFields` with the following field:
37+
If you wanted to link blog tags to blog posts, you might override [`DataObject::getCMSFields()`](api:SilverStripe\ORM\DataObject::getCMSFields()) with the following field:
2638

2739
```php
2840
$field = TagField::create(
29-
'BlogTags',
30-
'Blog Tags',
31-
BlogTag::get(),
32-
$this->BlogTags()
41+
'BlogTags',
42+
'Blog Tags',
43+
BlogTag::get(),
44+
$this->BlogTags()
3345
)
34-
->setShouldLazyLoad(true) // tags should be lazy loaded
35-
->setCanCreate(true); // new tag DataObjects can be created
46+
// tags should be lazy loaded
47+
->setShouldLazyLoad(true)
48+
// new tag DataObjects can be created
49+
->setCanCreate(true);
3650
```
3751

3852
**Note:** This assumes you have imported the namespaces class, e.g. `use SilverStripe\TagField\TagField;`.
3953

4054
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.
4155

42-
### StringTagField
56+
## StringTagField
4357

4458
You can also store string-based tags, with the following field type:
4559

4660
```php
4761
$field = StringTagField::create(
48-
'Tags',
49-
'Tags',
50-
['one', 'two'],
51-
explode(',', $this->Tags)
62+
'Tags',
63+
'Tags',
64+
['one', 'two'],
65+
explode(',', $this->Tags)
5266
)
5367
->setCanCreate(true)
5468
->setShouldLazyLoad(true);
@@ -57,28 +71,30 @@ $field = StringTagField::create(
5771
This assumes you are storing tags in the following data object structure:
5872

5973
```php
74+
namespace App\Models;
75+
6076
class BlogPost extends DataObject
6177
{
6278
private static $db = [
6379
'Tags' => 'Text',
64-
];
80+
];
6581
}
6682
```
6783

6884
In the above code example, the options available (whether lazy loaded or not) would be "one" and "two", and the
6985
user would be able to create new options. Whichever tags are chosen would be stored in the BlogPost's `Tags` field
7086
as a comma-delimited string.
7187

72-
## Using TagField with silverstripe-taxonomy
88+
## Using tagfield with silverstripe-taxonomy
7389

74-
TagField assumes a `Title` field on objects. For classes without a `Title` field
75-
use `setTitleField` to modify accordingly.
90+
TagField assumes that objects have a `Title` field. For classes without a `Title` field
91+
use [`TagField::setTitleField()`](api:SilverStripe\TagField\TagField::setTitleField()) to modify accordingly.
7692

7793
```php
7894
$field = TagField::create(
7995
'Tags',
8096
'Blog Tags',
81-
TaxonomyTerm::get(),
97+
TaxonomyTerm::get()
8298
)
8399
->setTitleField('Name');
84100
```

docs/en/index.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
## GitHub repository
18+
19+
<https://github.com/silverstripe/silverstripe-tagfield>
20+
21+
[CHILDREN]

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.

0 commit comments

Comments
 (0)