PHP code example of micschk / silverstripe-excludechildren

1. Go to this page and download the library: Download micschk/silverstripe-excludechildren library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

micschk / silverstripe-excludechildren example snippets


	public function HiddenChildren(){
		return SiteTree::get()->filter('ParentID', $this->ID)->sort('Sort');
	}

	public function PaginatedChildren(){
		$children = SiteTree::get()->filter('ParentID', $this->ID);
		$ctrlr = Controller::curr();
		$children = new PaginatedList($children, $ctrlr->request);
		$children->setPageLength(10);
		return $children;
	}

	class SubPageHolder extends Page {
		...
		static $extensions = array("ExcludeChildren");
		static $excluded_children = array('SubPage', 'AnotherPageType_Extending_Page');
		...

		Object::add_extension("SubPageHolder", "ExcludeChildren");
		Config::inst()->update("SubPageHolder", "excluded_children", array("BlogEntry"));

	$gridFieldConfig = GridFieldConfig::create()->addComponents(
		new GridFieldToolbarHeader(),
		new GridFieldAddNewSiteTreeItemButton('toolbar-header-right'), // GridfieldSitetreebuttons module
		new GridFieldSortableHeader(),
		new GridFieldFilterHeader(),
		$dataColumns = new GridFieldDataColumns(),
		new GridFieldPaginator(20),
		new GridFieldEditSiteTreeItemButton(), // GridfieldSitetreebuttons module
		new GridFieldOrderableRows() // Gridfieldextensions module, default 'Sort' is equal to page sort field...
	);
	$dataColumns->setDisplayFields(array(
		'Title' => 'Title',
		'URLSegment'=> 'URL',
		//'getStatus' => 'Status', // Implement getStatus() on child page class, see gridfieldpages module for an example
		'LastEdited' => 'Changed',
	));
	// use gridfield as normal
	$gridField = new GridField(
		"SubPages", # Can be any name, field doesn't have to exist on model...
		"SubPages of this page", 
        SiteTree::get()->filter('ParentID', $this->ID),
		$gridFieldConfig);
    $fields->addFieldToTab("Root.SubPages", $gridField);

	public function SortedChildren(){
		return SiteTree::get()->filter('ParentID', $this->ID)->sort('Sort');
	}

	public function PaginatedChildren(){
		$children = SiteTree::get()->filter('ParentID', $this->ID);
		$ctrlr = Controller::curr();
		$children = new PaginatedList($children, $ctrlr->request);
		$children->setPageLength(10);
		return $children;
	}