Skip to content
This repository was archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
ISAICP-4861: contextual ids tokens are needed for security reasons fr…
Browse files Browse the repository at this point in the history
…om Drupal 8.6.2.
  • Loading branch information
brummbar committed Oct 18, 2018
1 parent 8c65a84 commit 2a52d63
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions tests/src/ContextualLinksHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,23 @@ protected function generateContextualLinks(NodeElement $element): array {
/** @var \Symfony\Component\BrowserKit\Client $client */
$client = clone $this->getSession()->getDriver()->getClient();

$contextual_ids = array_map(function (NodeElement $element): string {
return $element->getAttribute('data-contextual-id');
}, $element->findAll('xpath', '//*[@data-contextual-id]'));
$ids = [];
$tokens = [];
foreach ($element->findAll('xpath', '//*[@data-contextual-id]') as $element) {
$ids[] = $element->getAttribute('data-contextual-id');
$tokens[] = $element->getAttribute('data-contextual-token');
}

// @see Drupal.behaviors.contextual.attach(), contextual.js
$client->request('POST', '/contextual/render', [
'ids' => $contextual_ids,
'ids' => $ids,
'tokens' => $tokens,
]);

$links = [];
$response = json_decode($client->getResponse()->getContent(), TRUE);
if ($response) {
foreach ($contextual_ids as $id) {
foreach ($ids as $id) {
if (isset($response[$id])) {
$crawler = new Crawler();
$crawler->addHtmlContent($response[$id]);
Expand Down

0 comments on commit 2a52d63

Please sign in to comment.