Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
file_entity
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
file_entity
Merge requests
!14
Revert "Issue
#3445785
by smulvih2: Normalizing file entity with missing file throws error"
Code
Review changes
Check out branch
Open in Workspace
Download
Patches
Plain diff
Expand sidebar
Closed
Revert "Issue
#3445785
by smulvih2: Normalizing file entity with missing file throws error"
issue/file_entity-3445785:3445785-normalizing-file-entity
into
8.x-2.x
Overview
0
Commits
1
Pipelines
1
Changes
1
Closed
Revert "Issue #3445785 by smulvih2: Normalizing file entity with missing file throws error"
Joseph Olstad
requested to merge
issue/file_entity-3445785:3445785-normalizing-file-entity
into
8.x-2.x
Jun 14, 2024
Overview
0
Commits
1
Pipelines
1
Changes
1
This reverts commit
0090805f
.
Closes
#3445785
0
0
Merge request reports
Compare
8.x-2.x
8.x-2.x (base)
and
latest version
latest version
f9332d68
1 commit,
Jun 14, 2024
1 file
+
5
−
16
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
src/Normalizer/FileEntityNormalizer.php
+
5
−
16
View file @ f9332d68
Edit in single-file editor
Open in Web IDE
Show full file
@@ -22,22 +22,11 @@ class FileEntityNormalizer extends ContentEntityNormalizer {
public
function
normalize
(
$entity
,
$format
=
NULL
,
array
$context
=
[]):
array
|
string
|
int
|
float
|
bool
|
\ArrayObject
|
NULL
{
$data
=
parent
::
normalize
(
$entity
,
$format
,
$context
);
if
(
!
isset
(
$context
[
'included_fields'
])
||
in_array
(
'data'
,
$context
[
'included_fields'
]))
{
$file_uri
=
$entity
->
getFileUri
();
// Check if the file exists before attempting to read it.
if
(
file_exists
(
$file_uri
))
{
// Save base64-encoded file contents to the "data" property.
$file_data
=
base64_encode
(
file_get_contents
(
$file_uri
));
$data
+=
array
(
'data'
=>
array
(
array
(
'value'
=>
$file_data
)),
);
}
else
{
// Save null to the "data" property.
$data
+=
array
(
'data'
=>
array
(
array
(
'value'
=>
NULL
)),
);
}
// Save base64-encoded file contents to the "data" property.
$file_data
=
base64_encode
(
file_get_contents
(
$entity
->
getFileUri
()));
$data
+=
array
(
'data'
=>
array
(
array
(
'value'
=>
$file_data
)),
);
}
return
$data
;
}
Loading