This bundle provides easy integration with array of strings for Symfony2. For example with this bundle, the following is possible:
$builder->add( 'tags', 'tags' );
This will perform the transformation between [ "tag1", "tag2", "tag3" ]
into tag1, tag2, tag3
and viceversa.
Installation is a 2 step process:
- Download BSPTagBundle using composer
- Enable the Bundle
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/D3r3ck/BSPTagBundle"
}
],
"require": {
"d3r3ck/bsp-tag-bundle": "v1.0"
}
}
Now tell composer to download the bundle by running the command:
$ php composer.phar update d3r3ck/bsp-tag-bundle
Composer will install the bundle to your project's vendor/d3r3ck/bsp-tag-bundle
directory.
Enable the bundle in the kernel:
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new BSP\TagBundle\BSPTagBundle(),
);
}
And you are done!
This bundle works adding the tags type into your Symfony2 form types:
$builder->add( 'tags', 'tags' );
This is particullary usefull when using a MongoDB ODM structure, because you can map a Hash
type into tags
form type.
...
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
...
class MyClass
{
/**
* @MongoDB\Hash
*/
protected $tags = array();
}
Besides, it includes a twig helper to explode the tags:
{{ MyClass.tags | tag_split }}
You can use this bundle in combination of jQuery Tags Input