Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

how to handle thousands of subpages in admin/cms

Go to End

9 Posts   8205 Views


Community Member, 57 Posts

26 February 2012 at 8:12pm

I have similar issue.

I have News Holder and News Post. But I Have extended Blog Holder and Blog Entry respectively.
Can I change this to DataObject while inheriting from Blog Entry?

I am a designer who can manage to code with little help :)

Current Code for NewsPost is

class NewsPost extends BlogEntry {
	static $db = array (
     'GalleryImageWidth' => 'Int',
     'Featured' => 'Boolean',
     'UserPost' => 'Boolean',
	static $default_parent = 'NewsHolder';
	static $can_be_root = false;
	static $has_one = array(
		'Photo' => 'Image'
		//'Gallery' => 'ImageGalleryPage' 
		//'GalleryImages' => 'GalleryImage' 
	static $has_many = array (
          'GalleryImages' => 'GalleryImage'

  public function init() {

    // Note: you should use SS template require tags inside your templates 
    // instead of putting Requirements calls here.  However these are 
    // included so that our older themes still work   


	function getCMSFields() {
	$fields = parent::getCMSFields();
    $fields->addFieldsToTab("Root.Content.Main", new CheckboxField('UserPost', "Post by a Member"));
	$fields->addFieldToTab("Root.Content.Main", new CheckboxField('Featured', "Featured Post"));
	$fields->addFieldToTab("Root.Content.Images", $leadImage= new ImageField('Photo', "Upload your lead image here"));
		$leadImage->setFolderName('Uploads/' .date("Y").'/' .date("m"));
	$fields->addFieldToTab("Root.Content.Configuration", $myField= new NumericField('GalleryImageWidth', 'Image Width'));
		/*$fields-> addFieldToTab ("Root.Content.Gallery", new DropdownField("GalleryID", "Gallery", 
			DataObject::get("ImageGalleryPage")->toDropdownMap(),  'Content'));*/
		$manager = new ImageDataObjectManager(
         $this, // Controller
        'GalleryImages', // Source name
        'GalleryImage', // Source class
        'MyGalleryImage', // File name on DataObject
            'GalleryImageTitle' => 'GalleryImageTitle'
         ), // Headings
         'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
         // Filter clause
         // Sort clause
         // Join clause
      $fields->addFieldToTab('Root.Content.GalleryImage', $manager); 
     return $fields;

// Function for SideBar
    function GetSidebarContent($num=3) {

      //$randomNumber = 
      $sidebarContent = DataObject::get_one("SidebarContent");

        return false;

      $contents = array();

      $contents[] =  DBField::create('Varchar', $sidebarContent->Content1);
      $contents[] =  DBField::create('Varchar', $sidebarContent->Content2);
      $contents[] =  DBField::create('Varchar', $sidebarContent->Content3);
      $contents[] =  DBField::create('Varchar', $sidebarContent->Content4);
      $contents[] =  DBField::create('Varchar', $sidebarContent->Content5);

      //return new DataObjectSet(array_rand($contents, $num));      
      return new DataObjectSet(array_slice($contents, 0, $num));   
      //return new DataObjectSet($contents);   

class NewsPost_Controller extends BlogEntry_Controller{


 * Replaces Images to a predefined max width and adds a nyroModal class to the image
 * In template use : $Content.Parse(ArticleImageParser)
class ArticleImageParser extends TextParser{
	public function parse() { 
		// match image src
		$pattern = '/<img[^>]+src[\\s=\'"]';
		$pattern .= '+([^"\'>\\s]+)/is';
			$i = 0;
			foreach ($match[0] as $m){	
				//var_dump($m); //"<img class="right" src="assets/Articles/installingsilverstripe/wampserver.jpg"
				// get original image url
				$href = preg_replace('/_resampled\/resizedimage[0-9]*-/', '',  $match[1][$i]);
				// add a tag with original image url
				$this->content	= str_replace ($m,'<a class="popImage" rel="grp-all" href="'.$href.'">'.$match[0][$i],$this->content);
			// add missing </a> tag after each image
			$this->content = preg_replace('/<img[^>]+>/', '${0}</a>', $this->content);
		return $this->content;


Go to Top