Last active
April 10, 2017 21:28
-
-
Save AndrewHaine/f2ce342b17c0b18d3950a79b0b56e09e to your computer and use it in GitHub Desktop.
Silverstripe UserForms extension for custom submission summary fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UserDefinedForm: | |
extensions: | |
- UserformsSubmissionExtension | |
EditableFormField: | |
extensions: | |
- EditableFormFieldExtension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EditableFormFieldExtension extends Extension | |
{ | |
private static $db = | |
[ | |
'ShowInSummary' => 'Boolean' | |
]; | |
/** | |
* Update Fields | |
* @return FieldList | |
*/ | |
public function updateCMSFields(FieldList $fields) | |
{ | |
$fields->addFieldToTab( | |
'Root.Main', | |
CheckboxSetField::create('ShowInSummary', 'Show In Table', ['1' => '']), | |
'Name' | |
); | |
return $fields; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class UserformsSubmissionExtension extends DataExtension | |
{ | |
/** | |
* Update Fields | |
* @return FieldList | |
*/ | |
public function updateCMSFields(FieldList $fields) | |
{ | |
$submissionSummaryFields = [ | |
'Created' => 'Created', | |
]; | |
foreach(EditableFormField::get()->filter(["ParentID" => $this->owner->ID]) as $formField) { | |
if($formField->ShowInSummary) { | |
$submissionSummaryFields[$formField->Name] = $formField->Title ?: $formField->Name; | |
} | |
} | |
$config = $fields->dataFieldByName('Submissions')->getConfig(); | |
$config->getComponentByType('GridFieldDataColumns')->setDisplayFields($submissionSummaryFields); | |
return $fields; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment