Made supported

This commit is contained in:
Christopher Pitt 2015-09-09 11:07:51 +12:00
parent 4f86c021cf
commit d7f0206a0e
12 changed files with 248 additions and 88 deletions

6
.gitattributes vendored Normal file
View File

@ -0,0 +1,6 @@
/tests export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/.scrutinizer.yml export-ignore
/phpunit.xml export-ignore

12
.scrutinizer.yml Normal file
View File

@ -0,0 +1,12 @@
inherit: true
tools:
external_code_coverage: true
checks:
php:
code_rating: true
duplication: true
filter:
paths: [code/*, tests/*]

View File

@ -1,28 +1,31 @@
# See https://github.com/silverstripe-labs/silverstripe-travis-support for setup details
language: php
php:
- 5.3
- 5.4
- 5.5
- 5.6
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
sudo: false
env:
- DB=MYSQL CORE_RELEASE=3.1
matrix:
allow_failures:
- php: 5.5
env: DB=MYSQL CORE_RELEASE=3.1
- php: 5.6
env: DB=MYSQL CORE_RELEASE=3.1
- DB=MYSQL CORE_RELEASE=3.1
before_script:
- git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support
- php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss
- cd ~/builds/ss
- git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support
- php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss
- cd ~/builds/ss
script:
- phpunit tagfield/tests
- vendor/bin/phpunit --coverage-clover coverage.clover tagfield/tests
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover --repository=g/silverstripe-labs/silverstripe-tagfield
branches:
only:
- master
matrix:
allow_failures:
- php: 7.0

View File

@ -1,69 +0,0 @@
# TagField Module
[![Build Status](http://img.shields.io/travis/silverstripe-labs/silverstripe-tagfield.svg?style=flat-square)](https://travis-ci.org/silverstripe-labs/silverstripe-tagfield)
[![Code Quality](http://img.shields.io/scrutinizer/g/silverstripe-labs/silverstripe-tagfield.svg?style=flat-square)](https://scrutinizer-ci.com/g/silverstripe-labs/silverstripe-tagfield)
## Requirements
* SilverStripe 3.1 or newer
* Database: MySQL 5+, SQLite3, Postgres 8.3, SQL Server 2008
## Download/Information
* http://silverstripe.org/tag-field-module
## Usage
### Relational Tags
```php
class BlogPost extends DataObject {
private static $many_many = array(
'BlogTags' => 'BlogTag'
);
}
```
```php
class BlogTag extends DataObject {
private static $db = array(
'Title' => 'Varchar(200)',
);
private static $belongs_many_many = array(
'BlogPosts' => 'BlogPost'
);
}
```
```php
$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
```
### String Tags
```php
class BlogPost extends DataObject {
private static $db = array(
'Tags' => 'Text'
);
}
```
```php
$field = StringTagField::create(
'Tags',
'Tags',
array('one', 'two'),
explode(',', $this->Tags)
);
$field->setShouldLazyLoad(true); // tags should be lazy loaded
```

9
changelog.md Normal file
View File

@ -0,0 +1,9 @@
# Changelog
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
## [1.0.0]
Changelog added.

22
code-of-conduct.md Normal file
View File

@ -0,0 +1,22 @@
# Code of Conduct
As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery
* Personal attacks
* Trolling or insulting/derogatory comments
* Public or private harassment
* Publishing other's private information, such as physical or electronic addresses, without explicit permission
* Other unethical or unprofessional conduct.
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.
This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)

3
contributing.md Normal file
View File

@ -0,0 +1,3 @@
# Contributing
Contributions are welcome! Create an issue, explaining a bug or proposal. Submit pull requests if you feel brave. Speak to me on [Twitter](https://twitter.com/assertchris).

9
docs/en/installing.md Normal file
View File

@ -0,0 +1,9 @@
# Installing
To install this module, [download and install Composer](https://getcomposer.org/doc/00-intro.md). Then run the following command:
```sh
$ composer require silverstripe/tagfield
```
Then run `/dev/build`, from either the command line or the browser. You'll then be able to use this field in your application.

14
docs/en/introduction.md Normal file
View File

@ -0,0 +1,14 @@
# Introduction
Custom tag input field, for SilverStripe.
## Sections
- [Installing](installing.md)
- [Using](using.md)
## Questions
This module is supported by [Christopher Pitt](https://twitter.com/assertchris). You can ask questions on Twitter.
You can report bugs or request features on [GitHub](http://github.com/silverstripe-labs/silverstripe-tagfield/issues).

63
docs/en/using.md Normal file
View File

@ -0,0 +1,63 @@
# Using
The primary use, for this module, is as a custom input field interface. For instance, imagine you had the following data objects:
```php
class BlogPost extends DataObject {
private static $many_many = array(
'BlogTags' => 'BlogTag'
);
}
class BlogTag extends DataObject {
private static $db = array(
'Title' => 'Varchar(200)',
);
private static $belongs_many_many = array(
'BlogPosts' => 'BlogPost'
);
}
```
If you wanted to link blog tags to blog posts, you might override `getCMSFields` with the following field:
```php
$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
```
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.
You can also store string-based tags, for blog posts, with the following field type:
```php
$field = StringTagField::create(
'Tags',
'Tags',
array('one', 'two'),
explode(',', $this->Tags)
);
$field->setShouldLazyLoad(true); // tags should be lazy loaded
```
This assumes you are storing tags in the following data object structure:
```php
class BlogPost extends DataObject {
private static $db = array(
'Tags' => 'Text'
);
}
```
These tag field classes extend the `DropdownField` class. Their template(s) don't alter the underlying select element structure, so you can interact with them as with any normal select element. You can also interact with the Select2 instance applied to each field, as you would any other time when using Select2.
> Chosen is applied to all select elements in the CMS, so this module attempts to remove it before applying Select2. Review the companion JS files to see how that happens...

View File

@ -20,4 +20,4 @@ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

88
readme.md Normal file
View File

@ -0,0 +1,88 @@
# Tag Field
Custom tag input field, for SilverStripe.
[![Build Status](http://img.shields.io/travis/silverstripe-labs/silverstripe-tagfield.svg?style=flat-square)](https://travis-ci.org/silverstripe-labs/silverstripe-tagfield)
[![Code Quality](http://img.shields.io/scrutinizer/g/silverstripe-labs/silverstripe-tagfield.svg?style=flat-square)](https://scrutinizer-ci.com/g/silverstripe-labs/silverstripe-tagfield)
[![Code Coverage](http://img.shields.io/scrutinizer/coverage/g/silverstripe-labs/silverstripe-tagfield.svg?style=flat-square)](https://scrutinizer-ci.com/g/silverstripe-labs/silverstripe-tagfield)
[![Version](http://img.shields.io/packagist/v/silverstripe/tagfield.svg?style=flat-square)](https://packagist.org/packages/silverstripe/tagfield)
[![License](http://img.shields.io/packagist/l/silverstripe/tagfield.svg?style=flat-square)](license.md)
## Requirements
* SilverStripe 3.1 or newer
* Database: MySQL 5+, SQLite3, Postgres 8.3, SQL Server 2008
## Installing
```sh
$ composer require silverstripe/tagfield
```
## Using
### Relational Tags
```php
class BlogPost extends DataObject {
private static $many_many = array(
'BlogTags' => 'BlogTag'
);
}
```
```php
class BlogTag extends DataObject {
private static $db = array(
'Title' => 'Varchar(200)',
);
private static $belongs_many_many = array(
'BlogPosts' => 'BlogPost'
);
}
```
```php
$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
```
### String Tags
```php
class BlogPost extends DataObject {
private static $db = array(
'Tags' => 'Text'
);
}
```
```php
$field = StringTagField::create(
'Tags',
'Tags',
array('one', 'two'),
explode(',', $this->Tags)
);
$field->setShouldLazyLoad(true); // tags should be lazy loaded
```
You can find more in-depth documentation in [docs/en](docs/en/introduction.md).
## Versioning
This library follows [Semver](http://semver.org). 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](http://github.com/silverstripe-labs/silverstripe-tagfield/issues) for any bugs you've found, or features you're missing.