Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
commerce_api
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
commerce_api
Merge requests
!1
Swap the variations resource controller method
Code
Review changes
Check out branch
Open in Workspace
Download
Patches
Plain diff
Expand sidebar
Open
Swap the variations resource controller method
issue/commerce_api-3161050:variations-filter
into
8.x-1.x
Overview
0
Commits
3
Pipelines
0
Changes
4
Open
Swap the variations resource controller method
Matt Glaman
requested to merge
issue/commerce_api-3161050:variations-filter
into
8.x-1.x
Jul 23, 2020
Overview
0
Commits
3
Pipelines
0
Changes
4
0
0
Merge request reports
Compare
8.x-1.x
version 2
e5472731
Jul 23, 2020
version 1
1e60f336
Jul 23, 2020
8.x-1.x (base)
and
latest version
latest version
1a43c7a9
3 commits,
Jul 24, 2020
version 2
e5472731
2 commits,
Jul 23, 2020
version 1
1e60f336
1 commit,
Jul 23, 2020
4 files
+
170
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
src/Routing/JsonapiRouteSubscriber.php
0 → 100644
+
47
−
0
View file @ 1a43c7a9
Edit in single-file editor
Open in Web IDE
<?php
declare
(
strict_types
=
1
);
namespace
Drupal\commerce_api\Routing
;
use
Drupal\Core\Routing\RouteSubscriberBase
;
use
Drupal\jsonapi\ResourceType\ResourceType
;
use
Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface
;
use
Drupal\jsonapi\Routing\Routes
as
JsonapiRoutes
;
use
Symfony\Cmf\Component\Routing\RouteObjectInterface
;
use
Symfony\Component\Routing\RouteCollection
;
final
class
JsonapiRouteSubscriber
extends
RouteSubscriberBase
{
/**
* The resource type repository.
*
* @var \Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface
*/
private
$resourceTypeRepository
;
/**
* Constructs a new JsonapiRouteSubscriber object.
*
* @param \Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface $resource_type_repository
* The resource type repository.
*/
public
function
__construct
(
ResourceTypeRepositoryInterface
$resource_type_repository
)
{
$this
->
resourceTypeRepository
=
$resource_type_repository
;
}
/**
* {@inheritdoc}
*/
protected
function
alterRoutes
(
RouteCollection
$collection
)
{
$product_resource_types
=
array_filter
(
$this
->
resourceTypeRepository
->
all
(),
static
function
(
ResourceType
$resource_type
)
{
return
$resource_type
->
getEntityTypeId
()
===
'commerce_product'
;
});
foreach
(
$product_resource_types
as
$resource_type
)
{
$variations_relationship_route_name
=
JsonapiRoutes
::
getRouteName
(
$resource_type
,
'variations.relationship.get'
);
$variations_relationship_route
=
$collection
->
get
(
$variations_relationship_route_name
);
if
(
$variations_relationship_route
!==
NULL
)
{
$variations_relationship_route
->
setDefault
(
RouteObjectInterface
::
CONTROLLER_NAME
,
'commerce_api.jsonapi_controller_shim:getVariationRelationship'
);
}
}
}
}
Loading