This has been long coming and would grant a lot of functionality for free without being particularly difficult (hopefully).
Step 1 is to use functions for dealing with entities instead of nodes. Step 2 is to provide a way to specify (maybe in the FIll PDF link?) which entity type is being used (if it isn't node).
This needs some more thinking but definitely needs to be done at some point. Only officially supporting nodes, but doing it via entity functions is goal #1.
| Comment | File | Size | Author |
|---|---|---|---|
| #82 | interdiff_70_81.txt | 698 bytes | wizonesolutions |
| #82 | 1526452_fillpdf_add_entity_support_81.patch | 49.73 KB | wizonesolutions |
Comments
Comment #1
wizonesolutionsThis is extremely important for 7.x-2.x. Time to end the module's dependency on "nodes and webforms."
It should still have the same level of integration with nodes and webforms, but if it can be done in a reusable way, that would be better.
One question then becomes how context would be established for other entity types. How would Fill PDF Links work? Would it be something like
fillpdf/<entity type>/<bundle>/<entity IDs>/<secondary IDs>(assuming a post-#1517652: [PP-1] Increase redirectability of Fill PDF URLs link style)?What if there were even more than two sets of IDs needed for the entity in question? Would I need an additional separator, e.g.
:, to separate groups of IDs? What if additional properties were needed? What if additional properties were needed but not additional IDs? What if additional something-I-haven't-thought-of...s were needed?There is a lot to think about. Maybe the link format could be
fillpdf/<entity type>/<bundle>/<entity IDs>[:<secondary IDs][:<tertiary IDs, etc...>]/<additional attribute 1>[:<additional attribute 2, etc.>I'd probably need info hooks of some sort to define how the link was processed and allow other modules to extend that.
What would those look like? This one needs some more speccing out for sure. I need to go through the Entity API (and Entity module, probably) and understand what's available and what kinds of things implementing modules do (Commerce, Rules, Field Collection would be good ones to look at). It would also be good to look at modules that consume entities, such as Computed Field Tools.
Comment #2
spidermanFWIW, I've rolled up a simple patch to handle my use-case for filling a PDF from Commerce Coupon entity values. This patch is based on the 1.9 release of FillPDF, patched with the following:
Apologies for this, it's what I'm running and testing for my site- the first two of these are in the -dev branch already, though, so hopefully this isn't too hard to apply. I've used the entities=<type>:<id> format for parsing the URI, and tried to mimic the support for multiple entities that fillpdf provides for nodes and webforms. In my case I only have one coupon at a time, however, so I haven't really tested this piece.
The key bits of code here are in fillpdf_parse_uri() to look for the 'entities' key in $_GET, and then extract entity type/id info from that, and in fillpdf_merge_pdf(), where I do an entity_load() and a token_replace() to replace entity-based tokens for each pdf field. Aside from that, there's just a small fix to the _fillpdf_admin_token_form() helper routine (introduced in the webform 4.x patch mentioned above) to lookup a list of entities and provide their tokens in the PDF Field editing interface.
Anyway, hopefully this gives an idea of the complexity of implementing entity support in FillPDF. It seems to me, from this experiment, that it should be possible to get a reasonably general solution working in the 2.x branch without much trouble.
Comment #3
wizonesolutions@spiderman: Thanks for the patch. I want to look into integrating this soon — potentially as-is, but I wanted to ask if you can recommend how I might test it starting from a vanilla Drupal instance. What are some common entities from which I might want to populate PDFs? I guess I could even just populate nodes using the entities. What is the link format? (I will have to add documentation for this.)
Comment #4
newmediaist commentedNot spiderman, but in response to your question - installing Commerce Kickstart ( https://www.drupal.org/project/commerce_kickstart ) is probably a great starting point from the testing perspective, as B) Drupal Commerce is entity based, and a natural fit with the FillPDF module B) it's basically a 1 click install, so you won't get bogged down on that side of things.
Comment #5
newmediaist commentedAlso, I've updated @spiderman's patch to be compatible with 7.x-1.10 , but discovered that it does't allow for both nodes and entities to be used to populate the contents of a PDF, when I have a moment I am going to investigate if that is an easy fix.
Comment #6
newmediaist commentedComment #7
cmcintosh commented@spiderman if you can reroll your patch against a git branch instead of local copies. ATM I cant apply your patches to any of the branches in the repo. If you let me know which these apply to that would be helpful.
For now Im going to proceed on a slightly different path. Ill create a sub-module FillPDF Entity that will add integrations for Entities.
Comment #8
cmcintosh commentedOk so I went with a slightly different direction. I created a Sub-module called fillpdf_entity. This module relies on the core module, token, and entity_token to do its thing. It adds a menu tab onto the Entity settings page(s) that you can upload a pdf to. This is respective of both Entity Type and Bundle, so this could allow a very flexible setup.
At the moment I purposely have excluded Nodes as I did not want to create confusion, but I hope this can be the start of a rewrite for the module as things seem quite cluttered. I would like to have the module rewritten to fully support Entities(Rather than Direct DB schema) and Field API.
Comment #9
wizonesolutionsThanks for the contributions, all. I don't yet see myself making huge changes to the D7 module (without help). HOWEVER, the D8 version has already been rewritten with full entity support. So things will be better at some point. I'll look at the patches here in a couple weeks (I'm heads-down focusing on getting a lot done by the 8.0.0 release date for #d8cx).
The biggest help I need, as per the project page, is automated tests. I'm squeamish about refactoring too much otherwise because each release inevitably breaks something.
Comment #10
cmcintosh commentedUpdate from my last patch file. This one adds a Rule action that will generate a Managed File from a entity.
Comment #11
wizonesolutionsJust FYI that the D8 version has entity support built-in, though it doesn't have all the features being discussed here. So leaving this open, and I'll look more at the patches to determine what's different and update the issue title accordingly.
Comment #12
wizonesolutionsComment #13
spidermanI've re-rolled my patch from the above comment #1526452-2: Support entities instead of nodes against the 7.x-1.10 release of FillPDF which incorporates 2 of the related patches needed then, but still requires the (now updated) patch from this issue:
* #2408735: Using FillPDF from Drush or command line PHP script
This was a pretty straightforward port up to the latest version of the module, and still takes the original approach, which is the same as the new Ubercart compatibility code I see in the 1.10 release. Unfortunately this is the easiest way forward for our site right now, though I'd love to see a proper backport of the d8 version of the module, of course :)
Comment #14
liam morlandComment #15
wizonesolutionsAlready done in D8. If you are interested in backporting, @Liam Morland, you can change the status appropriately.
Comment #16
wizonesolutionsActually, I will do that since there are unresolved patches in this issue.
Comment #17
liam morlandThanks.
Comment #18
wizonesolutionsNot planning to look at this this month, so unassigning. But as I recall, #13 was a fairly reasonable patch.
Comment #19
jlamp commentedUpdated patch in #13 to work in 7.x-1.12 . Unfortunately it does not cleanly apply to the latest 7.x-2.x dev branch due to API changes, and I just don't have the time at the moment to work on it further.
Comment #20
liam morland7.x-2.x has been withdrawn. Only 7.x-1.x is maintained for Drupal 7.
Comment #21
jlamp commentedThanks, sorry for my confusion, lol. That does make it a good bit easier.
Here's a new patch, to fix the missing arg in #19.
Comment #22
jlamp commentedHere's a newer patch. I found out that token replacements were not working on the filenames for entities, this addresses that.
Comment #23
liam morlandReading the patch, it looks fine. I noticed a couple of coding standards issues; please run a check on it. I would like to see a review from someone who is using this. It would be great for the patch to include some tests.
Comment #24
liam morlandComment #25
jorditr commentedHi Liam,
I'm trying to use those patches for filling PDFs from entityforms, in my case embeded on a node from paragraphs.
I've patched the module first with "cmcintosh" proposal and after restarted again patching with last "jlamp" proposal. Both look equally interesting but what I can't manage to understand is how the URL for click-and-build-pdf buttons should be constructed. Anyone could explain that?, because I can't get how to tell which kind of entity I want to open and which parameter name i should use for the corresponding ID, something like:
Thanks in advance!
Comment #26
liam morlandI think you want something more like:
/fillpdf?fid=1794&entity=10Comment #27
jorditr commentedThanks for answer Liam, but that way I've got:
on that code:
Comment #28
jorditr commentedNow I realize that I don't know if you are telling me that this is the path that already works or if you are just making a proposal...
In any case, regarding your URL /fillpdf?fid=1794&entity=10, how is the system capable to know which entity are we requiring with that "entity=10" ID ??
Comment #29
liam morlandI got that from quickly reading the patch. Search in the patch for "query_string".
Comment #30
jorditr commentedOk, I've used "/fillpdf?fid=1794&entities=10" according the code part that you mention and now no error pops up, and even it downloads a PDF file, but empty... fields are not filled...
So, I insist, how does FillPDF know that we are requiring data from an entityform and not from other kind of entity? and bundle?
Comment #31
liam morlandI don't know. I didn't write the patch. It should be possible to determine my reading the code.
Comment #32
jorditr commentedWell, I can't see on the #22 patch where do we select the type of entity and bundle...
Comment #33
cmcintosh commentedIt has been a bit since i looked at this, I will reread the code and provide some suggestions how to use it.
Comment #34
liam morlandI just read #27 again. The snippet of code looks like it is identifying entities by "type:id", splitting on the colon to get $type and $id. Give that a try.
It should have better error handling. When a colon is not provided, it should at least behave like other not-found situations.
Comment #35
jorditr commentedHmmm, thanks Liam, I'll try that.
Comment #36
jorditr commentedI've tried but again I'm not sure about which query it's needed: "?fid=1794&entities=entityform:90" ?? or "?fid=1794&entities:90" ?? I've tried both without any success.
Comment #37
liam morlandI would try
?fid=1794&entity=entityform:90.Comment #38
jorditr commentedWow! it works!! Thanks :-)))))))
Comment #39
liam morlandThis line:
$parts = explode(':', $e);Should be:
$parts = explode(':', $e, 2);This line:
$id = $parts[1];Should be:
$id = isset($parts[1]) ? (int) $parts[1] : NULL;An error should be raised later when $id is null.
Comment #40
jorditr commentedHi. I had to spend my time on other projects and finally I'm back to finnish that. I'm fillng properly PDF forms with values from the entity form, except for select fields, checkboxes and email fields. Select fields or checkbox are not reflected on the form, and email field is printed with "a mailto" tags. Is there a way to call those values?
Comment #41
liam morlandTo set things like checkboxes, the component value needs to be set to the value that the PDF is expecting. It could be something like "On". You can use
pdftk dump_data_fieldsto get these values.Comment #42
miksha commentedI needed this feature and I am glad I have found this page. I first tried cmcintosh's solution but couldn't apply second patch #10 after applying #8 successfully.
Solution from #13 works great, but after applying that patch (fillpdf-entity-support-1526452-2.patch) to latest 1.14 version, I now have problem that tokens inside Title field for generated PDF, are stripped and ignored e.g.
[entityform:created:medium].pdfbecomes
entityformcreatedmedium.pdfWith every other token happens the same.
Can someone help me with this problem? Thank you.
Comment #43
wizonesolutionsIf you attach your broken patch (after manually fixing the latest), it might help one of the patch authors guess what is wrong.
Comment #44
miksha commented@wizonesolutions I guess I jumped to conclusion on this one. Even without the mentioned patch (I removed it) I am having the same situation that tokens are not working only for pdf file name title field. Behavior is the same as I already described. I have already looked at fillpdf.module at the few important functions but still haven't found the cause.
Comment #45
wizonesolutionsSounds like it might be more of an issue with EntityForm or another module? FillPDF has fairly good token replacement tests, but they are not failing. It’s possible there is an edge case, and I’m open to that, but I wouldn’t know where to start. Are you able to reproduce this on a clean Drupal installation? Steps to reproduce would help investigate closer :)
Comment #46
liam morlandPlease make a new ticket for the token issue.
Comment #47
miksha commented@wizonesolutions I will first test on clean Drupal install (the same version of core and module) to see if token replacement works as intended and if it works, I will then add one by one of the other modules I use that could probably make problem.
@Liam Morland Thank you. If I encounter the problem again I will open a new ticket.
Comment #48
miksha commentedWhat I have found is that I have only functional version that works with Entityform by using fillpdf 1.10 with spiderman's patch. Other patches e.g. for fillpdf 1.12 even though they apply cleanly produce empty pdf fields. The problem with all of the patches is the same considering pdf generated file title token replacement - it doesn't work. Within spiderman's patch there is custom token replacement and I suppose it messes with token replecement for title field or maybe it disables it.
I was trying to manually re-implement entity support with current 1.14 dev but still haven't worked out valid solution. Until then I will use version 1.10, but that version also has title token replacement problem, and doesn't load all of the tokens e.g. date etc.
@wizonesolutions Do you maybe have time to deal with implementation of entity support? FillPDF is a great module and entityform stands side by side with webform as form solution, and I think it should be great if fillpdf for Drupal 7 would support entities in general by default. You have greater knowledge of the fillpdf code, and patch for 1.12 is almost compatible with current 1.14 dev (I don't know why it fails to produce token replacement yet).
I also think that path format that uses &entities=entity_type:nid is great but it could also be made like &entities[type]=entityform&entities[nid]=6 to be compatible with the rest of the solutions.
Thank you.
Comment #49
wizonesolutionsRe-tested #22, and that failed for some reason, but it applies fine locally. I am going to port the tests from D8 (I might need some additional ones since entity token support works a bit differently in D8 and is baked-in) and then make them work the same way.
@miksha, I probably won't add the format (I've never liked it), but for single entities I will support
entity_type=node&entity_id=1. I might, though (in which case I would also add it to D8).It would be ideal to ultimately remove direct node integration and rely on the Entity API in D7 as well in general.
However, that would have to be in a new major version.
Hopefully, I will have some progress on this tomorrow.
Comment #50
miksha commented@wizonesolutions That is great news that you are wiling to support this fully. I noticed that patch #22 didn't implement rest of the functionalities like to check for permissions etc.
Considering path format I agree with you that it would be best to stick with uniform path pattern like for the rest of the content types.
I am available and willing to test your patch when you complete it. Thank you.
Comment #51
wizonesolutions@miksha Yes, exactly. There's still some work to be done. I've been working on adding failing tests first for the various cases. Then I can make them pass by implementing the functionality.
Most of them are for filling in entities, but I will also have one to ensure filename generation works properly with entities and that entity access works properly.
I also have to add the default entity configuration options to the FillPDF form options (like default node; those fields exist in D8, so they should here too). I think that in this case I'm going to reuse the default NID as the entity ID, however; that way, I don't have to handle the case where they have both set (in D8, everything in entities, there are only default entity type and entity ID fields.
So let's see how far I get by Saturday. I will post an unfinished patch with what I have so far in case anyone wants to continue before I do (probably Friday).
Comment #52
wizonesolutionsIncomplete patch. See
//TODO:notes (which are also incomplete, since I've been working on the tests and not finishing the implementation until I have all the failing tests done). I tried to add some detail on what I was planning to do to the TODO's.Comment #53
miksha commentedJust to add if it matters. Token browse loading is very slow with spiderman's patch for FillPDF v1.10. With later version it loads fast like on any Drupal page that supports tokens and loads complete list of tokens.
Comment #54
wizonesolutions@miksha, entity tokens tend to cause that to happen, as there can be a lot of them. Sometimes using Token Tweaks to set the depth can help, although then you don't see all of them.
Re. progress on this patch, I'm fairly close. Currently getting most of the tests to pass, then I will add support for default entity type (new DB field), add another test for image filling with entity image fields, and do some manual testing. There were quite a few tweaks to make.
Comment #55
wizonesolutionsAlright! The new and improved patch is ready. I'm ready for people to test this out. Testers need to run database updates, as it adds a
default_entity_typefield to{fillpdf_forms}.On top of the original one, it also provides:
- automated tests for all new functionality and fixes
- support for image fields on entities too
- default entities for forms (like default NIDs, but for entities)
- consistency with the Drupal 8
entity_ids[]=node:3format. The way this patch originally implemented it still works, but it won't be documented- a functional option to redirect directly to the file (it was broken again)
If I ever try making a 7.x-4.x (I'd probably jump straight to match minor versions with 8.x), I plan to document entities as the default way to use FillPDF and remove references to
nid/nids[]. But that's for the future. Given that Drupal 8 is where it's at, I'm unlikely to do any more big cleanups of the D7 module, at least alone. And that would be another issue anyway.Please test manually and let me know if you run into any issues. As long as I don't hear anything bad back soon, I plan to merge and release this (perhaps as a release candidate first).
Comment #56
wizonesolutionsObligatory second comment with actual patch.
Comment #59
wizonesolutionsComment #60
wizonesolutionsThat does not fail locally. There's probably something different in testbot's URL. Adding more detail to the assertion to try to figure out what it is.
Comment #62
wizonesolutionsThat didn't tell me much. Let's try this.
Comment #64
wizonesolutionsTESTBOT: What's a clean URL?
ME: I see your lack of clean URLs and raise you testbot-specific workaround!
The good thing is that the code is actually working fine; it's the assertion part that was the issue.
Comment #65
wizonesolutionsOh yeah, I threw in some variable name changes there because tests are failing on Postgres (the table names get too long). Nothing FillPDF-specific, but it would be nice to clear up that noise. They must already be shorter in D8 because Postgres is fine there.
Comment #67
wizonesolutionsUmm, I don't get why that failed. It passes locally. I guess I'll just try it again (with some additional tweaks I made)?
Comment #69
wizonesolutionsOh, it wasn't passing locally. I was running the wrong test. I guess it's late.
It was really hard to try testing this like testbot locally because of an unrelated bug in Drupal (and the fact that I don't have DrupalCI set up locally).
So I hope this code is right this time.
Comment #70
wizonesolutionsOK, this one's ready to test manually! Remember to apply it against 7.x-1.x-dev.
Uploading one more patch where I remove some unneeded testing code that I missed getting into the last one.
Comment #71
wizonesolutionsComment #72
miksha commentedHello. Thank you for the patch. I read through the code to see the changes. Then I have uninstalled the previous version 1.10 that worked well with entityform except for the title token problem, and installed current dev patched with this patch.
On the Edit PDF page I got new "Default Entity Type" field and chose "Entityform Submissions" and didn't setup "Default Node ID" because edit link for my entityform form is string. I don't know how to get NID for entityform. Also "Deafult Node ID" field has some character size limit.
Where used to be FID as integer now stands [$fid], but hovering over above link "See which fields are which in this PDF." shows the real FID, and it is also visible inside here /fillpdf?fid=113&nid=10
I called pdf creation like this /fillpdf?fid=113&entity_ids[]=entityform:99 and got properly filled pdf file that has filename generated from tokens.
So, for now I can say it works. I will test it further. Also permissions are checked. Link becomes /fillpdf?fid=113&entity_ids[]=node:99 so entityform gets changed to node, and entering the new link again gives access denied.
Thank you very much for taking care of this issue, I think it was generally important.
Comment #73
wizonesolutions@miksha Thanks for testing. That's strange if you saw "Default Node ID"—when the entity token module is enabled (which it should be for entity support to work properly), you should see "Default Entity ID". Did it work even without entity_token enabled? Not by design, but interesting if so :)
Anyway, that link format looks correct, and yes, access is checked using the proper functions. This was part of the automated testing I did.
If I don't hear any complaints, I'll commit and release this after a week or so. After release, I will need to update the documentation. If you have any time and want to start on that, anyone can edit it. I would just link to this issue and say that it only works with this patch. And then when I do the final revision at release time, I can remove that.
All that said, one more quick test (maybe @JordiTR if you have time?) would be great.
Comment #74
liam morlandI usually wait two weeks after the last issue is marked "fixed" before issuing a release candidate and then I wait until the -rc is two weeks old with no release-blocker issues having been identified before making the full release.
Comment #75
wizonesolutionsThese changes are fairly well-tested and regression-tested, so I wonder if we really need a full month before a new stable. Two weeks seems low-risk enough for me (RC once committed to dev, then wait two weeks). From experience, few people will actually test the dev release anyway (or report bugs against it).
People tend to report new bugs either immediately after a release or months later anyway.
Comment #76
liam morlandNo doubt, what I suggest is conservative. I don't mind if the -rc goes out sooner than the two weeks. I do think it is important for the -rc to be two weeks old before a full release.
Comment #77
miksha commented@wizonesolutions You are right, it was my mistake it is not "Default Node ID", but "Default Entity ID" and I have Entity Token enabled.
As I used to have version 1.10 until this patch, in that version FID was printed as integer and it was convenient for admin to just go to edit page and directly see FID to be used in link creation. Then later that line wasn't wrapped within t() function. I suggest that you add double quotes on the line 422 of the current dev like:
'#description' => t("Form ID: [$fid]. Populate this form with node IDs, such as @example<br>", array('@example' => $entity_mode ? "/fillpdf?fid=$fid&nid=10" : "/fillpdf?fid=$fid&entity_id=node:10")),so that FID is again visible on Form Info after "Form ID:".
Also help text suggest to populate only with node IDs but it actually needs to be populated with entity type (if default not chosen) and NIDs. I have also tested pdf creation when default entity type is not chosen and also not given within link and then I got access denied on the page. Both creation with default entity type chosen and not given inside link, and if it isn't chosen and given inside link works properly.
Other than these comments I don't have any bugs to report. Token replacement works fine both in title and pdf fields. Token browser loads faster than with 1.10 version and has all available tokens in the list.
One more time, thank you for supporting entities within this great module.
Comment #78
wizonesolutions@miksha Ah, that is a good point. I hadn't noticed that I used single quotes there. I'll try to make the message clearer.
However, the separate entity_type is actually unnecessary in most cases and only works for single entities. After all, entity_ids[]=node:10 includes the entity type. That might have been what you meant anyway. This will all be in the documentation, so I'm not trying to explain every case there.
I appreciate you taking the time to give detailed feedback, and I'm glad everything works.
Comment #79
miksha commentedI don't know if it has any connection, but I tried to enable this patched version on another site with drush and got this error:
$data = base64_decode(drupal_json_decode($result->data)['pdf']);It's the same whether I use php 5.6 or 7.1.
Enabling module from UI goes without complaint. I am using Drush Version : 7.0-dev
Comment #80
miksha commentedConsidering drush error sorry, it was problem with drush's own php version. I set it up like this (inside ~/.bashrc) and everything works fine:
alias drush='/opt/php71/bin/php /home/user/drush/drush.php'You can delete these comments because they are not connected to the issue. Sorry.
Comment #82
wizonesolutionsNo problem. Given that this is the D7 version and all, I've decided to commit this and release an RC (once I get some time to update the 7.x documentation). Tests are passing on multiple platforms, and they are sufficiently detailed. I made the text fix; final committed patch attached. Will leave it in RC for at least 2 weeks before cutting a new stable.
Leaving in RTBC until the docs are updated.
Comment #84
wizonesolutionsThis failure makes sense because it is already committed. Back to RTBC.
Comment #85
wizonesolutionsComment #86
wizonesolutionsI have updated the documentation, and I'm satisfied with it. People are welcome to go through and fix typos or make the information clearer. (Just do it, and if I don't agree, I'll change it back or send you a message on the Discuss page.) When making changes, please check if the same text is used in the Drupal 8 version, and fix that as well if you know how to. If you don't, please leave a comment in your explanation of changes so I can look at it.
I've released 7.x-1.15-rc1 and will now update the project page. As of today, FillPDF finally has the same core features in both Drupal 7 and Drupal 8! 🎉 https://www.drupal.org/project/fillpdf/releases/7.x-1.15-rc1
Thanks to everyone who contributed.
Comment #88
liam morlandThis change has caused #3060718: Webform default_nid does not work when entity_token is enabled. I would appreciate a review of the patch there.