anh/taggable-bundle

Taggable symfony bundle

Installs: 12 571

Dependents: 2

Suggesters: 0

Security: 0

Stars: 6

Watchers: 2

Forks: 2

Open Issues: 3

Type:symfony-bundle

v1.2.1 2014-07-18 13:54 UTC

This package is auto-updated.

Last update: 2024-11-06 09:11:21 UTC


README

Bundle provides integration of doctrine-extensions-taggable, adds form types for editing tag and tagging.

Installation

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

Example

Building form

    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'])

Rendering form

<!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>

Example

Note

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 }