Skip to content

Commit 95f2beb

Browse files
committed
Merge branch '4.0' into 4
2 parents 8cdc3b3 + b70fe29 commit 95f2beb

9 files changed

Lines changed: 144 additions & 109 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: 2 additions & 2 deletions
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.
@@ -127,7 +127,7 @@ $field = StringTagField::create(
127127
$field->setShouldLazyLoad(true); // tags should be lazy loaded
128128
```
129129

130-
You can find more in-depth documentation in [docs/en](docs/en/introduction.md).
130+
You can find more in-depth documentation in the [documentation](https://docs.silverstripe.org/en/optional_features/tagfield).
131131

132132
## Using TagField with silverstripe-taxonomy
133133

composer.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"phpunit/phpunit": "^11.3",
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/01_usage.md

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

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.

docs/en/using.md

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

0 commit comments

Comments
 (0)