diff --git a/core/modules/file/src/Entity/File.php b/core/modules/file/src/Entity/File.php
index 1a38c16..c85a5e9 100644
--- a/core/modules/file/src/Entity/File.php
+++ b/core/modules/file/src/Entity/File.php
@@ -7,11 +7,14 @@
 
 namespace Drupal\file\Entity;
 
+use Drupal\Component\Utility\SafeMarkup;
 use Drupal\Core\Entity\ContentEntityBase;
 use Drupal\Core\Entity\EntityChangedTrait;
 use Drupal\Core\Entity\EntityStorageInterface;
 use Drupal\Core\Entity\EntityTypeInterface;
+use Drupal\Core\Entity\Exception\UndefinedLinkTemplateException;
 use Drupal\Core\Field\BaseFieldDefinition;
+use Drupal\Core\Url;
 use Drupal\file\FileInterface;
 use Drupal\user\UserInterface;
 
@@ -282,4 +285,17 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
     return $fields;
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  public function urlInfo($rel = 'canonical', array $options = []) {
+    // Core doesn't provide any link templates for files so let's build
+    // canonical url manually but allow contrib to provide link templates at
+    // some later time.
+    if ($rel == 'canonical' && !$this->hasLinkTemplate('canonical')) {
+      return Url::fromUri($this->url($rel, $options));
+    }
+
+    return parent::urlInfo($rel, $options);
+  }
 }
diff --git a/core/modules/file/src/Tests/LinkTest.php b/core/modules/file/src/Tests/LinkTest.php
new file mode 100644
index 0000000..e480a50
--- /dev/null
+++ b/core/modules/file/src/Tests/LinkTest.php
@@ -0,0 +1,33 @@
+<?php
+
+namespace Drupal\file\Tests;
+use Drupal\Core\Entity\Exception\UndefinedLinkTemplateException;
+
+/**
+ * Tests \Drupal\file\Entity\File::link().
+ *
+ * @group file
+ */
+class LinkTest extends FileManagedUnitTestBase {
+
+  /**
+   * Creates a link for a public file.
+   */
+  function testPublicLink() {
+    $file = $this->createFile('druplicon.txt', NULL, 'public');
+    $this->assertEqual($file->link(), "<a href=\"{$file->url()}\">{$file->label()}</a>");
+  }
+
+  /**
+   * Tests that only canonical links are supported.
+   */
+  function testNonCanonicalLink() {
+    $file = $this->createFile('druplicon.txt', NULL, 'public');
+    try {
+      $file->link('', 'notcanonical');
+      $this->fail('Non-canonical link accepted');
+    } catch (UndefinedLinkTemplateException $ex) {
+      $this->pass('Non-canonical link rejected');
+    }
+  }
+}
