I originally posted the module as a response to this forum post: https://www.drupal.org/forum/support/module-development-and-code-questio...
Then people started using it and I added many improvements.
This module provides a field formatter plugin for rendering File fields and Image fields as configurable links. A submodule provides a second field formatter for rendering Media reference fields as links to the media source.
In short, the formatters have these features:
- Configurable link text with token integration
- Configurable "target" attribute
- Configurable "download" attribute
- Automatic CSS class based on file type
- Configurable additional CSS classes on link
How it's different
The file_download_link field formatter differ from core formatters for Image and File fields in that more attributes are configurable and in that the link text is much more flexible.
The file_download_link_media field formatter is clearly distinct from any core field formatter for Media reference fields. It allows a Media reference to be rendered directly as a link to the media source with several configuration options.
Project Link
https://www.drupal.org/project/file_download_link
Git instructions
git clone --branch 8.x-1.x https://git.drupalcode.org/project/file_download_link.git
PAReview checklist
https://pareview.sh/pareview/https-git.drupal.org-project-file_download_...
I consider the DrupalPractice issues to be false positives. The \Drupal calls are made to avoid a dependency on the token module. If the token module is enabled then one of its services is used. However, the module is still useful without token and I did not want to create a dependency.
I have changed how the token service gets called such that there are no \Drupal calls.
Comments
Comment #2
rksyraviHi @danflanagan8,
Thank you for contribution!!!
As you can see from PAReview, it says to use dependency injection instead of direct service call.
Comment #3
rksyraviI am changing the status to 'Needs work' after you resolve the errors, change the status to 'Need Review'.
Comment #4
avpadernoComment #5
danflanagan8Hi, rksyravi!
Thanks for starting the review process. As I wrote in the summary (I have now moved it to the end of the summary), I chose not to use dependency injection for the service provided by the token contrib module because I want to avoid having a dependency on that module. The field formatters still have several useful features even when tokens are not available.
Do you have a recommended approach to fix the errors without creating a dependency on token?
Comment #6
danflanagan8Comment #7
danflanagan8Comment #8
danflanagan8I have changed how the token service gets called such that there are no \Drupal calls. It still allows the formatters to be used if the token module is not installed. So the PAReview report is clean now.
Comment #9
danflanagan8Comment #10
avpadernoThe previous status was correct, if you fixed what reported by reviewers. Needs work means you still need to fix the code.
Comment #11
danflanagan8Oops! Thanks, kiamlaluno. I got confused. I'll switch back to Needs Review.
Comment #12
danflanagan8Comment #13
klausiThanks for you contribution!
'#title' => 'Example Token',: all user facing text must run through $this->t() for translation.$this->t('Classes:') . ' ' . $this->getSetting('custom_classes'): do not concatenate variables to translatable strings, use placeholder with $this->t() instead.Otherwise looks good to me!
Comment #14
avpadernoThank you for your contribution! I am going to update your account.
These are some recommended readings to help with excellent maintainership:
You can find more contributors chatting on the IRC #drupal-contribute channel. So, come hang out and stay involved.
Thank you, also, for your patience with the review process.
Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.
I thank all the dedicated reviewers as well.
Comment #15
danflanagan8Thank you, rksyravi!
Thank you, klausi!
Thank you, kiamlaluno!