Skip to content
This repository has been archived by the owner on Jan 5, 2018. It is now read-only.

Fix routing for admin/content. #10

Open
wants to merge 4 commits into
base: 8.x-2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions file_entity.links.menu.yml
Original file line number Diff line number Diff line change
@@ -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.'
Expand Down
9 changes: 9 additions & 0 deletions file_entity.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 8 additions & 2 deletions src/Normalizer/FileEntityNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ( 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);
} 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);
Expand Down