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
75bb6a24
Commit
75bb6a24
authored
4 years ago
by
Björn Brala
Browse files
Options
Downloads
Patches
Plain Diff
Include ResourceTypeBuildEvents in the repository
parent
1f4fed9a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/ResourceType/ConfigurableResourceTypeRepository.php
+26
-10
26 additions, 10 deletions
src/ResourceType/ConfigurableResourceTypeRepository.php
with
26 additions
and
10 deletions
src/ResourceType/ConfigurableResourceTypeRepository.php
+
26
−
10
View file @
75bb6a24
...
...
@@ -6,6 +6,8 @@ use Drupal\Component\Plugin\Exception\PluginException;
use
Drupal\Core\Entity\EntityTypeInterface
;
use
Drupal\Core\Entity\EntityRepositoryInterface
;
use
Drupal\Core\Field\FieldDefinitionInterface
;
use
Drupal\jsonapi\ResourceType\ResourceTypeBuildEvent
;
use
Drupal\jsonapi\ResourceType\ResourceTypeBuildEvents
;
use
Drupal\jsonapi\ResourceType\ResourceTypeRepository
;
use
Drupal\jsonapi_extras
\Entity\JsonapiResourceConfig
;
use
Drupal\jsonapi_extras
\Plugin\ResourceFieldEnhancerManager
;
...
...
@@ -138,17 +140,34 @@ class ConfigurableResourceTypeRepository extends ResourceTypeRepository {
);
$resource_config
=
$this
->
getResourceConfig
(
$resource_config_id
);
// Make sure to respect the overrides coming from JSON:API if there is no
// input in JSON:API Extras.
$field_names
=
$this
->
getAllFieldNames
(
$entity_type
,
$bundle
);
$fields
=
$this
->
getFields
(
$field_names
,
$entity_type
,
$bundle
);
// Create subclassed ResourceType object with the same parameters as the
// parent implementation.
$internalize_resource_type
=
$entity_type
->
isInternal
();
if
(
!
$internalize_resource_type
)
{
$event
=
ResourceTypeBuildEvent
::
createFromEntityTypeAndBundle
(
$entity_type
,
$bundle
,
$fields
);
$this
->
eventDispatcher
->
dispatch
(
$event
,
ResourceTypeBuildEvents
::
BUILD
);
$internalize_resource_type
=
$event
->
resourceTypeShouldBeDisabled
();
$fields
=
$event
->
getFields
();
}
$fields
=
$this
->
overrideFields
(
$resource_config
,
$fields
);
$resource_type
=
new
ConfigurableResourceType
(
$entity_type
->
id
(),
$bundle
,
$entity_type
->
getClass
(),
$
entity_type
->
isInternal
()
||
(
bool
)
$resource_config
->
get
(
'disabled'
),
$
internalize_resource_type
||
(
bool
)
$resource_config
->
get
(
'disabled'
),
static
::
isLocatableResourceType
(
$entity_type
,
$bundle
),
TRUE
,
static
::
isVersionableResourceType
(
$entity_type
),
$
this
->
overrideFields
(
$resource_config
)
$
fields
);
// Inject additional services through setters. By using setter injection
...
...
@@ -197,7 +216,7 @@ class ConfigurableResourceTypeRepository extends ResourceTypeRepository {
if
(
!
$this
->
resourceConfigs
)
{
$resource_config_ids
=
[];
foreach
(
$this
->
getEntityTypeBundleTuples
()
as
$tuple
)
{
list
(
$entity_type_id
,
$bundle
)
=
$tuple
;
[
$entity_type_id
,
$bundle
]
=
$tuple
;
$resource_config_ids
[]
=
static
::
buildResourceConfigId
(
$entity_type_id
,
$bundle
...
...
@@ -249,13 +268,13 @@ class ConfigurableResourceTypeRepository extends ResourceTypeRepository {
*
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
protected
function
overrideFields
(
JsonapiResourceConfig
$resource_config
)
{
protected
function
overrideFields
(
JsonapiResourceConfig
$resource_config
,
$fields
)
{
// This is not ideal, but we cannot load the resource type to get the entity
// type object. That is because this is used during the creation of the
// ResourceType.
list
(
$entity_type_id
,
$bundle
)
=
explode
(
'--'
,
$resource_config
->
getOriginalId
());
[
$entity_type_id
,
$bundle
]
=
explode
(
'--'
,
$resource_config
->
getOriginalId
());
$entity_type
=
$this
->
entityTypeManager
->
getDefinition
(
$entity_type_id
);
$field_names
=
$this
->
getAllFieldNames
(
$entity_type
,
$bundle
);
// Use the base class to fetch the non-configurable field mappings.
$mappings
=
$resource_config
->
getFieldMapping
();
// Ignore all the fields that don't have aliases.
...
...
@@ -263,9 +282,6 @@ class ConfigurableResourceTypeRepository extends ResourceTypeRepository {
return
$field_info
!==
TRUE
;
});
// Make sure to respect the overrides coming from JSON:API if there is no
// input in JSON:API Extras.
$fields
=
$this
->
getFields
(
$field_names
,
$entity_type
,
$bundle
);
foreach
(
$mappings
as
$internal_name
=>
$mapping
)
{
if
(
!
isset
(
$fields
[
$internal_name
]))
{
continue
;
...
...
@@ -291,7 +307,7 @@ class ConfigurableResourceTypeRepository extends ResourceTypeRepository {
}
if
(
strpos
(
$type_name
,
'--'
)
!==
FALSE
)
{
list
(
$entity_type_id
,
$bundle
)
=
explode
(
'--'
,
$type_name
);
[
$entity_type_id
,
$bundle
]
=
explode
(
'--'
,
$type_name
);
return
static
::
lookupResourceType
(
$resource_types
,
$entity_type_id
,
$bundle
);
}
...
...
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