You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
Steve Boyd 3d6a77fff1 Merge branch '2.9' into 2 2 months ago
.github/workflows Merge branch '2.9' into 2 2 months ago
_config Setup TagField to work within AssetAdmin (Fixes #107) 3 years ago
client FIX Selected tag is not shown when isMutliple is false (#201) 4 months ago
docs/en FIX Selected tag is not shown when isMutliple is false (#201) 4 months ago
src fix: Fall back to the `ID` if no title is given 2 months ago
templates/SilverStripe/TagField Additional changes to convert tagfield to use react-select 4 years ago
tests FIX Selected tag is not shown when isMutliple is false (#201) 4 months ago
.editorconfig FIX Selected tag is not shown when isMutliple is false (#201) 4 months ago
.eslintrc.js Additional changes to convert tagfield to use react-select 4 years ago
.gitattributes Added standard git attributes 7 years ago
.gitignore FIX Adding a debounce to fetching lazy loaded tags with tag field 4 years ago
.nvmrc MNT Update to Node 10 2 years ago
.ss-storybook.js FIX Ensure tagfield is compatible with both React and Entwine contexts 3 years ago
.upgrade.yml FIX SS4 compatibility updates, PSR-4 in tests, table_name in stubs 5 years ago
README.md Merge branch '2.9' into 2 2 months ago
_config.php FIX Update module for latest SS4, vendorise 5 years ago
code-of-conduct.md Added standard code of conduct 7 years ago
codecov.yml FIX Update module for latest SS4, vendorise 5 years ago
composer.json DEP Set PHP 7.4 as the minimum version 8 months ago
contributing.md Made supported 7 years ago
license.md Updated license year 7 years ago
package.json DEP Update JS dependencies 10 months ago
phpcs.xml.dist MNT Use shared travis config, use sminnee/phpunit 2 years ago
phpunit.xml.dist MNT Standardise modules 2 months ago
webpack.config.js NEW Converting tagfield to use react components 4 years ago
yarn.lock FIX Selected tag is not shown when isMutliple is false (#201) 4 months ago

README.md

Tag Field

CI Silverstripe supported module

Custom tag input field, for SilverStripe.

Overview

Screenshot

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

Note: The field is optimised for usage in the Silverstripe CMS UI. The form field class itself can be used outside of the CMS, but you'll need to build your own frontend to interpret the raw field data (data-schema attribute).

Requirements

  • Silverstripe 4.0

Installing

$ composer require silverstripe/tagfield

Using

Relational Tags

use SilverStripe\ORM\DataObject;

class BlogPost extends DataObject
{
    private static $many_many = [
        'BlogTags' => BlogTag::class
    ];
}
use SilverStripe\ORM\DataObject;

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

    private static $belongs_many_many = [
        'BlogPosts' => BlogPost::class
    ];
}
$field = TagField::create(
    'BlogTags',
    'Blog Tags',
    BlogTag::get(),
    $this->BlogTags()
)
    ->setShouldLazyLoad(true) // tags should be lazy loaded
    ->setCanCreate(true);     // new tag DataObjects can be created

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

Has-One Relations

You can also use the TagField to select values for has_one relations. Let's assume, that a BlogPost has one BlogCategory.

class BlogCategory extends DataObject
{
    private static $db = [
        'Title' => 'Varchar(200)',
    ];
}
use SilverStripe\ORM\DataObject;

class BlogPost extends DataObject
{
    private static $has_one = [
        'BlogCategory' => BlogCategory::class
    ];
}
$field = TagField::create(
    'BlogCategoryID',
    $this->fieldLabel('BlogCategory'),
    BlogCategory::get()
)
    ->setIsMultiple(false)
    ->setCanCreate(true);

Note: We're using the ID suffix for the field-name (eg. BlogCategoryID instead of BlogCategory) and only allow one value by setting ->setIsMultiple(false)

String Tags

use SilverStripe\ORM\DataObject;

class BlogPost extends DataObject
{
    private static $db = [
        'Tags' => 'Text',
    ];
}
$field = StringTagField::create(
    'Tags',
    'Tags',
    ['one', 'two'],
    explode(',', $this->Tags)
);

$field->setShouldLazyLoad(true); // tags should be lazy loaded

You can find more in-depth documentation in docs/en.

Using TagField with silverstripe-taxonomy

TagField assumes a Title field on objects. For classes without a Title field use setTitleField to modify accordingly.

$field = TagField::create(
    'Tags',
    'Blog Tags',
    TaxonomyTerm::get(),
)
    ->setTitleField('Name');

Versioning

This library follows Semver. According to Semver, you will be able to upgrade to any minor or patch version of this library without any breaking changes to the public API. Semver also requires that we clearly define the public API for this library.

All methods, with public visibility, are part of the public API. All other methods are not part of the public API. Where possible, we'll try to keep protected methods backwards-compatible in minor/patch versions, but if you're overriding methods then please test your work before upgrading.

Reporting Issues

Please create an issue for any bugs you've found, or features you're missing.