Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By ParisLiakos on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Description:
Feeds
Aggregator feeds and feed items are now Content Entities.
Whenever a feed/feed item id needs to be retrieved use $feed->id()
and $feed->label()
for title.
D7
// Feeds.
$feeds = db_query('SELECT * FROM {aggregator_feed}');
foreach ($feeds as $feed) {
$options[$feed->fid] = $feed->title;
}
// Feed items.
$items = db_query('SELECT * FROM {aggregator_item}');
foreach ($items as $item) {
$options[$item->iid] = $item->title;
}
D8
// Feeds.
use Drupal\aggregator\Entity\Feed;
$feeds = Feed::loadMultiple();
foreach ($feeds as $feed) {
$options[$feed->id()] = $feed->label();
}
// Feed items.
use Drupal\aggregator\Entity\Item;
$feeds = Item::loadMultiple();
foreach ($items as $item) {
$options[$item->id()] = $item->label();
}
- aggregator_save_feed()
and aggregator_save_item()
have been removed in favor of save()
method
D7
// Feeds.
$feed = array(
'title' => $title,
'url' => $feed_url,
'refresh' => '900',
'block' => 5,
);
aggregator_save_feed($feed);
// Feed items.
$item = array(
'fid' => $fid,
'timestamp' => $timestamp,
'title' => $title,
'link' => $link,
'author' => $author,
'description' => $description,
'guid' => $guid,
);
aggregator_save_item($item);
D8
// Feeds.
$feed = Feed::create(array(
'title' => $title,
'url' => $feed_url,
'refresh' => 900,
'block' => 5,
));
$feed->save();
// Feed items.
$item = Item::create(array(
'fid' => $fid,
'timestamp' => $timestamp,
'title' => $title,
'link' => $link,
'author' => $author,
'description' => $description,
'guid' => $guid,
));
$item->save();
- aggregator_feed_source
theming function renamed to aggregator_feed
D7
function THEME_preprocess_aggregator_feed_source(&$variables) {
$feed = $variables['aggregator_feed'];
// Do stuff
}
D8
function THEME_preprocess_aggregator_feed(&$variables) {
// Notice the extra 'elements' key.
$feed = $variables['elements']['#aggregator_feed'];
// Do stuff
}
- aggregator_summary_item
and aggregator_summary_items
has been removed. aggregator_item
can now be used, with a check for the view mode:
D7
function THEME_preprocess_aggregator_summary_item(&$variables) {
$item = $variables['aggregator_item'];
// Do stuff
}
function THEME_preprocess_aggregator_summary_items(&$variables) {
$item = $variables['aggregator_item'];
// Do stuff
}
D8
function THEME_preprocess_aggregator_item(&$variables) {
// Notice the extra 'elements' key.
$item = $variables['elements']['#aggregator_item'];
if ($variables['elements']['#view_mode'] == 'summary') {
// Do stuff
}
}
Impacts:
Module developers
Themers