Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented file tokens for bulky items #375

Merged
merged 7 commits into from
Nov 25, 2024
Merged

Conversation

Toflar
Copy link
Member

@Toflar Toflar commented Nov 18, 2024

This implements a general listener for all bulky items.

For example, if you have a ##form_upload## field with an associated bulky items voucher, you will now automatically also get a ##file_item_html_form_upload## and ##file_item_text_form_upload## token.
You notice, the format is: file_item_<format>_<tokenName>.

The contents of those are defined by the new @Contao/notification_center/file_token.html.twig template which you can adjust. By default it will generate the following outputs:

For text:

- [test.png (10,9 KiB)](https://example.com/notifications/download/20241119/58161a5d-9e87-4fc8-839b-5ccfb1fa2aca?_hash=foobar)
- [test__2.png (10,9 KiB)](https://example.com/notifications/download/20241119/654bd791-3ff7-4480-8f75-801387178d16?_hash=foobar)

For html:

<ul>
  <li><a href="https://example.com/notifications/download/20241119/58161a5d-9e87-4fc8-839b-5ccfb1fa2aca?_hash=foobar">test.png (10,9 KiB)</a></li>
  <li><a href="https://example.com/notifications/download/20241119/654bd791-3ff7-4480-8f75-801387178d16?_hash=foobar">test__2.png (10,9 KiB)</a></li>
</ul>

You may adjust the @Contao/notification_center/file_token.html.twig according to your needs. You get the file items, the format but also the entire Parcel as template context in case you need to do anything complex.

The Twig template uses a notification_center_file_url() method that generates the URL to the file. It takes an optional 2nd parameter for $ttl in case you want to limit the downloads to a certain expiry date which I don't think is a requirement by default.

Implemented helper methods for gateways to automatically convert file tokens into download URIs.
@Toflar Toflar changed the title [WIP] Implemented downloadable file tokens Implemented file tokens for bulky items Nov 19, 2024
@Toflar Toflar marked this pull request as ready for review November 19, 2024 13:56
@Toflar Toflar merged commit 3159901 into 2.2 Nov 25, 2024
8 checks passed
@Toflar Toflar deleted the feature/improve-file-handling branch November 25, 2024 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant