Not a developer? Go to MovableType.com

Documentation

MT::Taggable

Movable Type comes with an easy to use tagging framework that allows any developer to attach tags to any object in the system. Once an object is designated as “taggable” then they will immediate be able to use all of the interface methods of a taggable object to get and set tags on that object.

The following methods are supported on any taggable object:

  • tags(@tags) - gets or sets an object’s list of tags. If used as a set operation, this method will replace any existing tags with the ARRAY of provided tags.

  • add_tags(@tags) - takes as input an ARRAY of tags to append to an object

  • remove_tags(@tags) - removes any tags found in the ARRAY of tags provided to the method as inpput

  • has_tag($tag) - returns true if the specified tag can be found in the associated object

  • tag_count()- returns the number of tags this object has

  • tagged_count() - returns the number of objects that share the specified tag

Inheriting from the Taggable Interface

To make an object taggable, a developer need only state that their package inherits from the MT::Taggable interface like so:

package My::Object::Model;
use MT::Tag;
use base qw( MT::Object MT::Taggable );

__PACKAGE__->install_properties({ # ... }); 1;

Using the MT::Taggable Interface

Then you get the methods in the Taggable interface on your model objects:

sub tag_awesomely {
    my ($m_id) = @_;
    my $m = My::Object::Model->load($m_id);
    if (!$m->has_tags('awesome')) {
        $m->add_tags('awesome');
    }
    $m->save();  # tags are automatically saved by the
                 # MT::Taggable::post_save_tags callback
}
Back