$announcements = Json::
decode($feed_content);
if (!
isset($announcements['items'
])) { $this->logger->
error('The feed format is not valid.'
);
throw new \
Exception('Invalid format'
);
} $announcements =
$announcements['items'
] ??
[];
// Ensure that announcements reference drupal.org and are applicable to
// the current Drupal version.
$announcements =
array_filter($announcements,
function Darray
$announcement) { return static::
validateUrl($announcement['url'
] ?? ''
) &&
static::
isRelevantItem($announcement['_drupalorg'
]['version'
] ?? ''
);
});
// Save the raw decoded and filtered array to temp store.
$this->tempStore->
setWithExpire('announcements',
$announcements,
$this->config->
get('max_age'
));
} // The drupal.org endpoint is sorted by created date in descending order.
// We will limit the announcements based on the configuration limit.
$announcements =
array_slice($announcements, 0,
$this->config->
get('limit'
) ?? 10
);