Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .doclintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docs/en/
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ composer require silverstripe/tagfield

## Overview

![Screenshot](docs/en/screenshot.png)
![Screenshot](docs/en/_images/screenshot.png)

Allows storing tags as a relationship, or comma-delimited strings.
Supports autocompletion with lazy-loading.
Expand Down Expand Up @@ -127,7 +127,7 @@ $field = StringTagField::create(
$field->setShouldLazyLoad(true); // tags should be lazy loaded
```

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

## Using TagField with silverstripe-taxonomy

Expand Down
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"phpunit/phpunit": "^9.6",
"squizlabs/php_codesniffer": "^3",
"silverstripe/standards": "^1",
"silverstripe/documentation-lint": "^1",
"phpstan/extension-installer": "^1.3"
},
"autoload": {
Expand All @@ -40,6 +41,11 @@
"client/dist"
]
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
114 changes: 114 additions & 0 deletions docs/en/01_usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
---
title: TagField Module Usage
summary: Managing tags on DataObjects, and integration with silverstripe-taxonomy
icon: tags
---

# Usage

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

```php
namespace App\Models;

use SilverStripe\Blog\Model\BlogTag;
use SilverStripe\ORM\DataObject;

class BlogPost extends DataObject
Comment thread
GuySartorelli marked this conversation as resolved.
{
private static $many_many = [
'BlogTags' => BlogTag::class,
];
}
```

```php
namespace App\Models;

use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\ORM\DataObject;

class BlogTag extends DataObject
{
private static $db = [
'Title' => 'Varchar(200)',
];

private static $belongs_many_many = [
'BlogPosts' => BlogPost::class,
];
}
```

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

```php
use SilverStripe\Blog\Model\BlogTag;
use SilverStripe\TagField\TagField;

$field = TagField::create(
'BlogTags',
'Blog Tags',
BlogTag::get(),
$this->BlogTags()
)
// tags should be lazy loaded
->setShouldLazyLoad(true)
// new tag DataObjects can be created
->setCanCreate(true);
```

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.

## StringTagField

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

```php
use SilverStripe\TagField\StringTagField;

$field = StringTagField::create(
'Tags',
'Tags',
['one', 'two'],
explode(',', $this->Tags)
)
->setCanCreate(true)
->setShouldLazyLoad(true);
```

This assumes you are storing tags in the following data object structure:

```php
namespace App\Models;

use SilverStripe\ORM\DataObject;

class BlogPost extends DataObject
{
private static $db = [
'Tags' => 'Text',
];
}
```

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

## Using tagfield with silverstripe-taxonomy

TagField assumes that objects have a `Title` field. For classes without a `Title` field
use [`TagField::setTitleField()`](api:SilverStripe\TagField\TagField::setTitleField()) to modify accordingly.

```php
use SilverStripe\TagField\TagField;
use SilverStripe\Taxonomy\TaxonomyTerm;

$field = TagField::create(
'Tags',
'Blog Tags',
TaxonomyTerm::get()
)
->setTitleField('Name');
```
File renamed without changes
21 changes: 21 additions & 0 deletions docs/en/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
title: TagField
summary: Provides a custom form field for adding tags to content, supporting either related data objects or simple string-based tags
icon: tags
---

# TagField

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.

## Installation

```bash
composer require silverstripe/tagfield
```

## GitHub repository

<https://github.com/silverstripe/silverstripe-tagfield>

[CHILDREN]
9 changes: 0 additions & 9 deletions docs/en/installing.md

This file was deleted.

14 changes: 0 additions & 14 deletions docs/en/introduction.md

This file was deleted.

84 changes: 0 additions & 84 deletions docs/en/using.md

This file was deleted.