Skip to content

Instantly share code, notes, and snippets.

@tedbow
Created November 4, 2020 18:26
Show Gist options
  • Save tedbow/29c7dd8f81297af5fdee51b726020192 to your computer and use it in GitHub Desktop.
Save tedbow/29c7dd8f81297af5fdee51b726020192 to your computer and use it in GitHub Desktop.
// Adapted from https://www.drupal.org/project/drupal/issues/3041885
public function getSecurityAdvisoryMessages(): array {
$messages = [];
$response = $this->tempStore->get('advisories_response');
if (!$response) {
$advisories_endpoint = 'https://drupal.org/items.json';
$response = (string) $this->httpClient->get($advisories_endpoint)->getBody();
// advisories.check_frequency is 12 hours in seconds
$this->tempStore->setWithExpire('advisories_response', $response, $this->config->get('advisories.check_frequency'));
}
$json_payload = json_decode($response, TRUE);
if ($json_payload !== NULL) {
foreach ($json_payload as $json) {
$output[] = [
'#theme' => 'drupalorg_item',
'#item' => $json,
];
}
}
else {
throw new \UnexpectedValueException('Drupal PSA JSON is malformed.');
}
return $messages;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment