1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\Forms\GridField; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Control\HTTPRequest; |
6
|
|
|
use SilverStripe\Control\HTTPResponse; |
7
|
|
|
use SilverStripe\ORM\DataObject; |
8
|
|
|
use SilverStripe\Forms\Form; |
9
|
|
|
use SilverStripe\Forms\CompositeField; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class GridFieldImportButton implements GridField_HTMLProvider |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Fragment to write the button to |
16
|
|
|
*/ |
17
|
|
|
protected $targetFragment; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var CompositeField |
21
|
|
|
*/ |
22
|
|
|
protected $importFormField; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param string $targetFragment The HTML fragment to write the button into |
26
|
|
|
*/ |
27
|
|
|
public function __construct($targetFragment = "after", $importFormField = null) |
28
|
|
|
{ |
29
|
|
|
$this->targetFragment = $targetFragment; |
30
|
|
|
$this->importFormField = $importFormField; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Place the export button in a <p> tag below the field |
35
|
|
|
* |
36
|
|
|
* @param GridField $gridField |
37
|
|
|
* @return array |
38
|
|
|
*/ |
39
|
|
|
public function getHTMLFragments($gridField) |
40
|
|
|
{ |
41
|
|
|
$button = new GridField_FormAction( |
42
|
|
|
$gridField, |
43
|
|
|
'import', |
44
|
|
|
_t('TableListField.CSVIMPORT', 'Import CSV'), |
45
|
|
|
'import', |
46
|
|
|
null |
47
|
|
|
); |
48
|
|
|
$button->addExtraClass('btn btn-secondary no-ajax font-icon-upload action_import'); |
49
|
|
|
$button |
50
|
|
|
->setAttribute('data-toggle', "modal") |
51
|
|
|
->setAttribute('data-target', "#". $gridField->ID() . ' .grid-field-import'); |
52
|
|
|
|
53
|
|
|
$button->setForm($gridField->getForm()); |
54
|
|
|
$extra = null; |
55
|
|
|
|
56
|
|
|
if($this->importFormField) { |
57
|
|
|
$extra = ($this->importFormField instanceof Form) |
58
|
|
|
? $this->importFormField->forTemplate() |
59
|
|
|
: $this->importFormField->Field(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return array( |
63
|
|
|
$this->targetFragment => ($extra) ? '<p class="grid-csv-button">' . $button->Field() . '</p>'.$extra : '', |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* export is an action button |
69
|
|
|
* |
70
|
|
|
* @param GridField $gridField |
71
|
|
|
* @return array |
72
|
|
|
*/ |
73
|
|
|
public function getActions($gridField) |
|
|
|
|
74
|
|
|
{ |
75
|
|
|
return []; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.