From b8a36557d2529b56a3ad1cf2136b2add061179d4 Mon Sep 17 00:00:00 2001
From: claudiucristea <claudiucristea@56348.no-reply.drupal.org>
Date: Fri, 25 Nov 2016 00:33:25 +0100
Subject: [PATCH 1/5] Issue #2758043 by claudiu.cristea, Berdir, ericpugh,
 MiSc: After installing the module, file 'type' field storage is not installed

---
 file_entity.install                                | 7 ++++---
 src/Tests/FileEntityFileTypeClassificationTest.php | 1 +
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/file_entity.install b/file_entity.install
index 54b4679..f0cba01 100644
--- a/file_entity.install
+++ b/file_entity.install
@@ -4,6 +4,7 @@
  * @file
  * Install, update and uninstall functions for the file_entity module.
  */
+
 use Drupal\Core\Entity\Entity\EntityFormDisplay;
 use Drupal\views\Entity\View;
 
@@ -50,9 +51,8 @@ function file_entity_schema() {
  * Implements hook_install().
  */
 function file_entity_install() {
-  $type_storage_definition = \Drupal::entityManager()->getFieldStorageDefinitions('file')['type'];
-  \Drupal::entityManager()->getStorage('file')->onFieldStorageDefinitionCreate($type_storage_definition);
-
+  $type_storage_definition = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions('file')['type'];
+  \Drupal::entityDefinitionUpdateManager()->installFieldStorageDefinition('type', 'file', 'file_entity', $type_storage_definition);
   // Set permissions.
   $roles = user_roles();
   foreach ($roles as $rid => $role) {
@@ -88,6 +88,7 @@ function file_entity_uninstall() {
   // Remove the added column to the core {file_managed} table.
   db_drop_field('file_managed', 'type');
 }
+
 /**
  * Update existing bogus entries for File types Document.
  */
diff --git a/src/Tests/FileEntityFileTypeClassificationTest.php b/src/Tests/FileEntityFileTypeClassificationTest.php
index 080c181..6a87193 100644
--- a/src/Tests/FileEntityFileTypeClassificationTest.php
+++ b/src/Tests/FileEntityFileTypeClassificationTest.php
@@ -60,6 +60,7 @@ class FileEntityFileTypeClassificationTest extends WebTestBase {
     // Enable file entity which adds adds a file type property to files and
     // queues up existing files for classification.
     \Drupal::service('module_installer')->install(array('file_entity'));
+    $this->assertTrue(empty(\Drupal::entityDefinitionUpdateManager()->getChangeSummary()), 'No entity definition changes pending');
 
     // Existing files have yet to be classified and should have an undefined
     // file type.
-- 
2.8.1


From 8accdd53fb9b87f3fe8462cfff020e4936d364e1 Mon Sep 17 00:00:00 2001
From: berdir <berdir@214652.no-reply.drupal.org>
Date: Sat, 28 Jan 2017 14:21:03 +0100
Subject: [PATCH 2/5] Issue #2760285 by Berdir, audriusb, dobrzyns: Download
 link in views missing token, download link not part of operations field

---
 file_entity.module                      | 22 +++++++++++++++++++---
 src/Plugin/views/field/LinkDownload.php |  4 +---
 src/Tests/FileEntityAdminTest.php       | 20 +++++++++-----------
 3 files changed, 29 insertions(+), 17 deletions(-)

diff --git a/file_entity.module b/file_entity.module
index 80e1dba..7c7d63b 100644
--- a/file_entity.module
+++ b/file_entity.module
@@ -5,16 +5,15 @@
  * Extends Drupal file entities to be fieldable and viewable.
  */
 
-use Drupal\Component\Utility\Html;
-use Drupal\Core\Database\Query\SelectInterface;
+use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Entity\EntityTypeInterface;
 use Drupal\Core\Field\BaseFieldDefinition;
 use Drupal\Core\Render\BubbleableMetadata;
 use Drupal\Core\Routing\RouteMatchInterface;
 use Drupal\Core\StreamWrapper\StreamWrapperInterface;
-use Drupal\Core\Url;
 use Drupal\file\Entity\File;
 use Drupal\file\FileInterface;
+use Drupal\file_entity\Entity\FileEntity;
 use Drupal\file_entity\Entity\FileType;
 
 /**
@@ -193,6 +192,23 @@ function file_entity_entity_type_alter(&$entity_types) {
 }
 
 /**
+ * Implements hook_entity_operation().
+ */
+function file_entity_entity_operation(EntityInterface $entity) {
+  $operations = [];
+
+  if ($entity instanceof FileEntity && $entity->access('download')) {
+    $operations['download'] = array(
+      'title' => t('Download'),
+      'weight' => 100,
+      'url' => $entity->downloadUrl(),
+    );
+  }
+
+  return $operations;
+}
+
+/**
  * Prepares variables for file templates.
  *
  * Default template: file.html.twig.
diff --git a/src/Plugin/views/field/LinkDownload.php b/src/Plugin/views/field/LinkDownload.php
index cffddab..b60e6c7 100644
--- a/src/Plugin/views/field/LinkDownload.php
+++ b/src/Plugin/views/field/LinkDownload.php
@@ -35,9 +35,7 @@ class LinkDownload extends Link {
     // Ensure user has access to delete this media item.
     if ($file->access('download')) {
       $this->options['alter']['make_link'] = TRUE;
-      $this->options['alter']['path'] = 'file/' . $file->id() . '/download';
-      $this->options['alter']['query'] = drupal_get_destination();
-
+      $this->options['alter']['path'] = $file->downloadUrl()->toString();
       $text = !empty($this->options['text']) ? $this->options['text'] : t('Download');
     }
 
diff --git a/src/Tests/FileEntityAdminTest.php b/src/Tests/FileEntityAdminTest.php
index 9fd8675..6fbd16a 100644
--- a/src/Tests/FileEntityAdminTest.php
+++ b/src/Tests/FileEntityAdminTest.php
@@ -165,17 +165,12 @@ class FileEntityAdminTest extends FileEntityTestBase {
     $this->assertResponse(200);
     $this->assertLinkByHref('file/' . $files['public_image']->id());
     $this->assertLinkByHref('file/' . $files['public_document']->id());
-    // @todo: Operations links are currently displayed for all users.
-    // Switch back to assertNoLinkByHref() after www.drupal.org/node/2406533
-    // is resolved.
-    $this->drupalGet('file/' . $files['public_image']->id() . '/edit');
-    $this->assertResponse(403, 'User doesn\'t have permission to edit files');
-    $this->drupalGet('file/' . $files['public_image']->id() . '/delete');
-    $this->assertResponse(403, 'User doesn\'t have permission to delete files');
-    $this->drupalGet('file/' . $files['public_document']->id() . '/edit');
-    $this->assertResponse(403, 'User doesn\'t have permission to edit files');
-    $this->drupalGet('file/' . $files['public_document']->id() . '/delete');
-    $this->assertResponse(403, 'User doesn\'t have permission to delete files');
+    $this->assertNoLinkByHref('file/' . $files['public_document']->id() . '/download');
+    $this->assertNoLinkByHref('file/' . $files['public_document']->id() . '/download');
+    $this->assertNoLinkByHref('file/' . $files['public_image']->id() . '/edit');
+    $this->assertNoLinkByHref('file/' . $files['public_image']->id() . '/delete');
+    $this->assertNoLinkByHref('file/' . $files['public_document']->id() . '/edit');
+    $this->assertNoLinkByHref('file/' . $files['public_document']->id() . '/delete');
 
     // Verify no tableselect.
     $this->assertNoFieldByName('bulk_form[' . $files['public_image']->id() . ']', '', t('No bulk form checkbox found.'));
@@ -196,6 +191,7 @@ class FileEntityAdminTest extends FileEntityTestBase {
     $this->assertNoLinkByHref($files['private_image']->url());
     $this->assertNoLinkByHref($files['private_image']->url('edit-form'));
     $this->assertNoLinkByHref($files['private_image']->url('delete-form'));
+    $this->assertNoLinkByHref($files['private_image']->downloadUrl()->toString());
 
     // Verify no tableselect.
     $this->assertNoFieldByName('bulk_form[' . $files['private_document']->id() . ']', '', t('No bulk form checkbox found.'));
@@ -220,6 +216,7 @@ class FileEntityAdminTest extends FileEntityTestBase {
       $this->assertLinkByHref('file/' . $file->id());
       $this->assertLinkByHref('file/' . $file->id() . '/edit');
       $this->assertLinkByHref('file/' . $file->id() . '/delete');
+      $this->assertLinkByHref('file/' . $file->id() . '/delete');
     }
 
     // Verify file access can be bypassed.
@@ -231,6 +228,7 @@ class FileEntityAdminTest extends FileEntityTestBase {
       $this->assertLinkByHref('file/' . $file->id());
       $this->assertLinkByHref('file/' . $file->id() . '/edit');
       $this->assertLinkByHref('file/' . $file->id() . '/delete');
+      $this->assertLinkByHref('file/' . $file->id() . '/download');
     }
   }
 
-- 
2.8.1


From 06a42fb586d3b58af9d2ae724290b576cf1f6583 Mon Sep 17 00:00:00 2001
From: git <git@3303043.no-reply.drupal.org>
Date: Mon, 6 Feb 2017 09:11:59 +0100
Subject: [PATCH 3/5] Issue #2849472 by tduong: FileEntityServiceProvider
 should check for rest module

---
 src/FileEntityServiceProvider.php | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/FileEntityServiceProvider.php b/src/FileEntityServiceProvider.php
index a59fc9a..bd8b893 100644
--- a/src/FileEntityServiceProvider.php
+++ b/src/FileEntityServiceProvider.php
@@ -21,8 +21,9 @@ class FileEntityServiceProvider extends ServiceProviderBase {
    */
   public function alter(ContainerBuilder $container) {
     $modules = $container->getParameter('container.modules');
-    // Check for installed REST & HAL modules, as HAL requires REST.
-    if (isset($modules['hal']) ) {
+    // Check for installed REST and HAL modules. HAL does not require REST
+    // anymore in 8.3 and later.
+    if (isset($modules['hal']) && isset($modules['rest'])) {
       // Add a normalizer service for file entities.
       $service_definition = new Definition('Drupal\file_entity\Normalizer\FileEntityNormalizer', array(
         new Reference('rest.link_manager'),
-- 
2.8.1


From 8bae0e1b9b876f1613dbc8b160db02274819ec66 Mon Sep 17 00:00:00 2001
From: berdir <berdir@214652.no-reply.drupal.org>
Date: Fri, 24 Feb 2017 00:38:03 +0100
Subject: [PATCH 4/5] Issue #2855443 by Berdir: Better support fallback
 formatter by using correct delta in FileAudioFormatter

---
 src/Plugin/Field/FieldFormatter/FileVideoFormatter.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Plugin/Field/FieldFormatter/FileVideoFormatter.php b/src/Plugin/Field/FieldFormatter/FileVideoFormatter.php
index 71f7fd1..568b3a5 100644
--- a/src/Plugin/Field/FieldFormatter/FileVideoFormatter.php
+++ b/src/Plugin/Field/FieldFormatter/FileVideoFormatter.php
@@ -186,7 +186,7 @@ class FileVideoFormatter extends FileFormatterBase implements ContainerFactoryPl
         $source_attributes->setAttribute('src', file_create_url($file->getFileUri()));
         $source_attributes->setAttribute('type', $file->getMimeType());
         if ($multiple_file_behavior == 'tags') {
-          $source_files[] = array(array('file' => $file, 'source_attributes' => $source_attributes));
+          $source_files[$delta] = array(array('file' => $file, 'source_attributes' => $source_attributes));
         }
         else {
           $source_files[0][] = array('file' => $file, 'source_attributes' => $source_attributes);
-- 
2.8.1


From 724ec2437d1a8ca14dac94ae5a1c124c63c9705f Mon Sep 17 00:00:00 2001
From: berdir <berdir@214652.no-reply.drupal.org>
Date: Sat, 25 Feb 2017 11:41:07 +0100
Subject: [PATCH 5/5] Issue #2855543 by Berdir: Test fails in
 FileEntityCacheTagsTest

---
 src/Tests/FileEntityCacheTagsTest.php | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/Tests/FileEntityCacheTagsTest.php b/src/Tests/FileEntityCacheTagsTest.php
index b3c839a..1f59b3e 100644
--- a/src/Tests/FileEntityCacheTagsTest.php
+++ b/src/Tests/FileEntityCacheTagsTest.php
@@ -107,38 +107,39 @@ class FileEntityCacheTagsTest extends FileEntityTestBase {
 
     // Check cache tags.
     $contexts = ['languages:language_interface', 'user.permissions', 'theme', 'timezone', 'url.query_args:_wrapper_format', 'user.roles:anonymous'];
-    $this->assertPageCacheContextsAndTags($node1->urlInfo(), $contexts, [
+    $this->assertPageCacheContextsAndTags($node1->toUrl(), $contexts, [
       'node:' . $node1->id(),
       'node_view',
       'rendered',
       'user:0',
       'user_view',
       'config:user.role.anonymous',
+      'http_response',
     ]);
-    $this->assertPageCacheContextsAndTags($node2->urlInfo(), $contexts, [
+    $this->assertPageCacheContextsAndTags($node2->toUrl(), $contexts, [
       'node:' . $node2->id(),
       'node_view',
       'rendered',
       'user:0',
       'user_view',
       'config:user.role.anonymous',
+      'http_response',
     ]);
-    $this->assertPageCacheContextsAndTags($node3->urlInfo(), $contexts, [
+    $this->assertPageCacheContextsAndTags($node3->toUrl(), $contexts, [
       'node:' . $node3->id(),
       'node_view',
       'rendered',
       'user:0',
       'user_view',
       'config:user.role.anonymous',
+      'http_response',
     ]);
 
     // Save the first file to invalidate cache tags.
     $file1->save();
-    $this->verifyPageCache($node1->urlInfo(), 'MISS');
-    $this->verifyPageCache($node2->urlInfo(), 'MISS');
-    $this->verifyPageCache($node3->urlInfo(), 'HIT');
-
-
+    $this->verifyPageCache($node1->toUrl(), 'MISS');
+    $this->verifyPageCache($node2->toUrl(), 'MISS');
+    $this->verifyPageCache($node3->toUrl(), 'HIT');
   }
 
   /**
-- 
2.8.1

