From 8162668ea9e41255904caa917fc978f8d4a51502 Mon Sep 17 00:00:00 2001 From: Z Snow Date: Sun, 6 Dec 2015 07:46:46 +1100 Subject: [PATCH 1/4] Fix routing for admin/content/files. --- file_entity.routing.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/file_entity.routing.yml b/file_entity.routing.yml index 6790afb..e19c3a0 100644 --- a/file_entity.routing.yml +++ b/file_entity.routing.yml @@ -57,6 +57,15 @@ entity.file.add_form: options: _admin_route: TRUE +entity.file.collection: + path: /admin/content/files + defaults: + _entity_list: 'file' + _title: 'Files' + requirements: + _permission: 'administer files' + + file_entity.file_add_upload: path: /file/add/upload defaults: From d62cc13e63a89bf262a2902351308d76d0c9493b Mon Sep 17 00:00:00 2001 From: Z Snow Date: Sun, 6 Dec 2015 08:13:08 +1100 Subject: [PATCH 2/4] Add files to the admin content menu. --- file_entity.links.menu.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/file_entity.links.menu.yml b/file_entity.links.menu.yml index 1793645..64a294f 100644 --- a/file_entity.links.menu.yml +++ b/file_entity.links.menu.yml @@ -1,3 +1,9 @@ +entity.file.collection: + title: Files + route_name: entity.file.collection + parent: system.admin_content + description: 'Manage files for your site.' + file_entity.types: title: 'File types' description: 'Manage settings for the type of files used on your site.' From bb9e01a3d0785dcdceb3dcf95ec20c8735829848 Mon Sep 17 00:00:00 2001 From: romain Date: Sat, 6 Feb 2016 17:45:27 +1100 Subject: [PATCH 3/4] Allow files to be sent as remote URLs. --- src/Normalizer/FileEntityNormalizer.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Normalizer/FileEntityNormalizer.php b/src/Normalizer/FileEntityNormalizer.php index cdb1df0..7d1bc9b 100644 --- a/src/Normalizer/FileEntityNormalizer.php +++ b/src/Normalizer/FileEntityNormalizer.php @@ -41,8 +41,14 @@ public function denormalize($data, $class, $format = NULL, array $context = arra // Avoid 'data' being treated as a field. $file_data = $data['data'][0]['value']; unset($data['data']); - // Decode and save to file. - $file_contents = base64_decode($file_data); + if ( strpos($file_data, 'http') === 0 ) { + // Get the remote file contents. + $file_contents = file_get_contents($file_data); + $file_data = base64_encode($file_contents); + } else { + // Decode and save to file. + $file_contents = base64_decode($file_data); + } $entity = parent::denormalize($data, $class, $format, $context); $dirname = drupal_dirname($entity->getFileUri()); file_prepare_directory($dirname, FILE_CREATE_DIRECTORY); From 44c8ea33db63c31f20d62ca6df878bd7679dc959 Mon Sep 17 00:00:00 2001 From: romain Date: Sun, 7 Feb 2016 06:38:44 +1100 Subject: [PATCH 4/4] Validate the URL rather than testing a substring. --- src/Normalizer/FileEntityNormalizer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Normalizer/FileEntityNormalizer.php b/src/Normalizer/FileEntityNormalizer.php index 7d1bc9b..31a0483 100644 --- a/src/Normalizer/FileEntityNormalizer.php +++ b/src/Normalizer/FileEntityNormalizer.php @@ -41,7 +41,7 @@ public function denormalize($data, $class, $format = NULL, array $context = arra // Avoid 'data' being treated as a field. $file_data = $data['data'][0]['value']; unset($data['data']); - if ( strpos($file_data, 'http') === 0 ) { + if ( filter_var($file_data, FILTER_VALIDATE_URL) ) { // Get the remote file contents. $file_contents = file_get_contents($file_data); $file_data = base64_encode($file_contents);