1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Firesphere\PartialUserforms\Extensions; |
4
|
|
|
|
5
|
|
|
use Firesphere\PartialUserforms\Models\PartialFormSubmission; |
6
|
|
|
use SilverStripe\Forms\CheckboxField; |
7
|
|
|
use SilverStripe\Forms\FieldList; |
8
|
|
|
use SilverStripe\Forms\GridField\GridField; |
9
|
|
|
use SilverStripe\Forms\GridField\GridFieldAddNewButton; |
10
|
|
|
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor; |
11
|
|
|
use SilverStripe\Forms\Tab; |
12
|
|
|
use SilverStripe\ORM\DataExtension; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class \Firesphere\PartialUserforms\Extensions\UserDefinedFormExtension |
16
|
|
|
* |
17
|
|
|
* @property \DNADesign\ElementalUserForms\Model\ElementForm|\SilverStripe\UserForms\Model\UserDefinedForm|\Firesphere\PartialUserforms\Extensions\UserDefinedFormExtension $owner |
18
|
|
|
* @method \SilverStripe\ORM\DataList|\Firesphere\PartialUserforms\Models\PartialFormSubmission[] PartialSubmissions() |
19
|
|
|
*/ |
20
|
|
|
class UserDefinedFormExtension extends DataExtension |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
private static $db = [ |
|
|
|
|
24
|
|
|
'ExportPartialSubmissions' => 'Boolean(true)', |
25
|
|
|
]; |
26
|
|
|
/** |
27
|
|
|
* @var array |
28
|
|
|
*/ |
29
|
|
|
private static $has_many = [ |
|
|
|
|
30
|
|
|
'PartialSubmissions' => PartialFormSubmission::class |
31
|
|
|
]; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param FieldList $fields |
35
|
|
|
*/ |
36
|
|
|
public function updateCMSFields(FieldList $fields) |
37
|
|
|
{ |
38
|
|
|
/** @var GridField $submissionField */ |
39
|
|
|
$submissionField = $fields->dataFieldByName('Submissions'); |
40
|
|
|
$list = $submissionField->getList()->exclude(['ClassName' => PartialFormSubmission::class]); |
41
|
|
|
$submissionField->setList($list); |
42
|
|
|
$fields->removeByName('PartialSubmissions'); |
43
|
|
|
/** @var GridFieldConfig_RelationEditor $gridfieldConfig */ |
44
|
|
|
$gridfieldConfig = GridFieldConfig_RelationEditor::create(); |
45
|
|
|
$gridfieldConfig->removeComponentsByType(GridFieldAddNewButton::class); |
46
|
|
|
|
47
|
|
|
// We need to manually add the tab |
48
|
|
|
$fields->addFieldToTab( |
49
|
|
|
'Root', |
50
|
|
|
Tab::create('PartialSubmissions', _t(__CLASS__ . '.PartialSubmission', 'Partial submissions')) |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
$fields->addFieldToTab( |
54
|
|
|
'Root.PartialSubmissions', |
55
|
|
|
GridField::create( |
56
|
|
|
'PartialSubmissions', |
57
|
|
|
_t(__CLASS__ . '.PartialSubmission', 'Partial submissions'), |
58
|
|
|
$this->owner->PartialSubmissions() |
|
|
|
|
59
|
|
|
) |
60
|
|
|
); |
61
|
|
|
|
62
|
|
|
$fields->insertAfter('DisableSaveSubmissions', |
63
|
|
|
$partialCheckbox = CheckboxField::create('ExportPartialSubmissions', |
64
|
|
|
_t(__CLASS__ . '.partialCheckboxLabel', 'Send partial submissions')) |
65
|
|
|
); |
66
|
|
|
$description = _t(__CLASS__ . '.partialCheckboxDescription', |
67
|
|
|
'The configuration and global export configuration can be set in the site Settings'); |
68
|
|
|
$partialCheckbox->setDescription($description); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.