<commit_before><?php

class GlobalNavSiteTreeExtension extends DataExtension
{

    private static $db = array (
        'ShowInGlobalNav' => 'Boolean',
        'ShowChildrenInGlobalNav' => 'Boolean'
    );


    public static function get_toolbar_hostname() {
        return  Config::inst()->get('GlobalNav','use_localhost') ? 
                Director::absoluteBaseURL() :
                Config::inst()->get('GlobalNav','hostname');        
    }


    public static function create_nav() {        
        $html = ViewableData::create()->customise(array(
            'ToolbarHostname' => self::get_toolbar_hostname(),
            'Pages' => SiteTree::get()->filter(array(
                'ParentID' => 0,
                'ShowInGlobalNav' => true
            )),
            'GoogleCustomSearchId' => Config::inst()->get('GlobalNav', 'google_search_id')
        ))->renderWith('GlobalNavbar');

        $path = Config::inst()->get('GlobalNav','snippet_path');
        
        file_put_contents(BASE_PATH.$path, $html);        
    }    


    public function updateSettingsFields(FieldList $fields) {
        $p = $this->owner->Parent();
        if(!$p->exists()) {
            $fields->addFieldToTab("Root.Settings", CheckboxField::create('ShowInGlobalNav','Show in global nav'));
            $fields->addFieldToTab("Root.Settings", CheckboxField::create('ShowChildrenInGlobalNav','Include child pages')
                                                        ->displayIf('ShowInGlobalNav')->isChecked()
                                                        ->end()
            );
        }

        else if($p->ShouldShowChildren()) {
            $fields->addFieldToTab("Root.Settings", CheckboxField::create('ShowInGlobalNav','Show in global nav'));        
        }
    }


    public function ShouldShowChildren() {
        return $this->owner->ShowInGlobalNav && $this->owner->ShowChildrenInGlobalNav;
    }


    public function GlobalNavLink() {
        if($this->owner instanceof RedirectorPage && $this->owner->ExternalURL) {
            return $this->owner->ExternalURL;
        }

        return Controller::join_links(Director::absoluteBaseURL(), $this->owner->Link());
    }


    public function GlobalNavChildren() {
        return $this->owner->Children()
                    ->filter(array(
                        'ShowInGlobalNav' => true
                    ));
    }


    public function onAfterWrite() {
        if($this->owner->ParentID == 0) {
            $this->createNav();
        }
    }

}<commit_msg>update createNav instance method to static method<commit_after><?php

class GlobalNavSiteTreeExtension extends DataExtension
{

    private static $db = array (
        'ShowInGlobalNav' => 'Boolean',
        'ShowChildrenInGlobalNav' => 'Boolean'
    );


    public static function get_toolbar_hostname() {
        return  Config::inst()->get('GlobalNav','use_localhost') ? 
                Director::absoluteBaseURL() :
                Config::inst()->get('GlobalNav','hostname');        
    }


    public static function create_nav() {        
        $html = ViewableData::create()->customise(array(
            'ToolbarHostname' => self::get_toolbar_hostname(),
            'Pages' => SiteTree::get()->filter(array(
                'ParentID' => 0,
                'ShowInGlobalNav' => true
            )),
            'GoogleCustomSearchId' => Config::inst()->get('GlobalNav', 'google_search_id')
        ))->renderWith('GlobalNavbar');

        $path = Config::inst()->get('GlobalNav','snippet_path');
        
        file_put_contents(BASE_PATH.$path, $html);        
    }    


    public function updateSettingsFields(FieldList $fields) {
        $p = $this->owner->Parent();
        if(!$p->exists()) {
            $fields->addFieldToTab("Root.Settings", CheckboxField::create('ShowInGlobalNav','Show in global nav'));
            $fields->addFieldToTab("Root.Settings", CheckboxField::create('ShowChildrenInGlobalNav','Include child pages')
                                                        ->displayIf('ShowInGlobalNav')->isChecked()
                                                        ->end()
            );
        }

        else if($p->ShouldShowChildren()) {
            $fields->addFieldToTab("Root.Settings", CheckboxField::create('ShowInGlobalNav','Show in global nav'));        
        }
    }


    public function ShouldShowChildren() {
        return $this->owner->ShowInGlobalNav && $this->owner->ShowChildrenInGlobalNav;
    }


    public function GlobalNavLink() {
        if($this->owner instanceof RedirectorPage && $this->owner->ExternalURL) {
            return $this->owner->ExternalURL;
        }

        return Controller::join_links(Director::absoluteBaseURL(), $this->owner->Link());
    }


    public function GlobalNavChildren() {
        return $this->owner->Children()
                    ->filter(array(
                        'ShowInGlobalNav' => true
                    ));
    }


    public function onAfterWrite() {
        if($this->owner->ParentID == 0) {
            self::create_nav();
        }
    }

}
{'fraction_non_alphanumeric': 0.14210320562939796, 'fraction_numerical': 0.0007818608287724785, 'mean_word_length': 2.086248492159228, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 86, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4535563', 'n_tokens_mistral': 1328, 'n_tokens_neox': 1274, 'n_words': 206}