Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
308
Merge Requests
308
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
505a062e
Commit
505a062e
authored
Jun 18, 2014
by
Dries
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2277705
by mashermike, juampy: Fixed Files don't have URI nor href.
parent
ade617fd
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
99 additions
and
1 deletion
+99
-1
core/modules/file/src/Entity/File.php
core/modules/file/src/Entity/File.php
+7
-0
core/modules/file/src/Tests/FileItemTest.php
core/modules/file/src/Tests/FileItemTest.php
+1
-0
core/modules/hal/src/Normalizer/FileEntityNormalizer.php
core/modules/hal/src/Normalizer/FileEntityNormalizer.php
+1
-1
core/modules/hal/src/Tests/FileNormalizeTest.php
core/modules/hal/src/Tests/FileNormalizeTest.php
+90
-0
No files found.
core/modules/file/src/Entity/File.php
View file @
505a062e
...
...
@@ -74,6 +74,13 @@ public function setFileUri($uri) {
$this
->
get
(
'uri'
)
->
value
=
$uri
;
}
/**
* {@inheritdoc}
*/
public
function
url
(
$rel
=
'canonical'
,
$options
=
array
())
{
return
file_create_url
(
$this
->
getFileUri
());
}
/**
* {@inheritdoc}
*/
...
...
core/modules/file/src/Tests/FileItemTest.php
View file @
505a062e
...
...
@@ -82,6 +82,7 @@ public function testFileItem() {
$this
->
assertEqual
(
$entity
->
file_test
->
display
,
1
);
$this
->
assertEqual
(
$entity
->
file_test
->
description
,
$description
);
$this
->
assertEqual
(
$entity
->
file_test
->
entity
->
getFileUri
(),
$this
->
file
->
getFileUri
());
$this
->
assertEqual
(
$entity
->
file_test
->
entity
->
url
(),
$url
=
file_create_url
(
$this
->
file
->
getFileUri
()));
$this
->
assertEqual
(
$entity
->
file_test
->
entity
->
id
(),
$this
->
file
->
id
());
$this
->
assertEqual
(
$entity
->
file_test
->
entity
->
uuid
(),
$this
->
file
->
uuid
());
...
...
core/modules/hal/src/Normalizer/FileEntityNormalizer.php
View file @
505a062e
...
...
@@ -55,7 +55,7 @@ public function __construct(EntityManagerInterface $entity_manager, ClientInterf
public
function
normalize
(
$entity
,
$format
=
NULL
,
array
$context
=
array
())
{
$data
=
parent
::
normalize
(
$entity
,
$format
,
$context
);
// Replace the file url with a full url for the file.
$data
[
'uri'
][
0
][
'value'
]
=
file_create_url
(
$data
[
'uri'
][
0
][
'value'
]
);
$data
[
'uri'
][
0
][
'value'
]
=
$this
->
getEntityUri
(
$entity
);
return
$data
;
}
...
...
core/modules/hal/src/Tests/FileNormalizeTest.php
0 → 100644
View file @
505a062e
<?php
/**
* @file
* Contains \Drupal\hal\Tests\FileNormalizeTest.
*/
namespace
Drupal\hal\Tests
;
use
Drupal\Core\Cache\MemoryBackend
;
use
Drupal\hal\Encoder\JsonEncoder
;
use
Drupal\hal\Normalizer\FieldItemNormalizer
;
use
Drupal\hal\Normalizer\FileEntityNormalizer
;
use
Drupal\rest\LinkManager\LinkManager
;
use
Drupal\rest\LinkManager\RelationLinkManager
;
use
Drupal\rest\LinkManager\TypeLinkManager
;
use
Symfony\Component\Serializer\Serializer
;
/**
* Test the HAL normalizer.
*/
class
FileNormalizeTest
extends
NormalizerTestBase
{
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'File Normalize Test'
,
'description'
=>
'Test that file entities can be normalized in HAL.'
,
'group'
=>
'HAL'
,
);
}
/**
* Modules to enable.
*
* @var array
*/
public
static
$modules
=
array
(
'file'
);
/**
* {@inheritdoc}
*/
function
setUp
()
{
parent
::
setUp
();
$this
->
installEntitySchema
(
'file'
);
$entity_manager
=
\
Drupal
::
entityManager
();
$link_manager
=
new
LinkManager
(
new
TypeLinkManager
(
new
MemoryBackend
(
'default'
)),
new
RelationLinkManager
(
new
MemoryBackend
(
'default'
),
$entity_manager
));
// Set up the mock serializer.
$normalizers
=
array
(
new
FieldItemNormalizer
(),
new
FileEntityNormalizer
(
$entity_manager
,
\
Drupal
::
httpClient
(),
$link_manager
,
\
Drupal
::
moduleHandler
()),
);
$encoders
=
array
(
new
JsonEncoder
(),
);
$this
->
serializer
=
new
Serializer
(
$normalizers
,
$encoders
);
}
/**
* Tests the normalize function.
*/
public
function
testNormalize
()
{
$file_params
=
array
(
'filename'
=>
'test_1.txt'
,
'uri'
=>
'public://test_1.txt'
,
'filemime'
=>
'text/plain'
,
'status'
=>
FILE_STATUS_PERMANENT
,
);
// Create a new file entity.
$file
=
entity_create
(
'file'
,
$file_params
);
file_put_contents
(
$file
->
getFileUri
(),
'hello world'
);
$file
->
save
();
$expected_array
=
array
(
'uri'
=>
array
(
array
(
'value'
=>
file_create_url
(
$file
->
getFileUri
())),
),
);
$normalized
=
$this
->
serializer
->
normalize
(
$file
,
$this
->
format
);
$this
->
assertEqual
(
$normalized
[
'uri'
],
$expected_array
[
'uri'
],
'URI is normalized.'
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment