File link

Default theming and some extra's for Drupal's file links.

 

Making more variables available in Twig

In this component 4 extra variables have been added that are available in the template: 

  • {{ file_uri }} contains the url where the link has to point as a string.
  • {{ mime_type }} contains the type of the file.
  • {{ filename }} contains the name of the file as a string.
  • {{ size }} the size of the file in Kilobytes.

Creating a file link in PHP

You can add a file link by defining it as a render array:

$form['file_field'] = [
  '#theme' => 'file_link',
  '#file' => $file,
  '#description' => $this->t('this is my file'),
];

Specifications

Machine name

file-link

Built upon

Drupal Core

Perks

Using Sass
Responsive
Accessible

Building blocks

HTML
CSS

Inspired by

Flat design

Stats

Public component
10 downloads
No open issue

Contributors