Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jsonapi_extras
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
jsonapi_extras
Commits
f2babd5d
Commit
f2babd5d
authored
1 year ago
by
Björn Brala
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3384599
: Cleanup Drupal 8 code paths
parent
72b777b7
No related branches found
No related tags found
1 merge request
!37
Issue #3384599: Cleanup Drupal 8 code paths
Pipeline
#17450
passed with warnings
1 year ago
Stage: build
Stage: validate
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/ResourceType/ConfigurableResourceTypeRepository.php
+4
-88
4 additions, 88 deletions
src/ResourceType/ConfigurableResourceTypeRepository.php
with
4 additions
and
88 deletions
src/ResourceType/ConfigurableResourceTypeRepository.php
+
4
−
88
View file @
f2babd5d
...
...
@@ -82,14 +82,10 @@ class ConfigurableResourceTypeRepository extends ResourceTypeRepository {
public
function
__construct
(...
$arguments
)
{
parent
::
__construct
(
...
$arguments
);
// This is needed, as the property is added in Drupal 8.8 and it is not
// yet present in 8.7 or the contrib version of JSON:API at the time.
if
(
property_exists
(
$this
,
'cacheTags'
))
{
$this
->
cacheTags
=
array_merge
(
$this
->
cacheTags
,
[
'config:jsonapi_extras.settings'
,
'config:jsonapi_resource_config_list'
,
]);
}
$this
->
cacheTags
=
array_merge
(
$this
->
cacheTags
,
[
'config:jsonapi_extras.settings'
,
'config:jsonapi_resource_config_list'
,
]);
}
/**
...
...
@@ -253,84 +249,4 @@ class ConfigurableResourceTypeRepository extends ResourceTypeRepository {
return
NULL
;
}
/**
* {@inheritdoc}
*
* @todo Remove this code when Drupal 8 support is dropped
*/
protected
function
getRelatableResourceTypesFromFieldDefinition
(
FieldDefinitionInterface
$field_definition
,
array
$resource_types
)
{
$item_definition
=
$field_definition
->
getItemDefinition
();
$entity_type_id
=
$item_definition
->
getSetting
(
'target_type'
);
$handler_settings
=
$item_definition
->
getSetting
(
'handler_settings'
);
$target_bundles
=
empty
(
$handler_settings
[
'target_bundles'
])
?
$this
->
getAllBundlesForEntityType
(
$entity_type_id
)
:
$handler_settings
[
'target_bundles'
];
$relatable_resource_types
=
[];
foreach
(
$target_bundles
as
$target_bundle
)
{
if
(
$resource_type
=
static
::
lookupResourceType
(
$resource_types
,
$entity_type_id
,
$target_bundle
))
{
$relatable_resource_types
[]
=
$resource_type
;
}
else
{
trigger_error
(
sprintf
(
'The "%s" at "%s:%s" references the "%s:%s" entity type that does not exist. Please take action.'
,
$field_definition
->
getName
(),
$field_definition
->
getTargetEntityTypeId
(),
$field_definition
->
getTargetBundle
(),
$entity_type_id
,
$target_bundle
),
E_USER_WARNING
);
}
}
return
$relatable_resource_types
;
}
/**
* {@inheritdoc}
*
* @todo Remove this code when Drupal 8 support is dropped
*/
protected
function
getAllBundlesForEntityType
(
$entity_type_id
)
{
// Ensure all keys are strings, because numeric values are allowed
// as bundle names and "array_keys()" will cast "42" to 42.
return
array_map
(
'strval'
,
array_keys
(
$this
->
entityTypeBundleInfo
->
getBundleInfo
(
$entity_type_id
)));
}
/**
* Lookups resource type by the internal and public identifiers.
*
* @param \Drupal\jsonapi\ResourceType\ResourceType[] $resource_types
* The list of resource types to do a lookup.
* @param string $entity_type_id
* The entity type of a seekable resource.
* @param string $bundle
* The entity bundle of a seekable resource.
*
* @return \Drupal\jsonapi\ResourceType\ResourceType|null
* The resource type or NULL if it cannot be found.
*
* @todo Remove this code when Drupal 8 support is dropped
*/
protected
static
function
lookupResourceType
(
array
$resource_types
,
$entity_type_id
,
$bundle
)
{
if
(
isset
(
$resource_types
[
"
$entity_type_id
--
$bundle
"
]))
{
return
$resource_types
[
"
$entity_type_id
--
$bundle
"
];
}
foreach
(
$resource_types
as
$resource_type
)
{
if
(
$resource_type
->
getEntityTypeId
()
===
$entity_type_id
&&
$resource_type
->
getBundle
()
===
$bundle
)
{
return
$resource_type
;
}
}
return
NULL
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment