-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1015 from creative-commoners/pulls/5/usedontable-…
…extension NEW Extension to link file submissions to userform on the used on table
- Loading branch information
Showing
4 changed files
with
67 additions
and
5 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
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
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