<commit_before><?php
class TeaserSection extends Section
{
    /**
     * Database fields
     * @return array
     */
    private static $db = array(
        'Title' => 'Text',
        'TeaserType' => 'Enum(array("List","Children"),"List")',
    );

    /**
    * Has one relationship
    * @return array
    */
    private static $has_one = array(
        'ParentPage' => 'Page'
    );

    /**
    * Many_many relationship
    * @return array
    */
    private static $many_many = array(
        'TeaserList' => 'Teaser'
    );

    private static $many_many_extraFields = array(
        'TeaserList' => array(
            'Sort' => 'Int'
        )
    );

    /**
     * CMS Fields
     * @return array
     */
    public function getCMSFields()
    {
        $fields = parent::getCMSFields();

        $TeaserConfig = GridFieldConfig_RecordEditor::create();
        if ($this->TeaserList()->Count() > 0) {
            $TeaserConfig->addComponent(new GridFieldOrderableRows());
        }

        $fields->addFieldsToTab(
            'Root.Main',
            array(
                TextareaField::create(
                    'Title'
                )->setRows(1),
                DropdownField::create(
                    'TeaserType',
                    'Type',
                    singleton('TeaserSection')
                        ->dbObject('TeaserType')
                        ->enumValues()
                ),
                TreeDropdownField::create(
                    'ParentPageID',
                    'Select a page',
                    'SiteTree'
                )->displayIf("TeaserType")->isEqualTo("Children")->end(),
                GridField::create(
                    'TeaserList',
                    'Current Teaser(s)',
                    $this->Teaser(),
                    $TeaserConfig
                )->displayIf("TeaserType")->isEqualTo("List")->end()
            )
        );
        return $fields;
    }

    public function List(){
        if($this->TeaserType == "Children"){
            $currentPage = Director::get_current_page();
            return $this
                ->ParentPage()
                ->Children()
                ->Exclude(
                    array(
                        "ID" => $currentPage->ID
                    )
                );
        }else{
            return $this->TeaserList();
        }

    }
}
<commit_msg>Added display logic<commit_after><?php
class TeaserSection extends Section
{
    /**
     * Database fields
     * @return array
     */
    private static $db = array(
        'Title' => 'Text',
        'TeaserType' => 'Enum(array("default",list","children"),"default")',
    );

    /**
    * Has one relationship
    * @return array
    */
    private static $has_one = array(
        'ParentPage' => 'Page'
    );

    /**
    * Many_many relationship
    * @return array
    */
    private static $many_many = array(
        'TeaserList' => 'Teaser'
    );

    private static $many_many_extraFields = array(
        'TeaserList' => array(
            'Sort' => 'Int'
        )
    );

    /**
     * CMS Fields
     * @return array
     */
    public function getCMSFields()
    {
        $fields = parent::getCMSFields();

        $TeaserConfig = GridFieldConfig_RecordEditor::create();
        if ($this->TeaserList()->Count() > 0) {
            $TeaserConfig->addComponent(new GridFieldOrderableRows());
        }

        $fields->addFieldsToTab(
            'Root.Main',
            array(
                TextareaField::create(
                    'Title'
                )->setRows(1),
                DropdownField::create(
                    'TeaserType',
                    'Type',
                    array(
                        "default" => "List all sub pages of this page",
                        "children" => "Specify a page and list all its sub pages",
                        "list" => "Specify each teaser"
                    )
                ),
                DisplayLogicWrapper::create(
                    TreeDropdownField::create(
                        'ParentPageID',
                        'Select a page',
                        'SiteTree'
                    )
                )->displayIf("TeaserType")->isEqualTo("children")->end(),
                DisplayLogicWrapper::create(
                    GridField::create(
                        'TeaserList',
                        'Current Teaser(s)',
                        $this->TeaserList(),
                        $TeaserConfig
                    )
                )->displayIf("TeaserType")->isEqualTo("list")->end()
            )
        );
        return $fields;
    }

    public function ListTeasers()
    {
        switch ($this->TeaserType) {
            case 'list':
                return $this->TeaserList();
                break;
            case 'Children':
                $currentPage = Director::get_current_page();
                return $this
                    ->ParentPage()
                    ->Children()
                    ->Exclude(
                        array(
                            "ID" => $currentPage->ID
                        )
                    );
                break;
            case 'default':
            default:
                $currentPage = Director::get_current_page();
                return $currentPage->Children();
                break;
        }
    }
}

{'fraction_non_alphanumeric': 0.12363904779479609, 'fraction_numerical': 0.0007381435689241557, 'mean_word_length': 1.176706827309237, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 61, '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': '4715461', 'n_tokens_mistral': 1420, 'n_tokens_neox': 1325, 'n_words': 253}