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.

Customising the CMS /

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

Customising gridField in CMS? (SS3) // SOLVED


Go to End


3 Posts   1982 Views

Avatar
LinseyM

Community Member, 99 Posts

13 May 2013 at 7:14am

Edited: 13/05/2013 7:17am

Hi there,

Since I've now realised that $gridField doesn't use "getCMSFields_forPopup()"*, how can I control my gridField to specify:

1) The upload folder for an image?
2) The title/label of the field(s) that are displayed in the CMS? (so I can can display something like: "Brand Logo (100x50px)" for the logo image field, instead of just "Logo")

Many thanks.

*despite stumbling on an online tutorial that said it did... (http://www.inforbiro.com/blog-eng/silverstripe-gridfield-tutorial/)

ps here is my code:

Data Object (Partner.php)

class Partner extends DataObject {

	// object's fields
	public static $db = array(
		'BrandName' => 'Varchar(255)',
		'OrderBy' => 'Varchar(5)'
	);

	// One-to-one relationships
	public static $has_one = array(
		'Logo' => 'Image',
		'GalleryPic' => 'Image',
		'Partners' => 'Partners'
	);

	// Summary fields
	public static $summary_fields = array(
		'Logo.StripThumbnail' => 'Image',
		'BrandName' => 'BrandName',
		'OrderBy' => 'OrderBy'
	);

	static $default_sort = "OrderBy";

}

And the Holding Page (Partners.php)


	public static $has_many = array(
		'Partners' => 'Partner'
	);


   function getCMSFields() {
   
		$fields = parent::getCMSFields();

		$fields->removeByName("RightColumn");

		$gridFieldConfig1 = GridFieldConfig::create()->addComponents(
			new GridFieldToolbarHeader(),
			new GridFieldAddNewButton('toolbar-header-right'),
			new GridFieldSortableHeader(),
			new GridFieldDataColumns(),
			new GridFieldPaginator(10),
			new GridFieldEditButton(),
			new GridFieldDeleteAction(),
			new GridFieldDetailForm()
		);
		
		$gridField = new GridField("Partners", "Brand Partners:", $this->Partners(), $gridFieldConfig1);
		$fields->addFieldToTab("Root.BrandPartners", $gridField);
			
		return $fields;
   }

Avatar
(deleted)

Community Member, 473 Posts

13 May 2013 at 8:18am

GridField, like ComplexTableField, uses the getCMSFields() method on the managed DataObject.

Avatar
LinseyM

Community Member, 99 Posts

13 May 2013 at 8:33am

OK, that worked once I figured out how to reference it (just Root.Main). Awesome. Thank you Simon. Much appreciated.

Just in case anyone is wondering:

I added the following code to the data object Partner.php


   function getCMSFields() {
   
		$fields = parent::getCMSFields();

			$uploadField = new UploadField('Logo', 'Brand Logo:'); 
			$uploadField->getValidator()->allowedExtensions = array('jpg', 'gif', 'png');
			$uploadField->setFolderName('assets/BrandPartners');
			$fields->addFieldToTab('Root.Main', $uploadField);
			
		return $fields;
   }
   
}