2016-11-30 22:07:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\Forms\GridField;
|
|
|
|
|
|
|
|
use SilverStripe\Forms\CompositeField;
|
|
|
|
|
|
|
|
class GridFieldImportButton implements GridField_HTMLProvider
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Fragment to write the button to
|
|
|
|
*/
|
|
|
|
protected $targetFragment;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var CompositeField
|
|
|
|
*/
|
|
|
|
protected $importFormField;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $targetFragment The HTML fragment to write the button into
|
|
|
|
*/
|
|
|
|
public function __construct($targetFragment = "after", $importFormField = null)
|
|
|
|
{
|
|
|
|
$this->targetFragment = $targetFragment;
|
|
|
|
$this->importFormField = $importFormField;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Place the export button in a <p> tag below the field
|
|
|
|
*
|
|
|
|
* @param GridField $gridField
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getHTMLFragments($gridField)
|
|
|
|
{
|
|
|
|
$button = new GridField_FormAction(
|
|
|
|
$gridField,
|
|
|
|
'import',
|
|
|
|
_t('TableListField.CSVIMPORT', 'Import CSV'),
|
|
|
|
'import',
|
|
|
|
null
|
|
|
|
);
|
2016-12-12 01:52:42 +01:00
|
|
|
$button->addExtraClass('btn btn-secondary no-ajax font-icon-upload btn--icon-large action_import');
|
2016-12-21 04:23:00 +01:00
|
|
|
|
|
|
|
// means that you can only have 1 import per page
|
2016-11-30 22:07:07 +01:00
|
|
|
$button
|
|
|
|
->setAttribute('data-toggle', "modal")
|
2016-12-21 04:23:00 +01:00
|
|
|
->setAttribute('data-target', "#". $gridField->getForm()->getHTMLID() . '_ImportModal');
|
2016-11-30 22:07:07 +01:00
|
|
|
|
|
|
|
$button->setForm($gridField->getForm());
|
|
|
|
$extra = null;
|
|
|
|
|
|
|
|
return array(
|
2016-12-21 04:23:00 +01:00
|
|
|
$this->targetFragment => '<p class="grid-csv-button">'. $button->Field() . '</p>'
|
2016-11-30 22:07:07 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* export is an action button
|
|
|
|
*
|
|
|
|
* @param GridField $gridField
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getActions($gridField)
|
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|