<commit_before><?php
class TaxonomyTermExtension extends DataExtension {

	private static $api_access = true;

	private static $belongs_many_many = array(
		'Pages' => 'SiteTree'
	);

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

    /**
     * Setup the appropriate field to manage tagging for a belongs_many_many
     * relationship.
     */
    public function createReverseTagField($name) {
        $belongs_many_many = $this->owner->config()->belongs_many_many;
        if (!isset($belongs_many_many[$name]))
        {
            return null;
        }
        $className = $belongs_many_many[$name];
        $s = singleton(($className === 'SiteTree') ? 'Page' : $className);
        $visibleName = $s->plural_name();
        $field = null;
        if ($className::has_extension('Hierarchy'))
        {
            $field = TreeMultiselectField::create($name, 'Tagged '.$visibleName, $className);
        }
        else
        {
            $records = array();
            foreach ($className::get() as $record)
            {
                if ($record->canView())
                {
                    $records[] = $record;
                }
            }
            $field = ListboxField::create($name, 'Tagged '.$visibleName, $className::get()->map()->toArray())->setMultiple(true);
        }
        if ($field)
        {
            $field->setRightTitle($visibleName.' ('.$className.') using this tag');
        }
        return $field;
    }
	
	/** 
     * Set title to show in a default TreeDropdownField.
     *
     * @return string
     */
    public function getTreeTitle() {
        return $this->owner->Name;
    }

    /**
     * Default behaviour of ba-sis to only allow tagging
     * of taxonomies with parents. See 'get_source'.
     *
     * @return boolean
     */
    public function getCanBeTagged() {
        return ($this->owner->ParentID != 0);
    }

	/**
     * Get field to add/remove taxonomies applied to the data object and
     * sets up 'quickaddnew'
     *
     * @return ListboxField
     */
    public static function create_field($name, $title = null) {
        // Get taxonomies to select
        $sourceCallback = array(__CLASS__, 'get_source');<commit_msg>fix(TaxonomyTermExtension): Fix callback to be PHP 5.3 compatible.<commit_after><?php
class TaxonomyTermExtension extends DataExtension {

	private static $api_access = true;

	private static $belongs_many_many = array(
		'Pages' => 'SiteTree'
	);

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

    /**
     * Setup the appropriate field to manage tagging for a belongs_many_many
     * relationship.
     */
    public function createReverseTagField($name) {
        $belongs_many_many = $this->owner->config()->belongs_many_many;
        if (!isset($belongs_many_many[$name]))
        {
            return null;
        }
        $className = $belongs_many_many[$name];
        $s = singleton(($className === 'SiteTree') ? 'Page' : $className);
        $visibleName = $s->plural_name();
        $field = null;
        if ($className::has_extension('Hierarchy'))
        {
            $field = TreeMultiselectField::create($name, 'Tagged '.$visibleName, $className);
        }
        else
        {
            $records = array();
            foreach ($className::get() as $record)
            {
                if ($record->canView())
                {
                    $records[] = $record;
                }
            }
            $field = ListboxField::create($name, 'Tagged '.$visibleName, $className::get()->map()->toArray())->setMultiple(true);
        }
        if ($field)
        {
            $field->setRightTitle($visibleName.' ('.$className.') using this tag');
        }
        return $field;
    }
	
	/** 
     * Set title to show in a default TreeDropdownField.
     *
     * @return string
     */
    public function getTreeTitle() {
        return $this->owner->Name;
    }

    /**
     * Default behaviour of ba-sis to only allow tagging
     * of taxonomies with parents. See 'get_source'.
     *
     * @return boolean
     */
    public function getCanBeTagged() {
        return ($this->owner->ParentID != 0);
    }

	/**
     * Get field to add/remove taxonomies applied to the data object and
     * sets up 'quickaddnew'
     *
     * @return ListboxField
     */
    public static function create_field($name, $title = null) {
        // Get taxonomies to select
        $sourceCallback = function() {
            return call_user_func(array(__CLASS__, 'get_source'));
        };
{'fraction_non_alphanumeric': 0.13348855258051998, 'fraction_numerical': 0.0007760962359332557, 'mean_word_length': 1.955848623853211, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4879782', 'n_tokens_mistral': 1464, 'n_tokens_neox': 1422, 'n_words': 322}