public function FeedsDrushCommands::listFeeds in Feeds 8.3
Display all feeds using a drush command.
@command feeds:list-feeds @aliases feeds-lf @field-labels feed_type: Feed type fid: Feed ID title: Title imported: Last imported next: Next import source: Feed source item_count: Item count state: Status @option limit Limit the number of feeds to show in the list. Optional. @option enabled Show only enabled feeds. @option disabled Show only disabled feeds. @usage feeds:list-feeds @usage feeds:list-feeds my_feed_type @usage feeds:list-feeds --limit=10 @usage feeds:list-feeds --limit=10 my_feed_type
Parameters
string $feed_type: The name of the feed type whose instances will be listed. Optional.
array $options: A list of options for this command. See below.
Return value
\Consolidation\OutputFormatters\StructuredData\RowsOfFields Tabular data, that can be processed by drush.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
File
- src/
Commands/ FeedsDrushCommands.php, line 53
Class
- FeedsDrushCommands
- Defines Drush commands for the Feeds module.
Namespace
Drupal\feeds\CommandsCode
public function listFeeds($feed_type = '', array $options = [
'limit' => 0,
'enabled' => FALSE,
'disabled' => FALSE,
'format' => 'table',
]) {
$entityQuery = \Drupal::entityQuery('feeds_feed');
if (!empty($feed_type)) {
$entityQuery
->condition('type', $feed_type);
}
if ($options['enabled']) {
$entityQuery
->condition('status', TRUE);
}
elseif ($options['disabled']) {
$entityQuery
->condition('status', FALSE);
}
if ($options['limit'] > 0) {
$entityQuery
->range(0, $options['limit']);
}
$feeds = \Drupal::entityTypeManager()
->getStorage('feeds_feed')
->loadMultiple($entityQuery
->execute());
// Loop through all retrieved feed entities and prepare them for display in
// the formatted table.
$tableData = [];
/** @var \Drupal\feeds\FeedInterface $feed */
foreach ($feeds as $feed) {
$tableData[$feed
->id()] = [
'feed_type' => $feed
->bundle(),
'fid' => $feed
->id(),
'title' => $feed
->label(),
'imported' => $feed
->getImportedTime() ? date('Y-m-d\\TH:i:s', $feed
->getImportedTime()) : $this
->t('Never'),
'next' => $feed
->getNextImportTime() > 0 ? date('Y-m-d\\TH:i:s', $feed
->getNextImportTime()) : $this
->t('Not scheduled'),
'source' => $feed
->getSource(),
'item_count' => $feed
->getItemCount(),
'state' => $feed
->isActive() ? $this
->t('Enabled') : $this
->t('Disabled'),
];
}
// Render $tableData in a renderable table for drush.
return new RowsOfFields($tableData);
}