Skip to content

Commit

Permalink
Made supported
Browse files Browse the repository at this point in the history
  • Loading branch information
assertchris committed Sep 9, 2015
1 parent 4f86c02 commit d7f0206
Show file tree
Hide file tree
Showing 12 changed files with 248 additions and 88 deletions.
6 changes: 6 additions & 0 deletions .gitattributes
@@ -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 changes: 12 additions & 0 deletions .scrutinizer.yml
@@ -0,0 +1,12 @@
inherit: true

tools:
external_code_coverage: true

checks:
php:
code_rating: true
duplication: true

filter:
paths: [code/*, tests/*]
39 changes: 21 additions & 18 deletions .travis.yml
@@ -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
69 changes: 0 additions & 69 deletions README.md

This file was deleted.

9 changes: 9 additions & 0 deletions changelog.md
@@ -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 changes: 22 additions & 0 deletions code-of-conduct.md
@@ -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 changes: 3 additions & 0 deletions contributing.md
@@ -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 changes: 9 additions & 0 deletions docs/en/installing.md
@@ -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 changes: 14 additions & 0 deletions docs/en/introduction.md
@@ -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 changes: 63 additions & 0 deletions docs/en/using.md
@@ -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...
2 changes: 1 addition & 1 deletion LICENCE → license.md
Expand Up @@ -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 changes: 88 additions & 0 deletions readme.md
@@ -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.

0 comments on commit d7f0206

Please sign in to comment.