mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
NEW Extension to link file submissions to userform on the used on table
This commit is contained in:
parent
4d56a6ae7c
commit
2a47b1821e
@ -7,3 +7,6 @@ SilverStripe\UserForms\Model\UserDefinedForm:
|
|||||||
SilverStripe\Assets\File:
|
SilverStripe\Assets\File:
|
||||||
extensions:
|
extensions:
|
||||||
- SilverStripe\UserForms\Extension\UserFormFileExtension
|
- SilverStripe\UserForms\Extension\UserFormFileExtension
|
||||||
|
SilverStripe\Admin\Forms\UsedOnTable:
|
||||||
|
extensions:
|
||||||
|
- SilverStripe\UserForms\Extensions\UsedOnTableExtension
|
||||||
|
60
code/Extension/UsedOnTableExtension.php
Normal file
60
code/Extension/UsedOnTableExtension.php
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\UserForms\Extensions;
|
||||||
|
|
||||||
|
use SilverStripe\Core\Extension;
|
||||||
|
use SilverStripe\ORM\DataObject;
|
||||||
|
use SilverStripe\UserForms\Model\EditableFormField;
|
||||||
|
use SilverStripe\UserForms\Model\Submission\SubmittedFileField;
|
||||||
|
use SilverStripe\UserForms\Model\Submission\SubmittedForm;
|
||||||
|
use SilverStripe\UserForms\Model\UserDefinedForm;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update DataObjects on the file "Used On" table
|
||||||
|
*/
|
||||||
|
class UsedOnTableExtension extends Extension
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Link submitted file fields to their parent page
|
||||||
|
*
|
||||||
|
* @param array $ancestorDataObjects
|
||||||
|
* @param DataObject $dataObject|null
|
||||||
|
*/
|
||||||
|
public function updateUsageDataObject(?DataObject &$dataObject)
|
||||||
|
{
|
||||||
|
if (!($dataObject instanceof SubmittedFileField)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/** @var SubmittedForm $submittedForm */
|
||||||
|
$submittedForm = $dataObject->Parent();
|
||||||
|
if (!$submittedForm) {
|
||||||
|
$dataObject = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Display the submitted form instead of the submitted file field
|
||||||
|
$dataObject = $submittedForm;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $ancestorDataObjects
|
||||||
|
* @param DataObject $dataObject
|
||||||
|
*/
|
||||||
|
public function updateUsageAncestorDataObjects(array &$ancestorDataObjects, DataObject $dataObject)
|
||||||
|
{
|
||||||
|
// SubmittedFileField was changed to a Submitted Form in updateUsageModifyOrExcludeDataObject()
|
||||||
|
if (!($dataObject instanceof SubmittedForm)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/** @var UserDefinedForm $page */
|
||||||
|
$page = $dataObject->Parent();
|
||||||
|
if (!$page) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Use an un-persisted DataObject with a 'Title' field to display the word 'Submissions'
|
||||||
|
$submissions = new EditableFormField();
|
||||||
|
$submissions->Title = 'Submissions';
|
||||||
|
$ancestorDataObjects[] = $submissions;
|
||||||
|
$ancestorDataObjects[] = $page;
|
||||||
|
}
|
||||||
|
}
|
@ -9,7 +9,6 @@ use SilverStripe\Forms\GridField\GridFieldConfig;
|
|||||||
use SilverStripe\Forms\GridField\GridFieldDataColumns;
|
use SilverStripe\Forms\GridField\GridFieldDataColumns;
|
||||||
use SilverStripe\Forms\GridField\GridFieldExportButton;
|
use SilverStripe\Forms\GridField\GridFieldExportButton;
|
||||||
use SilverStripe\Forms\GridField\GridFieldPrintButton;
|
use SilverStripe\Forms\GridField\GridFieldPrintButton;
|
||||||
use SilverStripe\Forms\GridField\GridFieldToolbarHeader;
|
|
||||||
use SilverStripe\Forms\ReadonlyField;
|
use SilverStripe\Forms\ReadonlyField;
|
||||||
use SilverStripe\ORM\DataObject;
|
use SilverStripe\ORM\DataObject;
|
||||||
use SilverStripe\ORM\DB;
|
use SilverStripe\ORM\DB;
|
||||||
|
@ -255,11 +255,11 @@ en:
|
|||||||
other: '{count} Submitted File Fields'
|
other: '{count} Submitted File Fields'
|
||||||
SINGULARNAME: 'Submitted File Field'
|
SINGULARNAME: 'Submitted File Field'
|
||||||
SilverStripe\UserForms\Model\Submission\SubmittedForm:
|
SilverStripe\UserForms\Model\Submission\SubmittedForm:
|
||||||
PLURALNAME: 'Submitted Forms'
|
PLURALNAME: 'Submitted forms'
|
||||||
PLURALS:
|
PLURALS:
|
||||||
one: 'A Submitted Form'
|
one: 'A Submitted form'
|
||||||
other: '{count} Submitted Forms'
|
other: '{count} Submitted forms'
|
||||||
SINGULARNAME: 'Submitted Form'
|
SINGULARNAME: 'Submitted form'
|
||||||
SUBMITTER: Submitter
|
SUBMITTER: Submitter
|
||||||
SilverStripe\UserForms\Model\Submission\SubmittedFormField:
|
SilverStripe\UserForms\Model\Submission\SubmittedFormField:
|
||||||
PLURALNAME: 'Submitted Form Fields'
|
PLURALNAME: 'Submitted Form Fields'
|
||||||
|
Loading…
Reference in New Issue
Block a user