Skip to content
Snippets Groups Projects

Issue #3336530: Make announcements json feed format consistent with https://www.jsonfeed.org/version/1.1/.

@@ -1069,7 +1069,7 @@ function drush_drupalorg_resign_files() {
*/
function drush_drupalorg_update_announcements_json() {
$body_instance = field_info_instance('node', 'body', 'post');
$output = [];
$items = [];
$result = (new EntityFieldQuery())->entityCondition('entity_type', 'node')
->propertyCondition('type', 'post')
@@ -1078,20 +1078,34 @@ function drush_drupalorg_update_announcements_json() {
->execute();
foreach (node_load_multiple(array_keys($result['node'])) as $node) {
$node_wrapper = entity_metadata_wrapper('node', $node);
$output[] = [
$items[] = [
'id' => $node->nid,
'title' => $node->title,
'teaser' => empty($node->body) ? '' : ($node_wrapper->body->summary->value() ?: text_summary($node_wrapper->body->value->value(), $node_wrapper->body->format->value(), $body_instance['display']['teaser']['settings']['trim_length'])),
'link' => url('node/' . $node->nid, ['absolute' => TRUE]),
'sticky' => (bool) $node->sticky,
'version' => empty($node->field_announcement_version) ? '*' : $node->field_announcement_version[LANGUAGE_NONE][0]['value'],
'updated' => date('c', $node->changed),
'content_html' => empty($node->body) ? '' : ($node_wrapper->body->summary->value() ?: text_summary($node_wrapper->body->value->value(), $node_wrapper->body->format->value(), $body_instance['display']['teaser']['settings']['trim_length'])),
'url' => url('node/' . $node->nid, ['absolute' => TRUE]),
'date_modified' => date('c', $node->changed),
'_extra' => [
'featured' => (bool) $node->sticky,
'version' => empty($node->field_announcement_version) ? '*' : $node->field_announcement_version[LANGUAGE_NONE][0]['value'],
]
];
}
$json = drupal_json_encode($output);
// https://www.jsonfeed.org/version/1.1/
// Domain is hard-coded so test fixtures can be generated from dev & staging.
$drupal_org_url = 'https://www.drupal.org';
$filename = drush_get_option('test', FALSE) ? 'announcements-this-is-only-a-test.json' : 'announcements.json';
$json_feed = [
'version' => 'https://jsonfeed.org/version/1.1',
'title' => t('Drupal Announcements Feed'),
'home_page_url' => $drupal_org_url,
'feed_url' => $drupal_org_url . '/' . $filename,
'favicon' => $drupal_org_url . '/favicon.ico',
'items' => $items,
];
$json = drupal_json_encode($json_feed);
if (!drush_confirm(dt('New contents to be written to @filename:', ['@filename' => $filename]) . "\n" . $json . "\n" . dt('Do you want to continue?'))) {
return;
}
@@ -1099,7 +1113,7 @@ function drush_drupalorg_update_announcements_json() {
$directory = 'public://announcements-feed';
file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
file_unmanaged_save_data($json, $directory . '/' . $filename, FILE_EXISTS_REPLACE);
drupalorg_crosssite_fastly_purge_url('https://www.drupal.org/' . $filename);
drupalorg_crosssite_fastly_purge_url(url($filename, ['absolute' => TRUE]));
}
/**
Loading