I'm using Drupal 8 and creating a feed entity like this:

$feed = \Drupal::entityTypeManager()->getStorage('feeds_feed')->create(array(
            'type' => 'my_feed',
            'uuid' => \Drupal::service('uuid')->generate(),
            'title' => 'RSS feed',
            'uid' => $uid,
            'status' => 1,
            'created' => time(),
            'source' => $form_state->getValue('rss_feed_url'),

That works fine! But how can I execute the import after saving the new feed entity? I've tried the following:

// Batch starts and returns "This webpage has a redirect loop" 

// Returns an error: "Call to undefined method Drupal\feeds\FeedImportHandler::startCronImport()"

How can I import the feed items after creating the feed entity?

  • There is some code in the Queue worker plugins in the feeds module that might help you find an answer. The feeds module is still in development so I am not sure how relevant an answer will be 6 months or a year from now. – mradcliffe Jun 16 '16 at 13:45

This is working for me. Note: You will need to know the numerical $id of your Feed from the D8 DB table feeds_feed. In my case it is 1 so $id = 1.

use Drupal\feeds\Entity\Feed;

function mymodule_cron() {

   * Runs single feeds on cron

  $feed = Feed::load($id);
  if (!$feed->isLocked()) {
    $queue = \Drupal::queue('feeds_feed_import:' . $feed->bundle());
    if ($queue->createItem($feed)) {
      // Add timestamp to avoid queueing item more than once.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.