silverstripe/tagfield
最新稳定版本:4.1.1
Composer 安装命令:
composer require silverstripe/tagfield
包简介
Tag field for SilverStripe
关键字:
README 文档
README
Custom tag input field, for SilverStripe.
Installation
composer require silverstripe/tagfield
Overview
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).
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 the documentation.
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.
统计信息
- 总下载量: 1.16M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 57
- 点击次数: 1
- 依赖项目数: 53
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2013-01-08
