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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

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

Extend Blogs to show on diffrent page type


Go to End


1087 Views

Avatar
Skullies

Community Member, 19 Posts

29 June 2016 at 12:18am

Edited: 29/06/2016 12:32am

Good day all

I am struggling with some "logical errors" in my code I believe...
I am trying to loop the Blogs I have on my site through the CMS to a Dropdown Menu on my "IssuePage".
I have got the Blogs to show on the dropdown but I am unable to save anything.
If you guys/gals have any ideas of what I could try that would be greatly appreciated!

Here is my code:

<?php

class IssuePage extends Page{
	static $description = "A page Containing issues";
	static $singular_name = 'IssuePage';
	private static $db = array(
	);

	private static $has_many = array(
	'IssuePage' => 'IssueExtension',
	);

	 public function getCMSFields() {
        $fields = parent::getCMSFields();
		$gridFieldConfig=GridFieldConfig_RelationEditor::create(10);
		$gridFieldConfig->addComponent(new GridFieldSortableRows('SortOrder'));
		$gridField = new GridField("IssuePage", "Choose Blogs To Display", $this->owner->IssuePage()->sort("SortOrder"), $gridFieldConfig);
		$fields->addFieldToTab("Root.Blogs", $gridField);
        return $fields;
    }
		
}

<?php
class IssueExtension extends DataObject {
	public static $db = array(
	'SortOrder'=>'Int',
	'BlogPostName' =>'Varchar',
	);

	public static $has_one = array(
	'IssueExtension'=>'IssuePage',
	);

		//Build the form fields in CMS
		public function getCMSFields() {
		// Create CMS Fields	
        $fields = parent::getCMSFields();
        $fields->addFieldToTab('Root.Blogs', 
            new GridField('BlogPost', 'All Blog Posts', BlogPost::get())); 
		$fields->addFieldToTab('Root.Main', new TextField('BlogPostName', 'Post Name '));
		$fields->addFieldToTab('Root.Main',new DropdownField('IssueExtension','Select Blog Post', BlogPost::get()->map('ID')));
		$fields->removeFieldFromTab('Root.Main','SortOrder');	// Dont need to display sort order
		return $fields;
	}
	
	// Tell the datagrid what fields to show in the table
		public static $summary_fields = array( 
		   'BlogPostName' => 'BlogPostName',
	   );
       public static $default_sort='SortOrder';

}

Regards
Skullies