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.

General Questions

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

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

SS3: Open Data Grid in popup


Reply

3 Posts   1570 Views

Avatar
Fraser

18 July 2012 at 10:52am (Last edited: 18 July 2012 11:52am), Community Member, 46 Posts

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

26 July 2012 at 9:54am Community Member, 33 Posts

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

28 July 2012 at 6:47am Community Member, 20 Posts

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