Closed (fixed)
Project:
Entity Print
Version:
8.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
17 Jan 2019 at 17:00 UTC
Updated:
27 Mar 2024 at 14:41 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
tame4tex commented\Drupal\entity_print\FilenameGenerator is a service, therefore, it can be modified to suit whatever needs to you have. See https://www.drupal.org/docs/8/api/services-and-dependency-injection/alte... for help on this.
Comment #3
tame4tex commented@benjy do you think it is worthwhile creating a filename alter event that enables any module to subscribe and alter the filename based on their own set of rules?
Comment #4
benjy commentedI wouldn't be against it if that's easier than replacing the service.
Comment #5
elpino commentedI've succesfully overriden the service, and indeed it's quite easy to do.
Having said that, I do believe a filename configuration page would be really useful, specially for those users who aren't developers.
Comment #6
maacl commentedI had a use case for something similar and created an event dispatcher to alter the filename in a custom module. It works for me, but it is the first time creating something like this, and I am not fully sure I did it the right way.
Comment #7
maacl commentedSorry, not used to create patches for drupal.org yet.
Also I am wondering if this should go in a separte issue and keep the scope on using tokens here, which could then use this event.
Comment #8
jayelless commentedUpdated patch to correct the spelling of the get/set filename methods.
Comment #10
jayelless commentedMissed one. This time should work.
Comment #11
lunk rat commentedI came across a use-case for the patch in #10 and I can report that it works well and I think there is a legitimate case for committing it. For others who want to try it: Apply the patch in #10 and then in your custom module at
my_module/src/EventSubscribercreate a fileMyModulePrintFilenameSubscriber.phpwith this as a starting point:Then just add it to
my_module.services.ymllike this:Comment #12
ab2211 commentedDoes this work for the "PDF Download" at the webform submissions? I want to change the filenamee of the pdf.
Comment #13
hdbonnett commented@ab2211 - yes, this works for me to change the name of the PDF File generated. I applied the patch from #10 and created a new event subscriber as described in #11.
Comment #14
ab2211 commented@hdbonnett: I don't have a custom module. I use it with webforms. So, just patching isn't enough?
Comment #15
macdev_drupal commented#10 Works for me with webforms but I needed to load the values used for the filename from the submission.
Anyone got this working with WebformTokens too?
Comment #16
hdbonnett commentedSorry @ab2211, I just saw your comment - you do need a custom module to implement the hook. I do this with a webform in a new EventSubscriber that I attach to my webforms.
The file webform_survey_handler.services.yml contains:
Comment #17
jaydee1818 commentedThis worked for me. Thanks.
Comment #18
vladimirausThank you.
Comment #21
gngn commentedJust because I stumbled upon it: the link in #2 is truncated.
I think it should be
/docs/drupal-apis/services-and-dependency-injection/altering-existing-services-providing-dynamic-services