Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
external_entities
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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
external_entities
Merge requests
!69
Issue
#3506812
: Add generic handling of JSON:API includes
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Issue
#3506812
: Add generic handling of JSON:API includes
issue/external_entities-3506812:3506812-add-generic-handling
into
3.0.x
Overview
0
Commits
5
Pipelines
4
Changes
3
Open
Peter Philipp
requested to merge
issue/external_entities-3506812:3506812-add-generic-handling
into
3.0.x
3 months ago
Overview
0
Commits
5
Pipelines
4
Changes
3
Expand
Closes
#3506812
0
0
Merge request reports
Compare
3.0.x
version 4
b34c13fb
3 months ago
version 3
671eebd5
3 months ago
version 2
ced44bca
3 months ago
version 1
80dbd523
3 months ago
3.0.x (HEAD)
and
latest version
latest version
d6626f86
5 commits,
3 months ago
version 4
b34c13fb
4 commits,
3 months ago
version 3
671eebd5
3 commits,
3 months ago
version 2
ced44bca
2 commits,
3 months ago
version 1
80dbd523
1 commit,
3 months ago
3 files
+
142
−
9
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
Search (e.g. *.vue) (Ctrl+P)
src/Plugin/ExternalEntities/StorageClient/JsonApi.php
+
42
−
9
Options
@@ -67,7 +67,7 @@ class JsonApi extends RestClient {
],
'response_format'
=>
[
'#type'
=>
'hidden'
,
'#default_value'
=>
'json'
,
'#default_value'
=>
'
external_entities_api_
json'
,
],
'data_path'
=>
[
'list'
=>
[
@@ -91,7 +91,7 @@ class JsonApi extends RestClient {
],
'pager'
=>
[
'#type'
=>
NULL
,
// Drupal uses a 50 elements per
b
age basis so we go for 1 query per
// Drupal uses a 50 elements per
p
age basis so we go for 1 query per
// page. 50 is the JSON:API default limit anyway.
'default_limit'
=>
[
'#type'
=>
'hidden'
,
@@ -348,16 +348,49 @@ class JsonApi extends RestClient {
$result
=
parent
::
load
(
$id
);
// Check for "included".
if
(
!
empty
(
$result
[
1
]))
{
// JSONPath returned an array of object so we got "extra" from "included".
$included
=
array_slice
(
$result
,
1
);
$result
=
$result
[
0
];
$result
[
'included'
]
=
$included
;
}
static
::
$cachedData
[
$this
->
configuration
[
'endpoint'
]][
$id
]
=
$result
;
return
$result
;
}
protected
function
resolveRelationships
(
&
$result
)
:
void
{
// Collect all includes and index them by type and id.
$includedRegistry
=
[];
foreach
(
$result
[
'included'
]
as
$included_entry
)
{
$included_id
=
(
$included_entry
[
'type'
]
??
NULL
)
.
':'
.
$included_entry
[
'id'
];
$includedRegistry
[
$included_id
]
=
$included_entry
;
}
$this
->
_resolveRelationsRecursive
(
$result
[
'relationships'
],
$includedRegistry
);
}
protected
function
_resolveRelationsRecursive
(
&
$relationships
,
$includedRegistry
)
:
void
{
foreach
(
$relationships
as
$field
=>
$relationship
)
{
if
(
!
empty
(
$relationship
[
'data'
]))
{
// Relationships can be single or multi-value.
if
(
isset
(
$relationship
[
'data'
][
'id'
]))
{
$this
->
_mapRelationshipData
(
$relationships
[
$field
][
'data'
],
$includedRegistry
);
}
else
{
foreach
(
$relationship
[
'data'
]
as
$i
=>
$data
)
{
$this
->
_mapRelationshipData
(
$relationships
[
$field
][
'data'
][
$i
],
$includedRegistry
);
}
}
}
}
}
protected
function
_mapRelationshipData
(
&
$data
,
array
$includedRegistry
)
:
void
{
if
(
isset
(
$data
[
'id'
]))
{
$included_id
=
(
$data
[
'type'
]
??
NULL
)
.
':'
.
$data
[
'id'
];
if
(
isset
(
$includedRegistry
[
$included_id
]))
{
$data
[
'included'
]
=
$includedRegistry
[
$included_id
];
}
if
(
!
empty
(
$data
[
'relationships'
]))
{
$this
->
_resolveRelationsRecursive
(
$data
[
'relationships'
],
$includedRegistry
);
}
}
}
}
Loading