By ParisLiakos on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Description:
After aggregator fetchers, processors and parsers have moved from hook implementations to plugins in Drupal 8.
Parsers
Class should be in {module}/src/Plugin/aggregator/parser/{Parser}.php and implement the ParserInterface
hook_aggregator_parse_infohas been replaced by annotationshook_aggregator_parsehas been replaced by\Drupal\aggregator\Plugin\ParserInterface::parse()
D7:
/**
* Implements hook_aggregator_parse_info().
*/
function aggregator_aggregator_parse_info() {
return array(
'title' => t('Default parser'),
'description' => t('Parses RSS, Atom and RDF feeds.'),
);
}
/**
* Implements hook_aggregator_parse().
*/
function aggregator_aggregator_parse($feed) {
// Do stuff.
}
D8:
/**
* Defines a default parser implementation.
*
* Parses RSS, Atom and RDF feeds.
*
* @Plugin(
* id = "aggregator",
* title = @Translation("Default parser"),
* description = @Translation("Default parser for RSS, Atom and RDF feeds.")
* )
*/
class DefaultParser implements ParserInterface {
/**
* Implements \Drupal\aggregator\Plugin\ParserInterface::parse().
*/
public function parse(FeedInterface $feed) {
// Do stuff.
}
}
Processors
Class should be in {module}/src/Plugin/aggregator/processor/{Processor}.php and implement the ProcessorInterface
hook_aggregator_process_infohas been replaced by annotationshook_aggregator_processhas been replaced by\Drupal\aggregator\Plugin\ProcessorInterface::process().hook_aggregator_removehas been replaced by\Drupal\aggregator\Plugin\ProcessorInterface::delete().aggregator_expire()has been removed in favor of\Drupal\aggregator\Plugin\ProcessorInterface::postProcess().
D7:
/**
* Implements hook_aggregator_process_info().
*/
function aggregator_aggregator_process_info() {
return array(
'title' => t('Default processor'),
'description' => t('Creates lightweight records from feed items.'),
);
}
/**
* Implements hook_aggregator_process().
*/
function aggregator_aggregator_process($feed) {
// Do stuff.
}
/**
* Implements hook_aggregator_remove().
*/
function aggregator_aggregator_remove($feed) {
// Do stuff.
}
/**
* Expires items from a feed depending on expiration settings.
*
* @param $feed
* Object describing feed.
*/
function aggregator_expire($feed) {
// Do stuff.
}
D8:
/**
* Defines a default processor implementation.
*
* Creates lightweight records from feed items.
*
* @Plugin(
* id = "aggregator",
* title = @Translation("Default processor"),
* description = @Translation("Creates lightweight records from feed items.")
* )
*/
class DefaultProcessor extends PluginBase implements ProcessorInterface {
/**
* Implements \Drupal\aggregator\Plugin\ProcessorInterface::process().
*/
public function process(FeedInterface $feed) {
// Do stuff.
}
/**
* Implements \Drupal\aggregator\Plugin\ProcessorInterface::delete().
*/
public function delete(FeedInterface $feed) {
// Do stuff.
}
/**
* Implements \Drupal\aggregator\Plugin\ProcessorInterface::postProcess().
*
* Expires items from a feed depending on expiration settings.
*/
public function postProcess(FeedInterface $feed) {
// Do stuff.
}
}
Impacts:
Module developers