This is a followup to #3048947: Refactor HandlePdfController::populatePdf() and #3059342: Add plugin inspection to backend plugins, and a blocker for #3040901: Allow backend plugins to supply settings for the FillPdfSettingsForm.
Our FillPdfBackend plugins suffer from neither extending a PluginBase class nor using a custom Annotation type, so any changes/additions to annotations need to be resolved by the backend manager, and any changes to the interface won't be backwards compatible unless resolved in the calling code.
The second generation BackendService plugins are way better. However only a single one has been created, and it doesn't stand alone, but is called by a FillPdfBackend plugin, so just following through with converting wouldn't solve the whole problem.
After the big all-in-one conversion patch #3040901: Allow backend plugins to supply settings for the FillPdfSettingsForm got stuck, we turned to refactoring things step by step, with the aim of limiting BC layers to the minimum necessary.
We want plugins to be configurable and to contain everything that specifically belongs to them.
We also do want to support parsing and merging a PDF file that may not necessarily be contained in a FillPdfForm, but is present either as a stream or a file.
Finally, we want to switch to FieldMapping objects (and already did so in #3048947: Refactor HandlePdfController::populatePdf(), though this wasn't immediately possibly without a BC layer in HandlePdfController and an API switch on the plugins).
So our next step would be: move all BC code out of the way to a single legacy backend manager. And it turned out that this is possible, avoiding any changes to legacy plugins we still want to support, while leaving us maximum freedom on defining new plugins, see the forthcoming patch.
Manual testing steps
For each backend:
- Configure the backend being tested.
- Parse a PDF with it; ensure fields are detected.
- Generate a sample PDF with it; ensure fields are detected.
- Recommended: if the backend supports image stamping, parse a simple PDF with a Button field and map an image to it. Set a default entity with an image field, fill from it, and make sure an image appears.
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | fillpdf_fix_javabridge_bc_18.patch | 1.13 KB | wizonesolutions |
| #13 | 3060086_12-13_interdiff.txt | 651 bytes | pancho |
| #13 | fillpdf_introduce_pdfbackend_plugins_3060086-13.patch | 67.63 KB | pancho |
| #12 | 3060086_11-12_diff.txt | 4.59 KB | pancho |
| #12 | fillpdf_introduce_pdfbackend_plugins_3060086-12.patch | 67.52 KB | pancho |
Comments
Comment #2
panchoHere's a first patch.
I managed to handle legacy plugins using the nifty
FallbackPluginManagerInterfacetogether withhandlePluginNotFound(), so there’s no need of any switch whatsoever (and #3046530: Revert: Add experimental sub-module to switch between BC and Next API may be reverted, yay!)Note that I duplicated all backends so we can manually test and compare both that original legacy and the converted plugin. Local and manual tests on pdftk and LocalServer were passing, and so far it seems they're working exactly the same, proving we're still 100% BC. We'd still need a manual test with legacy local and FillPDF Service though.
Next step I'd be removing the duplicates.
Comment #4
panchoVery minor deprecation warning. Ready for review.
Comment #5
panchoNote that similarity of some classes is too low, so git sees a deleted and another new file rather than a changed/renamed one. I will try to break it into two commits, so git can follow.
Comment #6
panchoAssigning for review and (manual) testing on FillPdfService and custom API uses.
Comment #7
wizonesolutionsComment #8
wizonesolutionsThere was a bug in FillPDF Service image filling; I think the wrong code from before got pasted, or something. Anyway, there's a particular array format that the XML-RPC call expects. It's even used properly in the legacy plugin. Fixed in new patch. Will test this tomorrow for BC against my implementation that currently uses LocalService directly.
Comment #9
wizonesolutionsConfirmed parsing works for FillPDF Service. Now checking that my code that uses the LocalService BackendService still works with this patch. I'll likely just leave it alone and port it to the new plugin type later on.
Comment #10
wizonesolutionsThe BackendService LocalService BC layer is perfect. Worked fine with my project.
I found some small things to note:
Should be
$pdfBackendJust leaving a comment in-issue to ensure this rename gets properly applied by
patch -p1(if not usinggit apply).Noticed this while reviewing the function signature. Can we a bit more specific and perhaps show a sample array? It's keyed on field names, yeah?
We could either introduce a value object that formalizes this (e.g. for those extra properties you wanted to use from PDFtk, when available)...or just document it. But as written, it's too hard for me to visualize what my plugin should be returning.
I want to run the FillPDF Service test locally one more time, and then after these tweaks, I think we're all good.
Comment #11
panchoHere's a new patch.
#10-1, #10-2: fixed.
#10-3: Returned to previous docblock. I'd like a value object here, too. But that should be a followup.
+ Many more minor improvements, standardizations, coding style, deprecations etc.
Also, git now correctly recognizes renamed files etc., so there's a little bit of noise in the interdiff, but the actual patch is smaller and less noisy.
Made sure changes from #8 didn't get lost.
All tests, both local and on DrupalCI, are passing.
Comment #12
panchoSome more tidbits. Attached a plain diff as it's easier to read in this case.
Comment #13
panchoSmall pdftk test fix.
Comment #14
panchoAll local tests passing again.
@wizonesolutions agrees we should move on, so let's move on!
Next one is going to be #3040901: Allow backend plugins to supply settings for the FillPdfSettingsForm.
Comment #16
panchoFiled #3062501: Add @trigger_error's to legacy backend plugins as a followup.
Comment #17
panchoThe JavaBridge backend needs a followup. We may not remove PluginBase from the plugin. Should receive tests, too.
Comment #18
wizonesolutionsReroll since we moved this to the
fillpdf_legacymodule.Comment #19
wizonesolutionsOh, and I think a small change like this is fine without tests. I don't really want to keep supporting the JavaBridge approach, anyway. FillPDF LocalServer has replaced it.
Comment #21
wizonesolutions