- Install the Media Entity Download module.
composer require drupal/media_entity_download
- Create a FileDownloadLink field formatter:
- either use an existing custom module on your site or create a new one
- create a file at
whatever_module/src/Plugin/Field/FieldFormatter/FileDownloadLink.php
- paste in the contents of the attached FileDownloadLink.php
- In the GUI create a paragraph that has two fields:
- a Media Library reference field: file_from_media_library
- a short plain text field: button_text
- Set the display for the media file to File Download Link
- Put an instance of that paragraph on some node, so you can grab the name of the paragraph template.
- Create a paragraph template. In it put:
{% extends 'paragraph.html.twig' %}
{% block content %}
{% set link = content.field_file_from_media_library[0]['#plain_text'] %}
{% set label = content.field_button_text['#items'].value %}
<a href="{{ link }}" class="button">{{ label }}</a>
{% endblock content %}