SilverStripe\DocumentConverter\ImportField
DocumentImporterField is built on top of UploadField to access a document conversion capabilities. The original field is stripped down to allow only uploads from the user's computer, and triggers the conversion when the upload is completed.
The file upload has additional parameters injected. They are set by the user
through the fields provided on the DocumentImportField:
* SplitHeader: if enabled, scans the document looking for H1 or H2 headers and
puts each subsection into separate page. The first part of the document until
the first header occurence is added to the current page.
* KeepSource: prevents the removal of the uploaded document, and stores its ID
in the has_one relationship on the parent page (see the
DocumentImportField::__construct for how to configure the name of this has_one)
* ChosenFolderID: directory to be used for storing the original document and the
image files that come along with the document.
* PublishPages: whether the current and the chapter pages should be published.
* IncludeTOC: builds a table of contents and puts it into the parent page. This
could potentially replace the document content from before the first heading.
Also, if the KeepSource is enabled, it will inject the document link into this
page.
Caveat: there is some coupling between the above parameters.
Synopsis
- // members
- private static array $allowed_actions = ;
- private static $importer_class = ServiceConnector::class;
- // methods
- public void upload()
- protected File preserveSourceDocument()
- protected void writeTOC()
- protected void getBodyText()
- protected void writeContent()
- public void importFromPOST()
Hierarchy
Extends
- SilverStripe\AssetAdmin\Forms\UploadField
Members
private
- $allowed_actions
- $importer_class
Methods
protected
- getBodyText()
- preserveSourceDocument() — Preserves the source file by copying it to a specified folder.
- writeContent() — Used only when writing the document that has been split by headers.
- writeTOC() — Builds and writes the table of contents for the document.
public
- importFromPOST() — Imports a document at a certain path onto the current page and writes it.
- upload() — Process the document immediately upon upload.