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

SS3: Open Data Grid in popup


Go to End


3 Posts   2541 Views

Avatar
Fraser

Community Member, 48 Posts

18 July 2012 at 10:52am

Edited: 18/07/2012 11:52am

I have upgraded a site to SS3 from 2.4 and implemented a datagrid to replace an ImageDataObjectManager following this tutorial: http://www.inforbiro.com/blog-eng/silverstripe-gridfield-tutorial/

Everything is working fine, however I need it to open in a pop up in the cms as currently every time you upload a new image, you have to go back to the main page, then click on the image tab, then click Add image and then go through the process.

I tried adding (from http://www.silverstriperesources.com/articles/using-the-silverstripe-3-gridfield/):

$gridFieldConfig->addComponent($gridFieldForm = new GridFieldPopupForms());		
$gridFieldForm->setTemplate('CMSGridFieldPopupForms');

But this is giving me an error: Class 'GridFieldPopupForms' not found.

I am using 3.0.0. The GridFieldPopupForms class does not exist in /sapphire/forms/gridfield/GridFieldPopupForms.php as the docs state.

My full code:

SliderImage.php

<?php
 
class SliderImage extends DataObject {
 
  	static $db = array (
		'Title' => 'Varchar',
		'ImageLink' => 'Varchar'
	);

  	static $has_one = array ( 
		'Home' => 'Home', 
	 	'SliderMainImage' => 'Image' 
	);
 
	public static $summary_fields = array(
    	'Title' => 'Image Title',
    	'ImageLink' => 'Link for the image'
  	);
 
  	public function getCMSFields_forPopup() {
 
	    $imageField = new UploadField('SliderMainImage', 'Image');
	    $imageField->allowedExtensions = array('jpg', 'png', 'gif');
	 
	    // Name, Description and Website fields
	    return new FieldList(
	    	new TextField('Title', 'Title'),
	     	new TextareaField('ImageLink', 'Link for the image'),
	      	$thumbField
	    );
	}
}

Home.php

public static $has_many = array(
		'SliderImages' => 'SliderImage'
	);
	
	function getCMSFields() {
		$fields = parent::getCMSFields();
		
		
		$gridFieldConfig = GridFieldConfig::create()->addComponents(
	    new GridFieldToolbarHeader(),
	    new GridFieldAddNewButton('toolbar-header-right'),
	    new GridFieldSortableHeader(),
	    new GridFieldDataColumns(),
	    new GridFieldPaginator(10),
	    new GridFieldEditButton(),
	    new GridFieldDeleteAction(),
	    new GridFieldDetailForm()
	    );
	    
	    $gridFieldConfig->addComponent($gridFieldForm = new GridFieldPopupForms());		
		$gridFieldForm->setTemplate('CMSGridFieldPopupForms');
	    
	    $gridField = new GridField("SliderImages", "Slider Images:", $this->SliderImages(), $gridFieldConfig);
	    $fields->addFieldToTab("Root.Slider", $gridField);
		
		return $fields;
	}

Avatar
Thomashv

Community Member, 35 Posts

26 July 2012 at 9:54am

Hi Fraser,

Good question. Did you find a solution for this? I don't get this to work either. It would have been fine not having to go back everytime you ad a new row to the gridfield.

Avatar
Hattori

Community Member, 20 Posts

28 July 2012 at 6:47am

http://www.silverstriperesources.com/articles/using-the-silverstripe-3-gridfield/

Note: I'm currently working with an early pre release version of Silverstripe 3, and the code here is a start point and not everything works.

GridFieldPopupForms has been removed in the SS3 Stable release