Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
_contextual_id_to_links example
throw
new
BadRequestHttpException
(
'No contextual ID tokens specified.'
)
;
}
$tokens
=
$request
->request->
all
(
'tokens'
)
;
$rendered
=
[
]
;
foreach
(
$ids
as
$key
=>
$id
)
{
if
(
!
isset
(
$tokens
[
$key
]
)
|| !
hash_equals
(
$tokens
[
$key
]
, Crypt::
hmacBase64
(
$id
, Settings::
getHashSalt
(
)
. \Drupal::
service
(
'private_key'
)
->
get
(
)
)
)
)
{
throw
new
BadRequestHttpException
(
'Invalid contextual ID specified.'
)
;
}
$element
=
[
'#type' => 'contextual_links',
'#contextual_links' =>
_contextual_id_to_links
(
$id
)
,
]
;
$rendered
[
$id
]
=
$this
->renderer->
renderRoot
(
$element
)
;
}
return
new
JsonResponse
(
$rendered
)
;
}
}
public
function
testContextualIdToLinks
(
array
$links
, string
$id
)
{
$this
->
assertSame
(
$links
,
_contextual_id_to_links
(
$id
)
)
;
}
}