CiviCRM has functionality to allow you to generate PDF letters.
The files that are being created throughout the system has a specific name depending on the nature of the file and does not provide any option to rename the file.
As such the file downloaded and the file recorded on an activity record against a contact record is always called "CiviLetter.pdf".
This makes it difficult for users to know what the letter was for.
Problem statement
The key point is not the name of the file that is downloaded to your Computer, a user can obviously always change this after it is downloaded. The problem is that CiviCRM creates an activity with the file in the activity listing and the filename of the file that is created automatically by CiviCRM is also named "CiviLetter.pdf". This makes it impossible for a user to know what the file was once it was created. There is no way for the user to change this.
Example use-case
Go to activities tab in contact detail page.
Choose Print/Merge Document from New Activity menu.
Fill the form and Proceed to download or preview the document.
The name of the file will be CiviLetter.pdf
CiviCRM will create an activity with the new CiviLetter.pdf attached
Users will not know what the CiviLetter.pdf was about after it was created and there is no way to change the name of that file as a user.
Current behaviour
The downloaded file has always the same specific name and the PDF attached to the activity always has that name.
Proposed behaviour
The postProcess method in class CRM/Contact/Form/Task/PDFLetterCommon.php can be changed such that it looks for the filename field being posted and if it does find that field then it uses the field value for naming the downloading file otherwise it uses the activity subject and even that is empty then it falls back to default 'CiviLetter'. This way the processing for the filename will be added as a work in progress and the ui for it can be added later.
Edited
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Child items ...
Show closed items
Linked items 0
Link issues together to show that they're related.
Learn more.
@shahrukh_compucorp does adding the ability to name the file on the form meet your need? When I first read this that was what I thought it would be & it seemed useful more broadly
@eileen thank you for reading and responding back yeah as far as my needs are concerned that would be sufficient but it would be needed to add to all the forms that are responsible for file downloads.
Hi @eileen jumping in here to add on from Shahrukh. Thanks for your quick response.
I completely agree with you that having this functionality across forms would be ideal. We are on a slightly tight time frame currently, with a big go-live for this particular feature. Could we start small with this (doing the form on email suggest by Shahrukh in the PR) and aim to expand this functionality across CiviCRM once we know it works and is approved by the client? That way we can get this out for the go-live and plan in the following work needed?
Yes, exactly @eileen - we will focus on 1 form first, adding a field to the PDF* form allowing for file re-naming. We'll test this with the client and then all going well we can add this field / file download functionality across civicrm where makes sense.
@shahrukh_compucorp please include this validation. File name can only be alphanumeric plus . - and _ (please in addition add a blue 'help' button at the end of the field to explain this).
@shahrukh_compucorp@fran also be careful with the email form as the CRM_Contact_Form_Task_EmailCommon might be in use in older versions but is deprecated in favour of CRM_Contact_Form_Task_EmailTrait on master
Apologies @eileen , it's the print/merge document (PDF) form we are working on. I hope that is slightly less risky than email, but is there anything we should be careful with regarding PDFs?
Ah yes. I think they are similar (we've also been thinking about a few things with print/merge documentation so great to hear you're clearing them up too). Shahrukh will cross check the Email form anyway to make sure.
@fran@eileen my understanding is that this would deal with changing the filename that is provided in the Content-Disposition HTTP header in various places, rather than actually changing existing file names in civicrm_file and on disk, correct?
I can't think of any security concerns in that case. Header injection in header() is mitigated by PHP itself, and nothing else comes to mind.
I did think a bit about whether a more generic alterHttpHeader hook or similar (basically applying the idea behind hook_civicrm_pageRun to HTTP headers) might make more sense, but no strong preference on that. This is probably more intuitive.
@pfigel yeah actually it will only be renaming the file that is getting downloaded once you click on the download button in Create pdf forms or print merge documents.
We did some quick UX testing for this feature with the proposed approach of having an additional field on the form and we had some quite negative feedback that it was confusing for users.
They raised the following points:
Users are clicking on the "download document" button without filling in the field as they are not near each other. As such they then get a validation message that the name is required which they don't like.
We do not save the contents for the field, it is only used when you download the final document.
They are confused as to why the filename is not used for preview given that it is shown always.
As such what we would like to suggest is that we have a popup that shows after the user clicks "download document" in order to allow the user to enter the file name. This is similar I guess to how MS Word would have a save screen which asks for the filename when you save the file for download.
Please see mockup below:
I'm aware that we don't have many examples of this kind of experience in Civi, but I really think this would be the best option. Would you be happy with this?
If we can get a yay or nay quickly that would really help as it appears we actually need to finalise this today
I hate to block things, but this seems to me like an odd pattern. We are piling of top of CiviCRM's odd habit of asking geeky questions to users who just want to get their work done.
I agree that CiviLetter.pdf is a bit ridiculous, and we should offer a sane default. The civiexportexcel extension does that for reports (defaults to generating a file based on the report title, timestamp, etc.)
For example, instead of CiviLetter, it could be "letter_[date]_[cid/display_name]".
Having a hook on top of that also makes sense, but it only helps a handful of developers, not 90% of our users, so we should also think about fixing the default. The hook might also need extra context, in order to be useful (entity type, entity id, context = letter/other).
We've had the concept approved over a week ago and 20h work has already gone into this - against a tight client deadline (today in fact we need to get the release out). I'm sorry but it's not really fair to start a new thread of comments late and after that time. We've just had to have another 8am call to align 2 devs / QA and PM on what to do here and to manage our release cycle. Its things like this that makes it impossible to plan any work if anything ever needs any core improvement...
Also I think that the point of the ticket is being missed.
The key point is not the name of the file that is downloaded to your Computer, a user can obviously always change this after it is downloaded. The problem is that CiviCRM creates an activity with the file in the activity listing and the filename of the file that is created automatically by CiviCRM is also named "CiviLetter.pdf". This makes it impossible for a user to know what the file was once it was created. There is no way for the user to change this.
With respect to having a better default filename - on the activity we already have the date and time of person creating it. This doesn't solve the attachment name issue which will always be generic.
As such I suggest the following:
We are about to submit a PR for the backend for this work which will allow the system to accept a parameter for the filename. This will have no impact on the user.
We will wait on doing the front end work until we get a consensus on what to show to the user. For the time being we will carry that as a customisation in the CiviCase extension so core is unaffected.
"With respect to having a better default filename - on the activity we already have the date and time of person creating it. This doesn't solve the attachment name issue which will always be generic."
The updated initial proposed behaviour makes sense and seems to do that (check a special field name, that can be used instead of CiviLetter.pdf).
Then an extension can alter it with a buildForm hook?
I understand you are under pressure from deadlines. I think it's better if we stick to a technical arguments. One person's feature is another person's bug, and I appreciate that you were able to quickly find a better solution.
It would be very helpful to have the filename exposed, and therefore to be able to write an extension to customize the file name. I also care about the downloaded file name - yes, it can be renamed but that's extra work and it adds up if you are downloading (and keeping track of) multiple files. It's also a great opportunity for errors and sending the wrong file to someone.
I understand the behavior mentioned in this thread is not, in fact, in CiviCase anymore.
Would Core be open to a patch to enable customization in extensions?
Hi @ananelson just obtained a bit more information on this. We did work on this as a customisation to the new Civicase extension that you left a comment on, but this has not been merged to the main extension. Could you pop me an email at jamie@compucorp.co.uk and perhaps we can discuss how we can get this merged to the main CiviCase extension? Best