Get server-rendered contextual links for the given contextual link ids.
array $ids: An array of contextual link ids.
string $current_path: The Drupal path for the page for which the contextual links are rendered.
string The response body.
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 => url('contextual/render', 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',
),
));
}