You are here

protected function ContentTranslationContextualLinksTest::renderContextualLinks in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/content_translation/src/Tests/ContentTranslationContextualLinksTest.php \Drupal\content_translation\Tests\ContentTranslationContextualLinksTest::renderContextualLinks()

Get server-rendered contextual links for the given contextual link ids.

Copied from \Drupal\contextual\Tests\ContextualDynamicContextTest::renderContextualLinks().

Parameters

array $ids: An array of contextual link ids.

string $current_path: The Drupal path for the page for which the contextual links are rendered.

Return value

string The response body.

1 call to ContentTranslationContextualLinksTest::renderContextualLinks()
ContentTranslationContextualLinksTest::testContentTranslationContextualLinks in core/modules/content_translation/src/Tests/ContentTranslationContextualLinksTest.php
Tests that a contextual link is available for translating a node.

File

core/modules/content_translation/src/Tests/ContentTranslationContextualLinksTest.php, line 153
Contains \Drupal\content_translation\Tests\ContentTranslationContextualLinksTest.

Class

ContentTranslationContextualLinksTest
Tests that contextual links are available for content translation.

Namespace

Drupal\content_translation\Tests

Code

protected function renderContextualLinks($ids, $current_path) {

  // Build POST values.
  $post = array();
  for ($i = 0; $i < count($ids); $i++) {
    $post['ids[' . $i . ']'] = $ids[$i];
  }

  // Serialize POST values.
  foreach ($post as $key => $value) {

    // Encode according to application/x-www-form-urlencoded
    // Both names and values needs to be urlencoded, according to
    // http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1
    $post[$key] = urlencode($key) . '=' . urlencode($value);
  }
  $post = implode('&', $post);

  // Perform HTTP request.
  return $this
    ->curlExec(array(
    CURLOPT_URL => \Drupal::url('contextual.render', array(), array(
      'absolute' => TRUE,
      'query' => array(
        'destination' => $current_path,
      ),
    )),
    CURLOPT_POST => TRUE,
    CURLOPT_POSTFIELDS => $post,
    CURLOPT_HTTPHEADER => array(
      'Accept: application/json',
      'Content-Type: application/x-www-form-urlencoded',
    ),
  ));
}