function patch_manager_field_formatter_view in Patch manager 7
Implements hook_field_formatter_view().
File
- ./
patch_manager.module, line 199 - Patch manager provides developers with tools for managing patches.
Code
function patch_manager_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$elements = array();
// Get the issue status from drupal.org.
// We couldn't use hook_field_formatter_prepare_view for it, because
// the items come nested into redundant array.
$issue_statuses =& drupal_static(__FUNCTION__, array());
foreach ($items as $delta => $item) {
$issue = $item['value'];
// Get the issue status.
if (empty($issue_statuses[$issue])) {
// Check cache.
if (!($issue_status = cache_get("patch_manager:issue_status:{$issue}")->data)) {
// Request to drupal.org to get the status.
$response_json = drupal_http_request("http://drupal.org/node/{$issue}/project-issue/json");
// Parse JSON-response to get item we need.
$response = drupal_json_decode($response_json->data);
$issue_status = $response['status'];
// Set cache for future requests.
cache_set("patch_manager:issue_status:{$issue}", $issue_status);
}
// Set static value.
$issue_statuses[$issue] = $issue_status;
}
// Set the status.
$item['status'] = $issue_statuses[$issue];
// Set the element.
$elements[$delta] = array(
'#markup' => theme_patch_manager_issuelink($item),
);
}
return $elements;
}