NEW Extension to link file submissions to userform on the used on table

This commit is contained in:
Steve Boyd 2020-11-04 11:47:50 +13:00
parent 4d56a6ae7c
commit 2a47b1821e
4 changed files with 67 additions and 5 deletions

View File

@ -7,3 +7,6 @@ SilverStripe\UserForms\Model\UserDefinedForm:
SilverStripe\Assets\File:
extensions:
- SilverStripe\UserForms\Extension\UserFormFileExtension
SilverStripe\Admin\Forms\UsedOnTable:
extensions:
- SilverStripe\UserForms\Extensions\UsedOnTableExtension

View 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;
}
}

View File

@ -9,7 +9,6 @@ use SilverStripe\Forms\GridField\GridFieldConfig;
use SilverStripe\Forms\GridField\GridFieldDataColumns;
use SilverStripe\Forms\GridField\GridFieldExportButton;
use SilverStripe\Forms\GridField\GridFieldPrintButton;
use SilverStripe\Forms\GridField\GridFieldToolbarHeader;
use SilverStripe\Forms\ReadonlyField;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB;

View File

@ -255,11 +255,11 @@ en:
other: '{count} Submitted File Fields'
SINGULARNAME: 'Submitted File Field'
SilverStripe\UserForms\Model\Submission\SubmittedForm:
PLURALNAME: 'Submitted Forms'
PLURALNAME: 'Submitted forms'
PLURALS:
one: 'A Submitted Form'
other: '{count} Submitted Forms'
SINGULARNAME: 'Submitted Form'
one: 'A Submitted form'
other: '{count} Submitted forms'
SINGULARNAME: 'Submitted form'
SUBMITTER: Submitter
SilverStripe\UserForms\Model\Submission\SubmittedFormField:
PLURALNAME: 'Submitted Form Fields'