symbiote / silverstripe-seed

Symbiote Seed. A set of modules that form a solid foundation for SilverStripe website builds.
BSD 3-Clause "New" or "Revised" License
8 stars 7 forks source link

feat(TaxonomyTermExtension): Pulled out code necessary to create tag fields ba-sis style #13

Closed silbinarywolf closed 8 years ago

silbinarywolf commented 8 years ago

Pulled out code necessary to create tag fields ba-sis style so that I could easily reuse it for personal FileTaxonomyExtension, Also added functionality that allows for easy-to-use and configure reverse tagging, ie. adding pages to the tag.

Example of File extension code used in current project:

class FileTaxonomyTermExtension extends DataExtension {
    private static $belongs_many_many = array(
        'Files' => 'File'
    );

    public function updateCMSFields(FieldList $fields) {
        if ($this->owner->CanBeTagged)
        {
            $field = $this->owner->createReverseTagField('Files');
            if ($field)
            {
                $fields->removeByName($field->getName());
                $fields->addFieldToTab('Root.Main', $field);
            }
        }
    }
}
<?php

class FileTaxonomyExtension extends DataExtension {

    private static $many_many = array(
        'Terms' => 'TaxonomyTerm',
    );

    public function updateCMSFields(FieldList $fields) {
        $fields->addFieldToTab('Root.Main', TaxonomyTermExtension::create_field('Terms', 'Terms'));
    }
}