Silverstripe Version: 4.4.4
Question:
So I have a dataobject (class A) with a many_many relationship (class B). I need my client to be able to create a (class A) dataobject and save it. Then using the GridfieldImportButton be able to upload a csv file that can be processed using a custom CsvBulkLoader to populate the many_many (class B) relations.
I have a CsvBulkLoader that works via ModelAdmin, but cannot get the GridfieldImportButton to work when its added to a relationship Gridfield. I have tried using ->setImportForm and also ->setImportIFrame too.
setImportForm - I tried two ways - a standard form and also a form based of the MemberImportForm as that is used by GridfieldImportButton in the Member modeladmin. Neither worked
setImportIFrame - I created a controller with form and submit function. The form appears in the modal, but on submission the submit function is never called. Code shown below:
<?php
namespace mspacemedia\sh\Controller;
use mspacemedia\sh\BulkLoaders\SHConstituentCsvBulkLoader;
use mspacemedia\sh\SH_Constituent;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\FileField;
use SilverStripe\Forms\FormAction;
use SilverStripe\Control\Controller;
class MailingConstituentImportController extends Controller
{
private static $allowed_actions = array(
'ImportForm'
);
protected function init()
{
parent::init();
}
public function index(){
$form = $this->ImportForm();
return $this->customise(['Form' => $form])->renderWith('MailingConstituentImportController');
}
public function ImportForm()
{
$fields = FieldList::create();
$fields->add( FileField::create('CsvFile', 'CSV to Import'));
$actions = FieldList::create();
$actions->add( FormAction::create('submit','Upload file' ));
$form = Form::create($this, 'ImportForm', $fields, $actions);
$form->setFormAction('submit');
return $form;
}
public function submit($data, $form)
{
//Stub submit
$this->redirectBack();
}
}
Any help would be greatly appreciated.