Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
TermRouteContext example
$term
=
$this
->
createTerm
(
$vocabulary
)
;
// Create RouteMatch from term entity.
$url
=
$term
->
toUrl
(
)
;
$route_provider
= \Drupal::
service
(
'router.route_provider'
)
;
$route
=
$route_provider
->
getRouteByName
(
$url
->
getRouteName
(
)
)
;
$route_match
=
new
RouteMatch
(
$url
->
getRouteName
(
)
,
$route
,
[
'taxonomy_term' =>
$term
,
]
)
;
// Initiate TermRouteContext with RouteMatch.
$provider
=
new
TermRouteContext
(
$route_match
)
;
$runtime_contexts
=
$provider
->
getRuntimeContexts
(
[
]
)
;
$this
->
assertArrayHasKey
(
'taxonomy_term',
$runtime_contexts
)
;
$this
->
assertTrue
(
$runtime_contexts
[
'taxonomy_term'
]
->
hasContextValue
(
)
)
;
}
}