Bundle provides integration of doctrine-extensions-taggable, adds form types for editing tag and tagging.
Install via composer with command:
$ php composer.phar require 'anh/taggable-bundle:~1.0'
Enable bundles in the kernel:
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Sp\BowerBundle\SpBowerBundle(),
new Anh\TaggableBundle\AnhTaggableBundle()
);
// ...
}
Install dependencies:
$ app/console sp:bower:install
Bundle uses SpBowerBundle for manage external assets, so installed bower is required.
Update schema:
$ app/console doctrine:schema:update --force
public function buildForm(FormBuilderInterface $builder, array $options)
{
// ...
$builder
->add('tags', 'tags', array(
'tagit' => array(/* ... */), // see https://github.com/hilobok/tag-it for available options, may be empty
'autocomplete' => 'dynamic' // default
))
;
// ...
}
autocomplete
option:
dynamic
- tags fetched dynamically via ajax (you may set custom url in['tagit']['autocomplete']['source']
) (limited to 100 tags)static
- all tags passed via attribute (limited to 100 tags)custom
- no tags will be provided from db (custom list of tags may be passed by setting['tagit']['availableTags']
)
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" />
{% stylesheets
'@anh_taggable_css'
%}<link rel="stylesheet" href="{{ asset_url }}" />{% endstylesheets %}
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
{% javascripts
'@anh_taggable_js'
%}<script src="{{ asset_url }}"></script>{% endjavascripts %}
</head>
<body>
{{ form(form) }}
</body>
</html>
Bundle automatically adds mapping for Tag and Tagging entities from doctrine-extensions-taggable. If you for any reason have to disable it put in config.yml:
doctrine:
orm:
mappings:
anh_taggable: { mapping: false }